Question
Programming Challenge 2 (30 points): List and explain the Errors in the following program. Then submit the correct .java program. public class square { private
Programming Challenge 2 (30 points):
List and explain the Errors in the following program. Then submit the correct .java program.
public class square
{
private int sideLength;
private int area;
public Square(int initialLength)
{
sideLength = initialLength;
area = sideLength * sideLength;
}
public int area(){ return area;}
public void grow(){ sideLength = 2* sideLength;}
}
Programming Challenge 2 (50 points):
Implement a class Employee. An employee has a name (a string) and a salary (a double). (5 points)
Provide a constructor with two arguments (10 points)
public Employee(string employeeName, double currentSalary) and methods (15 points)
public String getName() public double getSalary() public void raiseSalary(double byPercent)
These methods return the name and salary, and raise the employees salary by certain percentage.
Sample usage:
Employee harry = new Employee(Hacker, Harry, 5000); Harry.raiseSalary(10); //Harry gets a 10 percent raise
Supply an EmployeeTester class that tests all methods. (15 points)
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