| | |
Beginer Java Coder....
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2009
Posts: 24
Reputation:
Solved Threads: 0
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
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.
Once this class and the arrays are constructed you can construct new Video objects and load them into an array.
•
•
Join Date: Apr 2009
Posts: 24
Reputation:
Solved Threads: 0
•
•
•
•
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.
Thanks again for the help!
•
•
Join Date: Sep 2008
Posts: 1,658
Reputation:
Solved Threads: 206
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
Now, consider a 'Car Dealership' where the Car Dealership typically has a lot of Cars...
Video[] theVideos = new Video[howeverManyVideosYouHave];
If you wanted to make a class called Car, it might look like this
Java Syntax (Toggle Plain Text)
public class Car{ //The data members public String color; public int weight; //The constructor public Car(String theColor, int theWeight){ color = theColor; weight = theWeight; } }
Now, consider a 'Car Dealership' where the Car Dealership typically has a lot of Cars...
Java Syntax (Toggle Plain Text)
public class CarDealership{ Car[] theCars; public CarDealership(Car[] cars){ theCars = cars; } }
Last edited by BestJewSinceJC; Apr 8th, 2009 at 3:55 pm.
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.
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.
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
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...
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)
public class VideoTest { public static void main(String[] args){ Video[] video = new Video[5]; video[0] = new Video("Fast and Furious", 1); video[1] = new Video("Save private Rayne", 5); printVideoList(video); printByTitle(video); printByRating(video); } private static void printVideoList(Video[] video){} private static void printByTitle(Video[] video){} private static void printByRating(Video[] video){} }
- 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...
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Apr 2009
Posts: 24
Reputation:
Solved Threads: 0
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.
. 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);
}
}
![]() |
Other Threads in the Java Forum
- Previous Thread: read from text file
- Next Thread: helloworld program error in linux server
Views: 898 | Replies: 19
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool linux list loop map method methods mobile netbeans newbie number object oracle os pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






