Question

In: Computer Science

Exercise #1: Create an abstract class called GameTester. The GameTester class includes a name for the...

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.

Solutions

Expert Solution

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:



Related Solutions

in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and average petrol consumption. Provide 2 constructors, the first takes name and type as parameter, the second takes four parameters for the four instance variables. (2 pt) Provide also a method called distancePerTank that calculate the average distance that a vehicle can travel if the tank is full (multiplies the tank size by the average petrol consumption), then returns the value. (2 pt) Provide a...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape. Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester...
Write a Java application that implements the following: 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...
Animal class Create a simple class called Animal instantiated with a name and a method toString...
Animal class Create a simple class called Animal instantiated with a name and a method toString which returns the name. Cat class Create a simple class Cat which extends Animal, but adds no new instance variable or methods. RedCat class Create a simple class RedCat which extends Cat, but adds no new instance variable or methods. WildCardTester class Create a class with the main method and methods addCat, deleteCat and printAll as follows. addCat method Has two parameters, an ArrayList...
Create a class called Student which stores • the name of the student • the grade...
Create a class called Student which stores • the name of the student • the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into the grade field. • Calculate the...
Create a C# Application. Create a class object called “Employee” which includes the following private variables:...
Create a C# Application. Create a class object called “Employee” which includes the following private variables: firstN lastN idNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: constructor properties CalcPay(): Calculate the regular pay and overtime pay. Create...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT