Solved

I NEED IF SOME ONE CAN HELP ME OUT WITH THIS CODE I AM REALLY PRIMITIVE WITH JAVA AND I REALLY NEED YOU GUYS HELP!!!

Posted on 2003-11-27
12
279 Views
Last Modified: 2010-03-31
I have to write this java a program that stores an array of video titles and their corresponding ID numbers in inventory.In addition  it has to display the list before it is sorted, and display a list sorted by inventory ID number.  It has to use two single-dimensional arrays – one for titles and one for the inventory ID number. Here what I have come up with so far Can Anyone HELP PLEASE! Your gratitude will be gladly appriciated. Thanks

------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Videos
{

private String videoName;
private int videoMinidnumber;

public videos(String video, int idnumber);

{
videoName = video;
videoMinidnumber = idnumber;
}


public String getvideoName()
{
     return videoName;
}

public void setvideoName (String video)
{
     videoName = video;
}
public int getvideoMinidnumber()

{
     return videoMinidnumber;
}

public void setvideoMinnumber(int idnumber)
{
     videoMinidnumber = idnumber;
}


}
 
-------------------------------------------------------------------------------------------------------------------------------------------------------------
HERE IS THE VIDEO ARRAY:



public class VideosArray{

public static void main (String[] args);
{    
         
videoName[] somevideoName = new [5];
idnumber [] someidnumber = new idnumber[5];
int IDnumber [] = {"101", "102", "103", "104", "105"};          
String[] videoName = {"Matrix Revolutions","Analyze That","Scarface","Saving Private Ryan", "Blackhawk Down"};
System.out.println(someVideos[].getvideoNamearray() + " " + someVideos[].getvideoMinidnumberarray());
   
  videos[i].set methods
  videos[i].set methods


}


}
 
0
Comment
Question by:cubanitoloco
12 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 125 total points
ID: 9835085
Sounds like homework, but since you've come up with some coding efforts, its better.

>> It has to use two single-dimensional arrays

Why do you need two single-dimensional arrays? Is it necessary? How about using an array of objects of type Videos, or a Vector? If you use Java Collections, then you will be able to sort the whole thing very easily too.

Mayank.
0
 
LVL 9

Expert Comment

by:yongsing
ID: 9835117
public class VideosArray {

  public static void main (String[] args) {    
    int IDnumber [] = {"101", "102", "103", "104", "105"};          
    String[] videoName = {"Matrix Revolutions","Analyze That","Scarface","Saving Private Ryan", "Blackhawk Down"};

    // Create array of Videos objects.
    Videos videos = new Video[5];
    for (int i = 0; i < 5; i++) {
      videos[i] = new Videos(videoName[i], IDnumber[i]);
    }

    // Print Videos objects.
    for (int i = 0; i < 5; i++) {
      System.out.println(videos[i].getvideoName() + " " + videos[i].getvideoMinidnumber());
    }
  }

}
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9835179
Yeah, that is correct, yongsing, as per the requirements. But don't you think that using 2 arrays is not a good approach to it? Moreover, for sorting, we will again have to write a sorting algorith, maybe bubble-sort or what-ever. How about letting the Java Collections do it? Just a thought..

Regards,

Mayank.
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 9

Expert Comment

by:yongsing
ID: 9835217
For my code, the two arrays are just a place holder for the data. The actual data would be collected in some other ways, say from a file or via user input. Eventually the data would be in Videos objects. I agree that using a collection is better:

// Create Vector of Videos objects.
Vector videos = new Vector();
for (int i = 0; i < 5; i++) {
    videos.add(new Videos(videoName[i], IDnumber[i]));
}

// Sort the Vector of Videos objects here.

// Print Videos objects.
for (int i = 0; i < videos.size(); i++) {
  Videos video = (Videos)videos.get(i);
  System.out.println(video.getvideoName() + " " + video.getvideoMinidnumber());
}
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9835796
By t1he way, cubanitoloco, just for your knowledge, so that you don't repeat these mistakes. There were some major errors in your code:

>> videoName[] somevideoName = new [5];
>> idnumber [] someidnumber = new idnumber[5];

videoName is a data-member of class Videos. Its is not a data-type in its own. You cannot declare an array of videoNames directly like that. You have to make an array of objects (of type Videos) like yongsing has done in his first code fragment, or (better) use a Vector which stores objects of type Videos (after setting the data-member videoName and videoMinidnumber. Moreover, you have also tried to declare an array of type idnumber too, which is also wrong (idnumber is also not even a data-member of the Videos class. Probably, you wanted to declare an array of videoMinidnumber over there, but even that is wrong, like I said).

If you add them to a Vector, then you can use your own Comparator to sort them (or let Java sort them for you). Or if you want to maintain an array, then you have to go through the process of writing the code for sorting too.

Regards,

Mayank.

0
 

Author Comment

by:cubanitoloco
ID: 9836175
Hey Yonsing and mayankeagle thank you very very much for your help and knowledge enrichment and I really appriciate you guys help so if my code looks like this it would it work??? I still have to compile it, I have not done that yet can you help!! Do you think it will work??


public class Videos
{

private String videoName;
private int videoMinidnumber;

public videos(String video, int idnumber);

{
videoName = video;
videoMinidnumber = idnumber;
}


public String getvideoName()
{
     return videoName;
}

public void setvideoName (String video)
{
     videoName = video;
}
public int getvideoMinidnumber()

{
     return videoMinidnumber;
}

public void setvideoMinnumber(int idnumber)
{
     videoMinidnumber = idnumber;
}


}

\\\HERE IS THE VIDEO ARRAY:



public class VideosArray {

  public static void main (String[] args) {    
    int IDnumber [] = {"101", "102", "103", "104", "105"};          
    String[] videoName = {"Matrix Revolutions","The Godfather","Scarface","Saving Private Ryan", "Blackhawk Down"};

    // Create array of Videos objects.
    Videos videos = new Video[5];
    for (int i = 0; i < 5; i++) {
      videos[i] = new Videos(videoName[i], IDnumber[i]);
    }

    // Print Videos objects.
    for (int i = 0; i < 5; i++) {
      System.out.println(videos[i].getvideoName() + " " + videos[i].getvideoMinidnumber());
    }
  }

}
0
 
LVL 9

Expert Comment

by:yongsing
ID: 9836219
You are using my code, so why did you accept mayankeagle's comment as answer?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9836267
Right, you should have given the points to yongsing.

Anyway, there are a few things wrong with your code:

>> public videos(String video, int idnumber);

Remove the semi-colon from the end of this line. Also, change videos to Videos (with a capital V) because that is what your class-name is.

>> Videos videos = new Video[5];
>>    for (int i = 0; i < 5; i++) {
>>      videos[i] = new Videos(videoName[i], IDnumber[i]);
>>    }

There is no need to allocate memory twice. I would do it as:

Videos videos = new Video[5];
    for (int i = 0; i < 5; i++) {
      videos[i].setvideoMinnumber (IDnumber[i]);
      videos[i].setvideoName (IDnumber[i]);
    }

I guess everything else looks fine so far.

Mayank.

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9836305
Oops!

>> videos[i].setvideoName (IDnumber[i]);

would be:

videos[i].setvideoName (videoName[i]);

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9836321
Also, by the way, you can't have two public classes in the same .java file. You will need to write the two classes in different files.
0
 

Expert Comment

by:taekee
ID: 10303199
I have the same assignemnt for homework but I can not figure out the finished product for this.  Any other comments out there?  Any help is appreciated.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10307237
We don't directly help with code for homework. Its against EE policies. Come up with some coding efforts, and then we can help you fix the errors and get it working. And post your own question for that! Don't use somebody else's question-page for that.

Mayank.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java Server Faces parameter pass? 6 50
Java SE 8u111  Lot of stuff broke 11 71
javap bin 2 36
maven module vs maven project 3 23
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question