By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,638 Members | 1,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,638 IT Pros & Developers. It's quick & easy.

Stuck

P: 3
Hi guys,

I am stuck on a project. I am doing a HDIP that is unrelated to my undergraduate degree. One of my modules is java which i'm trying to get my head round. The lecturer is unhelpful and keeps giving us really hard assignments.

My latest assignment is create a

film class
name:string
code:string
film (string)
setName(string)
getName(string)
getCode(String)

Actor class
name: string
address: string
age: int
myFilm:arraylist
Actor(string,string,int)
setName(string)
getName:(string)
setAddress(string)
setAge(int)
setfilm(arraylist)
getAddress(string)

I also have to creat a main class(console application). Using the classes specified I have to create an arraylist to hold many actors that can have many films. The main method is only to use one film arraylist for all actors. The actors also have to have their on collection of films deep copy.

I'm sorry for the long winded description however, I have never programmed java before and i feel slightly lost. The lecturer has given me a week to do it? I could do with some help to point me in the right direction.

Thanks for even reading my post I appreciate you taking the time to do so.

Thanks in advance,
Regards,
Desperate student with a bad lecturer!
Oct 16 '13 #1
Share this Question
Share on Google+
5 Replies


Expert 100+
P: 785
If we give you the spoon-feed solution, you would never learn programming. But you attend the course to learn programming.
Learning programming is not how to do it, but how to get the information how to do it. When you work on a real program in your future job, there are always hundreds of unknown and mostly undocumented methods somebody else wrote. To change them, you must first understand them. There would be no lecturer. Your only help is analysing them youself with a lot of try-and-error and looking up some API desription in the internet or tutorials. To figure out yourself how it works , that is called "programming", not just copying some none-understood code. That is the reason why your lecturer is a good lecturer: the less he writes code for you, the more you learn. When you come up with something you wrote yourself, the lecturer should be there to point out your errors and give you ideas of how to make it better. But never write the code for you.

I never had a lecturer when i started programming. I read books a lot and spend many hours with try and error and also research of undocumented methods. Nowadays it is easier to learn: there are a lot of online tutorials outside.

So just grab an online tutorial from Java for beginners and start immediately: you have only one week. Try to learn as much in this week as possible. Spend 3 days with online-tutorials and the last 4 days with doing your task.

When you are stuck in your task, show us the code you have written yourself so far (this is mandatory, else no learning effect!), and we will help you here in this forum.
Oct 17 '13 #2

P: 3
Expand|Select|Wrap|Line Numbers
  1. public class Film {
  2.  
  3.  private String Name;
  4.  private String Code;
  5.  
  6.  public Film (String name) {
  7.      super();
  8.      Name = name;
  9.  }
  10. public String getCode() {
  11.     return Code;
  12. }
  13. public void setCode(String code) {
  14.     Code = code;
  15. }
  16. public String getName() {
  17.     return Name;
  18. }
  19. public void setName(String name) {
  20.     Name = name;
  21. }
  22.  
  23.  
  24.  
  25.  
  26. }
  27.  
  28.  
  29. public class Actor{
  30.     private String name;
  31.     private String address;
  32.     private String age;
  33.     private String myFilm;
  34.  
  35.     public String getAddress() {
  36.         return address;
  37.     }
  38.     public void setAddress(String title) {
  39.         this.address = address;
  40.     }
  41.     public String getName() {
  42.         return name;
  43.     }
  44.     public void setName(String director) {
  45.         this.name = name;
  46.     }
  47.     public String getAge() {
  48.         return age;
  49.     }
  50.     public void setAgeString actor) {
  51.         this.age = age;
  52.     }
  53.     public void setMyFilm {
  54.         this.myFilm = myFilm
  55.     }
  56.     public String getMyFilm() {
  57.         return myFilm;
  58.     }
  59. }
  60.  
  61.  
  62. import java.util.ArrayList;
  63.  
  64. import java.util.Scanner;
  65.  
  66. public class MainTest {
  67.  
  68.         ArrayList<actor> Actors = new ArrayList<actor>();
  69.  
  70.             private static Scanner keyboard;
  71.  
  72.             public static void main( String[] args ){
  73.                 keyboard = new Scanner( System.in );
  74.                 int numberactors=0;
  75.  
  76.                 String[] nameone = new String[100];  
  77.                 String[] address = new String[100]; 
  78.                 String[] films = new String[100];
  79.                 String [] age = new String [100];
  80.                 System.out.print( "Enter the number of Actors" ); 
  81.                 numberactors = keyboard.nextInt(); 
  82.                 boolean finished = false;
  83.  
  84.                 if (numberactors==-1) {
  85.                     System.out.printf("Enter the number of Actors\n");
  86.                     numberactors = keyboard.nextInt(); 
  87.                 }
  88.                 else{
  89.                     for(int i=0;i<numberactors;i++){
  90.                         System.out.print("Enter Actors first name: "); 
  91.                         nameone[i] = keyboard.next(); 
  92.                         System.out.print("Enter Actors second name: "); 
  93.                         address[i] = keyboard.next(); 
  94.                         System.out.print("Enter Films by Actor: "); 
  95.                         films[i] = keyboard.next(); 
  96.                         System.out.printf("Enter Actors Age");   
  97.                         age[i] = keyboard.next();  
  98.  
  99.  
  100.                     do  {
  101.  
  102.                         System.out.println("///// Menu ////////");
  103.                         System.out.println("Choose option 1 to view Actors details :");
  104.                         System.out.println("Option 2 to add Actor details");
  105.                         System.out.println("Choose option 3 to delete Actor details :");
  106.                         System.out.println("Option 4 to exit goodbye");
  107.  
  108.                         int option = keyboard.nextInt();  
  109.  
  110.  
  111.  
  112.                         switch (option){
  113.  
  114.                         case 1:
  115.                             for (int ii=0;ii<numberactors;ii++){
  116.  
  117.                                 System.out.println("First name " +  nameone[ii] + " Second name " +nametwo[ii] + " Films " +films[ii]+ " Age " +age[ii]); 
  118.                             }
  119.  
  120.                             break;
  121.  
  122.                         case 2:
  123.                             System.out.print("Enter Actors first name: "); 
  124.                             nameone[numberactors] = keyboard.next();
  125.  
  126.                             System.out.print("Enter Actors second name: "); 
  127.                             nametwo[numberactors] = keyboard.next(); 
  128.  
  129.                             System.out.printf("Enter Actors Age");   
  130.                             age[numberactors] = keyboard.next();
  131.  
  132.                             System.out.printf("Enter Films");   
  133.                             films[numberactors] = keyboard.next();
  134.  
  135.                             break;
  136.  
  137.  
  138.                         case 3:
  139.  
  140.                             System.out.println("Enter Actors name to delete their details");
  141.  
  142.                             for (int ii=0;ii<numberactors;ii++){
  143.  
  144.                                 System.out.println(" Actor: "+ii +" for " + nameone[ii]+ " " +nametwo[ii] ); 
  145.                             }       
  146.                             int x=0;
  147.                             x = keyboard.nextInt();
  148.                             System.out.println(x);
  149.  
  150.                             nameone[x]=null;
  151.                             nametwo[x]=null;
  152.                             age[x]=null;
  153.                             films[x]=null;
  154.  
  155.                             break;
  156.  
  157.  
  158.  
  159.                         case 4:
  160.  
  161.                             System.out.println("You are finished goodbye");
  162.                             finished = true;
  163.                             break;
  164.  
  165.  
  166.                             default: 
  167.                                 System.out.println("fuk off oonagh");
  168.                         }
  169.                     }
  170.  
  171.                     while (!finished);
  172.                     }
  173.  
  174.  
  175.                 }
  176.  
  177.             }
  178.  
  179. }
//this is what i have so far it runs, but i am stuck on how to implement the array? I am not asking that someone does this for me and beleive me i have watched hours and hours of tutorials. thanks for your reply I appreciate your help and your time to reply
Oct 17 '13 #3

Expert 100+
P: 785
Who is "oonagh"? It seems you don't like him much :-)

Congratulations, you have done good work as a beginner.
Now how to implement the arrays:

You wrote:
Expand|Select|Wrap|Line Numbers
  1. String[] nameone = new String[100];
  2. String[] address = new String[100];
  3. String[] films = new String[100];
  4. String [] age = new String [100];
That works, but here is a better idea, especially referring to this part of your assignment:
Actor class
name: string
address: string
age: int
myFilm:arraylist
Actor(string,string,int)
setName(string)
getName:(string)
setAddress(string)
setAge(int)
setfilm(arraylist)
getAddress(string)
This means that you do not use a set of arrays, each holding a part of a single actor's data, but you define a class "Actor" which holds all of the data of a single actor. Then you define an array of Actors.

Expand|Select|Wrap|Line Numbers
  1. class Actor {
  2.    String name;
  3.    String address;
  4.    ....
  5.  
  6.    public String getName()
  7.    {
  8.       return name;
  9.    }
  10.    public void setName(String newName)
  11.    {
  12.       name = newName;
  13.    }
  14.    public String getAddress()
  15.    {
  16. ...
  17.    }
  18.    public void setAddress(String newAddress)
  19.    {
  20. ...
  21.    }
  22. ...
  23. }
  24.  
Make an instance of an actor and feed all your data:

Expand|Select|Wrap|Line Numbers
  1. Actor actor = new Actor();
  2. actor.setName("me"),
  3. actor.setAddress("here");
  4. ...
  5.  

Now you can put him into the the array of actors:

Expand|Select|Wrap|Line Numbers
  1. Actor[] actorArray = new ActorArray[100];
  2. actorArray[0] = actor;
  3.  
Oct 17 '13 #4

Expert 100+
P: 785
The next step would be to use an dynamic sized ArrayList instead of a fixed size array with size=100, (but for beginners a fixed size array is easier).

So it is best if you make the proposed changes first, and as a second step you exchange the fixed array with an ArrayList.

If you still have difficulties, you are welcome to get more help, but you must post your new / changed code first.
And please use the code tags when you post: select your code in the editor and click the "code" button on top of the editor.
Oct 17 '13 #5

P: 3
Thank you so much for your help. I will implement this and post my new code as soon as I can. Oonagh is our lecturer lol

Regards,
Gary
Oct 17 '13 #6

Post your reply

Sign in to post your reply or Sign up for a free account.