Newb Java Homework Help!

Stokes

Senior member
Apr 20, 2005
510
0
0
Hi all,

I just entered a Computer Science class and because of an illness I missed a day and fell behind a bit and now am stuck on this homework problem for a program due tomorrow. Here is the directions, its pretty simple program, I'm just struggling with parts of it.

"Write two classes: Track class, TestTrack class. The Track class is the schematic for saving a track from a CD. It should at least store the song title, the artist, and the duration in seconds. (Make the duration a variable of type int.) The track class should have at least one constructor, a method to print the duration in minutes and seconds, and a method to output the complete track information.

To input information, use the Scanner class and to output information, use the JOptionPane.

The TestTrack class contains the main method and asks the user for information about a track, builds a track, then uses the appropriate method to print out a nice formatted version of the information. "

Here is what I have so far:

import java.util.Scanner;

public class Track
{
public static void main(String[] args)
{

Scanner in = new Scanner(System.in);

System.out.print("Enter Song Title: ");
String Title = in.nextLine();

System.out.print("Enter Artist Name: ");
String Artist = in.nextLine();

System.out.print("Enter Track Duration (seconds): ");
int duration = in.nextInt();

}

}

So here is what I'm having trouble understanding.. in the directions am I suppose to display the track info at the end that the user entered? Am I on the right track so far with the track.java file.. I found an example in the book about the test file, but I don't understand anything about it, because it's dealing with a cash register and I am really just having trouble understanding what they are doing in that instance.

How is the test file connected to the main file? In this situation I don't really care if anyone completely tells me how to do this problem, which I would like, but I need a good explanation of why.

Any help is appreciated.
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
*Your main method needs to go in a separate class, "TestTrack". You currently have it inside of Track. In a separate file, declare a new class of the name TestTrack, and give it the main method. It should use the code you wrote for input, construct a new instance of Track, then tell Track to display itself.
*You need a constructor for track, look it up in your book. You'll also need instance variables within it for each of the fields (title, artist, and duration). Look those up as well.
 

minofifa

Senior member
May 19, 2004
485
0
0
ya what 'catraz said is correct.

make a constructor for your Track class, maybe one that declares your title artist adn duration variables. Then in your TestTrack class, in the main method, do something like :

Track mytrack = new Track (title, artist, duration);

then use the code you have already to update those variables.
 

Stokes

Senior member
Apr 20, 2005
510
0
0
I appreciate the help, and I'm looking in the book for the things mentioned, but I'm still kind of clueless where to go.. Can anyone help me a little bit with some of the coding for this? I need to see it or an example that will help me go. I'm really struggling with this for some reason.