In: Computer Science
Exercise #1:
Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time).
Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour.
Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the user to choose game tester type and enter the number of hours for the part-time testers.
Exercise #2:
CityToronto bank provides mortgages for individuals and businesses up to $300,000. Write a Java application that keeps track of mortgages and computes the total amount owed at any time (mortgage amount + interest).
Design the following classes to implement your application:
Mortgage – an abstract class that implements the MortgageConstants interface. A Mortgage includes a mortgage number, customer name, amount of mortgage, interest rate, and term.
Don’t allow mortgage amounts over $300,000. Force any mortgage term that is not defined in the MortgageConstants interface to a short-term, one year loan. Create a getMortgageInfo method to display all the mortgage data.
MortgageConstants – includes constant values for short-term (one year), medium-term (three years) and long-term (5 years) mortgages. It also contains constants for bank name and the maximum mortgage amount.
BusinessMortgage – extends Mortgage. Its constructor sets the interest rate to 1% over the current prime rate.
PersonalMortgage - extends Mortgage. Its constructor sets the interest rate to 2% over the current prime rate.
ProcessMortgage – a main class that create an array of 3 mortgages. Prompt the user for the current interest rate. Then in a loop prompts the user for a mortgage type and all relevant information for that mortgage. Store the created Mortgage objects in the array. When data entry is complete, display all mortgages.
1.
// GameTester.java
abstract public class GameTester
{
private String name; // name of the tester
private boolean fullTime; // value representing the
status (full-time, part-time)
// constructor to set the name and status of the
tester
public GameTester(String name, boolean fullTime)
{
this.name = name;
this.fullTime = fullTime;
}
// abstract method to return the salary
public abstract int salary();
}
//end of GameTester.java
// FullTimeGameTester.java
public class FullTimeGameTester extends GameTester
{
// constructor to set name and status
public FullTimeGameTester(String name)
{
super(name, true); // call
GameTester's constructor with name and status as true for
fullTime
}
// method to return the salary for full time
tester
public int salary()
{
return 3000 ;
}
}
// end of FullTimeGameTester.java
// PartTimeGameTester.java
public class PartTimeGameTester extends GameTester
{
// field for part time tester
private int hours;
// constructor to set the name, status and hours
public PartTimeGameTester(String name, int
hours)
{
super(name, false); // call
GameTester's constructor with name and status as false for
fullTime
this.hours = hours; // set hours
worked
}
// method to return the salary for part time
tester
public int salary()
{
return hours*20; // part time
tester are getting $20 per hour
}
}
// end of PartTimeGameTester.java
// GameTesterDriver.java
import java.util.Scanner;
public class GameTesterDriver {
public static void main(String[] args) {
int choice;
int hours;
String name;
GameTester tester;
Scanner keyboard = new
Scanner(System.in);
// input name of the tester
System.out.print("Enter name:
");
name = keyboard.nextLine();
// input the type of tester
System.out.println("1.
FullTimeGameTester\n2. PartTimeGameTester: ");
System.out.print("Enter your
choice(1/2): ");
choice = keyboard.nextInt();
// part time tester, input number
of hours
if(choice == 2)
{
System.out.print("Enter number of hours: ");
hours =
keyboard.nextInt();
tester = new
PartTimeGameTester(name, hours); // create a part time tester
}else
tester = new
FullTimeGameTester(name); // create a full time tester
System.out.println("Salary:
$"+tester.salary()); // display salary
}
}
// end of GameTesterDriver.java
Output: