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

CIS 283 - Programing assignment02

Email: jperezc at calstatela.edu

 

For this assignment you are going to write code for the following ONE class.

    • Person

This class has instance variables AND methods.

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
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"


Read the instructions carefully:

      1. create a folder called Assignment02
      2. create a file called Person.java and save it in folder Assignment02
      3. download file Test02.class.zip (Test02_java6.class.zip) and put it in your folder Assignment02
      4. compile all java files in folder Assignment02
      5. type the following command in the DOS prompt window:
      6. java Test02

      7. 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