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

CIS 283 - Programing assignment04

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 public 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 (if you were using class Person in a driver program):

    Person pp;
    pp = new Person();
    pp.setFirstName("jon");
    System.out.println(pp.getFirstName()); // prints "jon"

HINT:
      void setFirstName(String ff){
	fName = ff;
    }
  

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.getLastName());//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"
  

HINT:
    String getFirstName(){
	return fName;
    }

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 public INSTANCE variables.

    • title of type String
    • composer of type Person (you will create the type Person in this assignment)

    • HINT:
        String title;
        Person composer;
      

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.getTitle()); // 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 Assignment04
    • create a file for each class required (Song.java and Person.java)
    • write all the methods described above
    • download file Test04.class.zip and put it in your folder Assignment04
    • compile all java files in folder Assignment04
    • type the following command in the DOS prompt window:

    java Test04

    • 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
Email: jperezc at calstatela.edu