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
260 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:
mayankeagle 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:mayankeagle
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
 
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:mayankeagle
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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:mayankeagle
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:mayankeagle
ID: 9836305
Oops!

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

would be:

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

0
 
LVL 30

Expert Comment

by:mayankeagle
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:mayankeagle
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now