Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

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!!!

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
cubanitoloco
Asked:
cubanitoloco
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
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
 
yongsingCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
yongsingCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
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
 
cubanitolocoAuthor Commented:
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
 
yongsingCommented:
You are using my code, so why did you accept mayankeagle's comment as answer?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
Oops!

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

would be:

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

0
 
Mayank SAssociate Director - Product EngineeringCommented:
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
 
taekeeCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now