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
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.
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?
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
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.
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.
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
printVideoList() - uses just simple loop mechanism to print the list
printByTitle() - need to be first sorted by title and then printed out
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...
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){
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.