java hw
CSE 110 - ASSIGNMENT # 6 – Fall 2015
Due: Tuesday November 3rd by 10:00AM Maximum Points: 20 pts
What This Assignment Is About:
• implementing classes
• understanding and accessing instance variables
• implementing methods
• object construction
• constructors
• encapsulation
Your programming assignments require individual work and effort to be of any benefit. Every student
must work independently on his or her assignments. This means that every student must ensure that
neither a soft copy nor a hard copy of their work gets into the hands of another student. Sharing your
assignments with others in any way is NOT permitted.
Violations of the University Academic Integrity policy will not be ignored. The university academic
integrity policy is found at http://www.asu.edu/studentlife/judicial/integrity.html
Use the following Coding Guidelines:
Give identifiers semantic meaning and make them easy to read (examples numStudents,
grossPay, etc).
Keep identifiers to a reasonably short length.
User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case
with uppercase word separators for all other identifiers (variables, methods, objects).
Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes
classes, methods, and code associated with ifs, switches and loops. Be consistent with the
number of spaces or tabs that you use to indent.
Use white space to make your program more readable.
Use comments after the ending brace of classes, methods, and blocks to identify to which block it
belongs.
Assignments Documentation:
At the beginning of each programming assignment you must have a comment block with the following
information:
/*-------------------------------------------------------------------------
// AUTHOR: your name
// FILENAME: title of the source file
// SPECIFICATION: description of the program
// YOUR Lab Letter and Name of the TA for your Closed lab
// FOR: CSE 110- homework #- days and time of your class
// TIME SPENT: how long it took you to complete the assignment
//----------------------------------------------------------------------*/
Reasonably good amount of comments should be added in your program so that it is easy for other people
to understand it. Please see the comment style in the textbook.
Part 1: Written Exercises: (6 points)
Note: The answers to the following questions should be typed in the block of comments in the
Employee.java file. Please make sure they're commented out (green). Type them neatly and make them
easy to read for the graders
Object References: You use a null reference to indicate that an object variable (reference) does not refer
to any object. Of course, you cannot invoke methods on a null reference since there is no object to which
the method would apply. Consider this program segment:
String str = null;
System.out.println(str);
str.length();
System.out.println(str);
1. What problem arises when executing these statements? Do the statements produce any printout beyond
an error message? If so, what printout? (2 points)
2. Explain the difference between (2 points)
new BankAccount(5000);
and
BankAccount b;
Part 2: Programming Assignment: (16 points)
Your assignment is to implement a class Employee (there is no main method). An Employee has a name
(a String), a salary (a double) and a number of years of experience (an integer). Also your class Employee
must have a static instance variable to keep track of number of employees. The class Employee must
include the following constructors and methods.
Method header Method Description
Employee( ) Default constructor sets the name to "???”, the
salary to 0.0 and years of experience to 0
Employee (String name,double
salary, int years)
Constructs an Employee given the name as a
String, salary as double and years of experience as
an integer
Employee (String str) Constructs an Employee given a string and using
methods in class String or Scanner to extract name,
salary: years of experiences. For Example the string
"Bond:70000:20"
String getName( ) Returns the name of the employee
int getYears( ) Returns the number of years of experience for the
employee
double getSalary( ) Returns the employee's salary.
void setYears() A method to be run annually; increments the years
of experiences annually
void raiseSalary (double
byPercent)
Takes one parameter and raises the employee's
salary by that percent
Employee makesMore(Employee x) Compares two salaries and returns the Employee
who makes more money
static int getNumEmployees() Returns the number of employees
String toString( ) Returns a String with information on each
Employee (etc. name, salary, and years of
experiences). The salary needs to be printed with
currency format.
Save the Employee class in a file called Employee.java and use a test driver called Assignment6.java,
which has the main method to create new Employee objects and to test your class. A sample output is
shown below.
Important Notes: Your class should have exactly the method headers that are described or otherwise your
class will not work with the test driver program (Assignment6.java) that is provided. You should never
change the test driver program, i.e., Assignment6.java, but instead make changes to Employee class to
make it work.
Sample output:
Enter name of the employee? Smith
Enter salary for Smith? 40000
Enter number of years for Smith? 5
Command Options
-----------------------------------
'a': prints info
'b': raise salary
'c': increment the years of experience
'd': who makes more
'e': number of employees
'?': Displays the help menu
'q': quits
Please enter a command or type ?
a
Name: Smith
Salary: $40,000.00
Years of Experience: 5
Name: Bond
Salary: $70,000.00
Years of Experience: 20
Please enter a command or type ?
d
Bond is making more.
Please enter a command or type ?
b
Enter the amount of raise:
5
Name: Smith
Salary: $42,000.00
Years of Experience: 5
Name: Bond
Salary: $73,500.00
Years of Experience: 20
Please enter a command or type ?
?
Command Options
-----------------------------------
'a': prints info
'b': raise salary
'c': increment the years of experience
'd': who makes more
'e': number of employees
'?': Displays the help menu
'q': quits
Please enter a command or type ?
d
Bond is making more.
Please enter a command or type ?
e
They are 2 employees.
Please enter a command or type ?
c
Year has been added.
Please enter a command or type ?
a
Name: Smith
Salary: $42,000.00
Years of Experience: 6
Name: Bond
Salary: $73,500.00
Years of Experience: 21
Please enter a command or type ?
q
Submit your homework by following the instructions below:
Go to the course web site (my.asu.edu), and then click on the on-line Submission tab:
https://courses.eas.asu.edu/cse110/
Submit both the files, Employee.java and Assignment6.java files on-line. Make sure to choose
Hw6 from drop-down box.
Employee.java should have the following, in order:
In comments, the assignment Header described in "Important Note".
In comments, the answers to questions in part 1.
Your files must compile and run as you submit it. You can confirm this by viewing your
submission results
Important Note: You may resubmit as many times as you like until the deadline, but we will only mark
your last submission.
NO LATE ASSIGNMENTS WILL BE ACCEPTED.