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

CIS 283 - Programing assignment04

Email: jperezc at calstatela.edu

 

This is similar to programming challenge 1, from our book (page 105).

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

    • Person

Here are the specifications of class Person:

Person must have 3 public INSTANCE variables.

    • name of type String
    • age of type int
    • annualPay of type double

Methods of class Person:

getName
returns: String
arguments: none
what it does: it returns the value of variable name

setName
returns: nothing
arguments: one String
what it does: it assigns the value of its argument to the variable name. For example, if the value of the argument is "mary jones" then this method will assign the String "mary jones" as a value to variable name.

getAge
returns: int
arguments: none
what it does: it returns the value of variable age

setAge
returns: nothing
arguments: one int
what it does: it assigns the value of its argument to the variable age. For example, if the value of the argument is 23, then this method will assign the int 23 as a value to variable age.

getAnnualPay
returns: double
arguments: none
what it does: it returns the value of variable annualPay

setAnnualPay
returns: nothing
arguments: one double
what it does: it assigns the value of its argument to the variable annualPay. For example, if the value of the argument is 100000.0, then this method will assign the double 100000.0 as a value to variable anualPay.

print
returns: nothing
arguments: none
what it does: it prints the values of the instance variables in the following way. For example, if name is "Joe Mahoney", age is 26 and annualPay is 100000.0, then this method would print:

My name is Joe Mahoney, my age is 26 and 
I hope to earn $100000.0 per year.   

but if name is "mary jones", age is 21 and annualPay is 500000.0, then this method would print:

My name is mary jones, my age is 21 and 
I hope to earn $500000.0 per year. 

 

VERY IMPORTANT NOTE: your must use the methods

Test04.print

and

Test04.println

instead of System.out.print and System.out.println respectively. If you don't use the correct print methods your code will not pass the tests. Test04.print and Test04.println work in exactly the same way as System.out.print and System.out.println, they just have different names.

Notice:

    1. you must have downloaded either Test04.class or Test04_java6.class before compiling your file
    2. if you are using Test04_java6 you must use Test04_java6.print and Test04_java6.println



Read the instructions carefully:

    • create a folder called Assignment04
    • create a file called Person.java and save it in folder Assignment04
    • download file Test04.class.zip (Test04_java6.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 moodle quizz corresponding to programming exercise 04
Email: jperezc at calstatela.edu