Cal State L.A. logo and University Seal - Link back to main page

CIS 283 - Programing assignment03

Email: jperezc at calstatela.edu

 

For this assignment you are going to write code for the following TWO classes:

    • Song
    • Person

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:

Methods of class Person:

setFirstName
returns: nothing
arguments: 1 String
what it does: it assigns its argument to the variable fName
The following code example shows how this method would be used. This is NOT the code you have to write:

// if pp is a variable that contains a reference to Person, then:
pp.setFirstName("jon");// the argument is the String "jon"
System.out.println(pp.fName); // prints "jon"

another example:

pp.setFirstName("mary");//the argument in this case is the String "mary"
System.out.println(pp.fName); // prints "mary"

setLastName
returns: nothing
arguments: 1 String
what it does: it assigns its argument to the variable lName
Example:

// if pp is a variable that contains a reference to Person, then:
pp.setLastName("foo");//the argument in this case is the String "foo"
System.out.println(pp.lName);//prints "foo"

another example:

pp.setLastName("doe");
System.out.println(pp.lName);//this time this statement prints "doe"

getFirstName
returns: String
arguments: none
what it does: it returns the value of variable fName

Example:


// if pp is a variable that contains a reference to Person, then:

//next statment assigns a value to variable fName
pp.setFirstName("mary");//notice that getFirstName in the next statement has no argument

//next statement prints the current value of varuable fName
System.out.println(pp.getFirstName()); // prints "mary"

getLastName
returns: String
arguments: none
what it does: it returns the value of variable lName

Example:

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

setComposer
returns: nothing
arguments: 1 Person

what it does: it assigns its argument to the variable composer

getTitle
returns: String
arguments: none
what it does: it returns the value of variable title


getComposer
returns: Person
arguments: none
what it does: it returns the value of variable composer


Read the instructions carefully:

    • create a folder called Assignment03
    • create a file called Person.java and save it in folder Assignment03
    • download fileTest03.class.zip(Test03_java6.class.zip) and put it in your folder Assignment03
    • compile all java files in folder Assignment03
    • type the following command in the DOS prompt window:
    • java Test03

    • 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 moodle quizz corresponding to programming exercise 02
Email: jperezc at calstatela.edu