Question
Write a program named Employee.java that is a class representing an Employee that has the following Attributes ( Instance Variables ) Employee ID int Employee
Write a program named Employee.java that is a class representing an Employee that has the following Attributes (Instance Variables)
Employee ID int
Employee Name String
Employee Status boolean
Employee Salary double
Company Name String (This is a static variable)
Step 2: Write a no-arg constructor that assigns values for the above Instance Variables as follows:
Employee ID = -1
Employee Name = Unknown
Employee Status = false
Employee Salary = 0
Step 3: Write a constructor that takes ID, Name and Status as input parameters and assign those values to the Instance Variables
Step 4: Write getter methods to return each of the 4 Attributes above
Step 5: Write a setter method to set the salary of an Employee based on the input parameter the method will receive
Step 6: Write a program named MyCompany.java
Step 7: Create an emp1 object and use the no-arg constructor
Step 8: Print the Company Name
Step 9: Print the output of the emp1 object as in screenshot below
Step 10: Create an emp2 object and give the appropriate values for ID, Name and Status
Step 11: Prompt the user for Salary.
Step 12: Get the input and call the setter method on the emp2 object to set the Salary Step 13: Print the Company Name
Step 14: Print the output of the emp2 object as in screenshot below
Sample run of the program:
Write a program named Employee.java that is a class representing an Employee that has the following Attributes (Instance Variables)
Employee ID int
Employee Name String
Employee Status boolean
Employee Salary double
Company Name String (This is a static variable)
Step 2: Write a no-arg constructor that assigns values for the above Instance Variables as follows:
Employee ID = -1
Employee Name = Unknown
Employee Status = false
Employee Salary = 0
Step 3: Write a constructor that takes ID, Name and Status as input parameters and assign those values to the Instance Variables
Step 4: Write getter methods to return each of the 4 Attributes above
Step 5: Write a setter method to set the salary of an Employee based on the input parameter the method will receive
Step 6: Write a program named MyCompany.java
Step 7: Create an emp1 object and use the no-arg constructor
Step 8: Print the Company Name
Step 9: Print the output of the emp1 object as in screenshot below
Step 10: Create an emp2 object and give the appropriate values for ID, Name and Status
Step 11: Prompt the user for Salary.
Step 12: Get the input and call the setter method on the emp2 object to set the Salary Step 13: Print the Company Name
Step 14: Print the output of the emp2 object as in screenshot below
Sample run of the program:
2. Create a class named Student. A Student has fields for an ID number, total score earned by the Student and Grade of the Student.
Add a static variable SchoolName and give it a name of your choice
Re-use logic in program of Week 6 to compute the grade of a student and store it for this student using a setter method.
Create a class MySchool and create 3 Student objects.
For each object prompt the user for an ID Number and total score.
Display the Output as Below:
------------------------------------
School of Technology
------------------------------------
ID: 100
Score: 97
Grade: A+
------------------------------------
ID: 105
Score:80
Grade: A-
------------------------------------
ID: 110
Score: 50
Grade: D
------------------------------------
Below are for Further Practice for those interested
Suppose that you have created a program with only the following variables.
int a = 5;
int b = 6;
Suppose that you also have a method with the following header:
public static void mathMethod(int a)
Which of the following method calls are legal?
a. mathMethod(a);
b. mathMethod(b);
c. mathMethod(a + b);
d. mathMethod(a, b);
e. mathMethod(2361);
f. mathMethod(12.78);
g. mathMethod(29987L);
h. mathMethod();
i. mathMethod(x);
j. mathMethod(a / b);
Suppose that you have created a program with only the following variables.
int age = 34;
int weight = 180;
double height = 5.9;
Suppose that you also have a method with the following header:
public static void calculate(int age, double size)
Which of the following method calls are legal?
a. calculate(age, weight);
b. calculate(age, height);
c. calculate(weight, height);
d. calculate(height, age);
e. calculate(45.5, 120);
f. calculate(12, 120.2);
g. calculate(age, size);
h. calculate(2, 3);
i. calculate(age);
j. calculate(weight, weight);
3.
a. Create a class named Lease with fields that hold a tenants name, apartment number, monthly rent amount, and term of the lease in months.
Include a constructor that initializes the tenants name to ABC, the apartment number to 0, the rent to 1000, and the term to 12.
Also include methods to get and set each of the fields.
Include a method named addPetFee() that adds $10 to the monthly rent value. Save the class as Lease.java.
b. Create a class named TestLease that imports the Scanner class
In this class write a static method getData()that takes a Lease object as input parameter, prompts the user for the details of Tenant Name, Apartment No, Lease Term and Rent amount AND then calls setter methods on the Lease object to set these values
In this class, write another method showValues() that takes a Lease object as input parameter, and calls the getter methods on the Lease object to display the details of the Lease.
Now write the public static void main method.
Within the main method, declare the 1st Lease object.
Call the showValues() method to display the Lease details.
Now declare the 2nd Lease object
Call the getData()method on this Lease object.
Call the showValues() method to display the Lease details.
Call the addPetFee() method on this Lease object
Confirm that the fee is added to the rent by calling the showValues() method for the Lease object again.
Save the application as TestLease.java.
Sample run of the program:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started