Beginer Java Coder....

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2009
Posts: 24
Reputation: hollywoood69 is an unknown quantity at this point 
Solved Threads: 0
hollywoood69 hollywoood69 is offline Offline
Newbie Poster

Beginer Java Coder....

 
0
  #1
Apr 8th, 2009
Here is my assignment:

Write a class named 'Video' that has two attributes, a title (type String) and rating (type int). Then write an application class named 'VideoStore' that first creates an array consisting of 5 video objects, then display the list three times; first unsorted, then sorted by title and finally sorted by rating.

I understand an array, i understand how to make an array, and i understand how to display the array. My problem is that i don't understand how to combine the two arrays to create this list that my instructor is looking for. I am not looking for a straight answer, but if there is any resources that you can post or maybe a dummy code that i can use for reference that would be great. Thanks everyone
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 55
Reputation: LevelSix is an unknown quantity at this point 
Solved Threads: 3
LevelSix's Avatar
LevelSix LevelSix is offline Offline
Junior Poster in Training

Re: Beginer Java Coder....

 
0
  #2
Apr 8th, 2009
What it appears you need to do is simply create one array, of type Video. Video will be a class you have to write, simple enough: Constructor with the two parameters and then return methods.

Once this class and the arrays are constructed you can construct new Video objects and load them into an array.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 24
Reputation: hollywoood69 is an unknown quantity at this point 
Solved Threads: 0
hollywoood69 hollywoood69 is offline Offline
Newbie Poster

Re: Beginer Java Coder....

 
0
  #3
Apr 8th, 2009
Originally Posted by LevelSix View Post
What it appears you need to do is simply create one array, of type Video. Video will be a class you have to write, simple enough: Constructor with the two parameters and then return methods.

Once this class and the arrays are constructed you can construct new Video objects and load them into an array.
That is the problem that i am having. I am not understanding those parts of it. I am very new and the instructor isnt very helpful. And when you say to have the constructor with two paramerters how would i do that?

Thanks again for the help!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Beginer Java Coder....

 
1
  #4
Apr 8th, 2009
Your class is named Video. The Video class has a String and an int as data members. Your other class is VideoStore. It has an array of videos as its only data member. If you know how to create an array, then you should have no problems.

Video[] theVideos = new Video[howeverManyVideosYouHave];

If you wanted to make a class called Car, it might look like this

  1. public class Car{
  2. //The data members
  3. public String color;
  4. public int weight;
  5.  
  6. //The constructor
  7. public Car(String theColor, int theWeight){
  8. color = theColor;
  9. weight = theWeight;
  10. }
  11. }

Now, consider a 'Car Dealership' where the Car Dealership typically has a lot of Cars...

  1. public class CarDealership{
  2. Car[] theCars;
  3.  
  4. public CarDealership(Car[] cars){
  5. theCars = cars;
  6. }
  7. }
Last edited by BestJewSinceJC; Apr 8th, 2009 at 3:55 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 55
Reputation: LevelSix is an unknown quantity at this point 
Solved Threads: 3
LevelSix's Avatar
LevelSix LevelSix is offline Offline
Junior Poster in Training

Re: Beginer Java Coder....

 
0
  #5
Apr 8th, 2009
Constructor for class video would appear as:
public Video(String name, int rating)
{
///store name and rating to instance fields
}
Then you would have methods such as:
public String getVideoName()
{
return //instance field of video name
}

Instance fields if you're unaware are just global variables:
private String videoName //for example.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 24
Reputation: hollywoood69 is an unknown quantity at this point 
Solved Threads: 0
hollywoood69 hollywoood69 is offline Offline
Newbie Poster

Re: Beginer Java Coder....

 
0
  #6
Apr 8th, 2009
I will post what i have in just a little bit. I think I have an idea of what i need to do. Maybe when i post what i have it will help with what I am doing wrong.

Thanks everyone for the help
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 24
Reputation: hollywoood69 is an unknown quantity at this point 
Solved Threads: 0
hollywoood69 hollywoood69 is offline Offline
Newbie Poster

Re: Beginer Java Coder....

 
0
  #7
Apr 8th, 2009
LevelSix-

Thank you. I will post something within the hour. If i have problems...well i will be back

Thank you again!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Beginer Java Coder....

 
0
  #8
Apr 8th, 2009
hollywood - if you need more help, look at the example I provided.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,208
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 486
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Beginer Java Coder....

 
1
  #9
Apr 8th, 2009
There is only one array involved that you need to use. Video class represent an object that has to be stored in array.
I'm not gone do Video class for you as that is simple and judging by assignment topic you should be familiar with it. So assuming you already created your Video class this is skeloton of what you supposed to do
  1. public class VideoTest {
  2.  
  3. public static void main(String[] args){
  4. Video[] video = new Video[5];
  5. video[0] = new Video("Fast and Furious", 1);
  6. video[1] = new Video("Save private Rayne", 5);
  7.  
  8. printVideoList(video);
  9. printByTitle(video);
  10. printByRating(video);
  11. }
  12.  
  13. private static void printVideoList(Video[] video){}
  14.  
  15. private static void printByTitle(Video[] video){}
  16.  
  17. private static void printByRating(Video[] video){}
  18. }
  1. printVideoList() - uses just simple loop mechanism to print the list
  2. printByTitle() - need to be first sorted by title and then printed out
  3. printByRating() - need to be first sorted by rating and then printed out

Two things, if you clever you will reuse printVideoList() to help you out after sorting. Two, few days ago I made a post in regards of simple sorting that can be reused too...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 24
Reputation: hollywoood69 is an unknown quantity at this point 
Solved Threads: 0
hollywoood69 hollywoood69 is offline Offline
Newbie Poster

Re: Beginer Java Coder....

 
0
  #10
Apr 8th, 2009
Alright...maybe i don't know as much as I claim or think . I am still having major problems. I have got the video class done (I think....I'll post what i have), now i am having issues with the VideoStore class...
I think i am going to become a seamstress....

Here is what i have so far. Maybe I am way off.


public class Video {

String[] movieTitle = new String[5];
int[] movieRating = new int[5];

public Video(){

}


public Video(String[] j_movieTitle, int[] j_movieRating){

movieTitle = j_movieTitle;
movieRating = j_movieRating;
}

public void setMovie(String[] j_movieTitle){
movieTitle = j_movieTitle;
}

public String[] getMovie() {
return(movieTitle);
}

public void setRating(int[] j_movieRating) {
movieRating = j_movieRating;
}

public int[] getRating() {
return(movieRating);
}

}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC