943,515 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1179
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 8th, 2009
0

Beginer Java Coder....

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hollywoood69 is offline Offline
24 posts
since Apr 2009
Apr 8th, 2009
0

Re: Beginer Java Coder....

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.
Reputation Points: 22
Solved Threads: 3
Junior Poster in Training
LevelSix is offline Offline
59 posts
since May 2008
Apr 8th, 2009
0

Re: Beginer Java Coder....

Click to Expand / Collapse  Quote originally posted by LevelSix ...
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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hollywoood69 is offline Offline
24 posts
since Apr 2009
Apr 8th, 2009
1

Re: Beginer Java Coder....

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

Java Syntax (Toggle Plain Text)
  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...

Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Apr 8th, 2009
0

Re: Beginer Java Coder....

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.
Reputation Points: 22
Solved Threads: 3
Junior Poster in Training
LevelSix is offline Offline
59 posts
since May 2008
Apr 8th, 2009
0

Re: Beginer Java Coder....

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hollywoood69 is offline Offline
24 posts
since Apr 2009
Apr 8th, 2009
0

Re: Beginer Java Coder....

LevelSix-

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

Thank you again!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hollywoood69 is offline Offline
24 posts
since Apr 2009
Apr 8th, 2009
0

Re: Beginer Java Coder....

hollywood - if you need more help, look at the example I provided.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Apr 8th, 2009
1

Re: Beginer Java Coder....

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
Java Syntax (Toggle Plain Text)
  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...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,653 posts
since Dec 2004
Apr 8th, 2009
0

Re: Beginer Java Coder....

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.

Quote ...

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);
}

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hollywoood69 is offline Offline
24 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: read from text file
Next Thread in Java Forum Timeline: helloworld program error in linux server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC