|
For this assignment you are going to write code for the following TWO classes:
Here are the specifications of class Person:
Person must have 2 INSTANCE variables.
- fName of type String
- lName of type String
Methods of class Person:
setFirstName
returns: nothing
arguments: 1 String
what it does: it assigns its argument to the variable fName
Example:
Person pp;
pp = new Person();
pp.setFirstName("jon");
System.out.println(pp.fName); // prints "jon"
setLastName
returns: nothing
arguments: 1 String
what it does: it assigns its argument to the variable lName
Example:
Person pp;
pp = new Person();
pp.setLastName("foo");
System.out.println(pp.lName);//prints "foo"
getFirstName
returns: String
arguments: none
what it does: it returns the value of variable fName
Example:
Person pp;
pp = new Person();
pp.setFirstName("mary");
System.out.println(pp.getFirstName()); // prints "mary"
getLastName
returns: String
arguments: none
what it does: it returns the value of variable lName
Example:
Person pp;
pp = new Person();
pp.setLastName("smith");
System.out.println(pp.getLastName()); // prints "smith"
Here are the specifications of class Song:
Song must have 2 INSTANCE variables.
- title of type String
- composer of type Person
Methods of class Song
setTitle
returns: nothing
arguments: 1 String
what it does: it assigns its argument to the variable title
Example:
Song ss;
ss = new Song();
ss.setTitle("hello world");
System.out.println(ss.title); // prints "Hello world"
setComposer
returns: nothing
arguments: 1 Person
what it does: it assigns its argument to the variable composer
Example:
Song ss;
ss = new Song();
Person pp;
pp = new Person();
ss.setComposer(pp);
//now the composer of ss is pp
getTitle
returns: String
arguments: none
what it does: it returns the value of variable title
Example:
Song ss;
ss = new Song();
ss.setTitle("foo");
System.out.println(ss.getTitle());//prints "foo"
getComposer
returns: Person
arguments: none
what it does: it returns the value of variable composer
Example:
Song ss;Person pp;
ss = new Song();
pp = new Person();
pp.setFirstName("gary");
ss.setComposer(pp);
System.out.println(ss.getComposer().getFirstName());//prints "gary"
Read the instructions carefully:
- create a folder called Assignment02
- write the code for classes Person and Song and save it in files called Person.java and Song.java in folder Assignment02
- download file Test02.class and put it in your folder Assignment02
- compile all java files in folder Assignment02
- type the following command in the DOS prompt window:
java Test02
- tests will be run on your code and appropriate messages will be printed out showing which tests passed and which failed. At the end the program will tell you which option to choose in the web form: 283progassignment02.htm
|