It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

help needed

help needed

Postby Wolf2222 on Tue Oct 31, 2006 10:25 pm

I have a package called test which has two classes.

I have completed class 1 but I am having problems with the 2nd class

Below is class 1

package test;

/**
* Title: Artist
* Description: To be completed for TMA01

*/

public class Artist
{
String name; // Artists name
String genre; // Type of music the artist records
boolean stocked; // Is the artist stocked

public String getName()
{
return name;
}

public String genre()
{
return genre;
}

public boolean isStocked()
{
return stocked;
}

public void setName(String n)
{
String name = n;
}

public void setGenre(String g)
{
String genre = g;
}

public void setStocked(boolean b)
{
boolean stocked = b;
}

public String toString()
{
System.out.println(name + ", " + genre + stocked);

}
}

I have to do the following for class 2. i am currently stuck with the 2nd part of the class.

package test;

/**
* Title: TestArtist
* Description: This class is to be completed to test the Artist class

*/

public class TestArtist
{

public static void main(String[] args)
{
// The following two references are provided
Artist a1, a2;

// The following lines create two objects of type Artist
// referenced by the names a1 and a2. Each has default
// values for the instance variables defined by Artist
a1 = new Artist();
a2 = new Artist();

// Write your code to test the Artist methods below.

boolean test [] = {false, false, false};
// 1. Create an array referenced by variable test,
// with room to store three boolean values.
// Initially all array locations should store the value false

a1 = "a1";
n = a1;
a2 = "a2";
n = a2;




// 2. Set the name of the artist referenced by a1 to "a1"
// and set the name of the artist referenced by a2 to "a2"

// 3. Add code to manually set that the artist referenced by a1 is stocked
// and that the artist referenced by a2 is not stocked

// 4. Set the genres of the artists referenced by a1 and a2 to different values

// 5. Display on the screen for a1 and a2 the artists name and
// whether the artist is stocked. For example
// Name: Creme Brulee. Stocked: false

// 6. Display on the screen the full details of the two artists

// 7. Display the text "both stocked" if the two artists are both stocked

// 8. Display the text "neither stocked" if neither artist is stocked

// 9. Use the string equals method to compare the genres of the artists
// and display the message "the artists have different genres" if the
// artists have different genres

// 10. Change the genre of the artist a1 to be the same as a2

// 11. Use the string equals method to compare the genres of the artists
// and display the message "the artists have the same genres"
// if the artists have the same genres

// 12. Set the first test array location to be the stocked value for artist a1

// 13. Set the third array value to be the opposite value of the second array location

// 14. Write a for-loop to print out all the values in the test array on separate lines
// in the manner test[n] = v, where n is the index and v is the value at each position in the array
// e.g. one line of output might be
// test[1] = false


System.out.println("done testing the Artist class");

}
}
Wolf2222
 
Posts: 0
Joined: Tue Oct 31, 2006 10:19 pm

Who is online

Users browsing this forum: No registered users and 0 guests