Question: Purpose: This lab focuses on interface inheritance and the use of polymorphism to more easily control the construction of an object at runtime. Task: Create
Purpose: This lab focuses on interface inheritance and the use of polymorphism to more easily control the construction of an object at runtime.
Task: Create a project called Customers. This project will consist of the following files: the Main class provided on Blackboard as well as the Customer, RegularCustomer, and PlatinumCustomer classes you will implement. Remember to include comments summarizing the various components of this lab.
1. Review the UML class diagram included with the directions for lab 5. Keep in mind the interface inheritance relationship between Customer and the other two classes: RegularCustomer and PlatinumCustomer.
2. Write the code for the Customer interface with each of the four abstract methods specified in the UML class diagram: displayName, displayBalance, addToBalance, and makeTransaction.
3. Write the code for the RegularCustomer with the two fields and four methods specified in the UML class diagram. Additionally, remember that RegularCustomer implements the Customer interface. The four methods should have the following behaviors:
a. The displayName method returns the following String with replaced with the name field: This regular customer is .
b. The displayBalance method returns the following String with replaced with the balance field formatted to two decimal places: The balance for this regular customer is $.
c. The addToBalance method adds the passed in deposit to the balance field.
d. The makeTransaction method subtracts the passed in cost from the balance field.
4. Write the code for the PlatinumCustomer with the two fields and four methods specified in the UML class diagram. Additionally, remember that PlatinumCustomer implements the Customer interface. The four methods should have the following behaviors:
a. The displayName method returns the following String with replaced with the name field: This platinum customer is .
b. The displayBalance method returns the following String with replaced with the balance field formatted to two decimal places: The balance for this platinum customer is $.
c. The addToBalance method adds the passed in deposit to the balance field.
d. The makeTransaction method subtracts the passed in cost from the balance field with a 10% reward deduction. For example, a transaction that normally costs $100 would instead be $90.
Main.java
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); Customer cust = null; String name = null; double balance = 0.0; String type = null; double deposit = 0.0; double cost = 0.0; System.out.print("What is the customer's name? "); name = keyboard.nextLine(); System.out.print("What is the customer's initial balance? "); balance = keyboard.nextDouble(); keyboard.nextLine(); System.out.print("What type of customer is this? "); type = keyboard.nextLine(); if (type.equals("regular")) { cust = new RegularCustomer(name, balance); } else if (type.equals("platinum")) { cust = new PlatinumCustomer(name, balance); } System.out.println(cust.displayName()); System.out.println(cust.displayBalance()); System.out.print("How much is this customer adding to the balance? "); deposit = keyboard.nextDouble(); cust.addToBalance(deposit); System.out.println(cust.displayBalance()); System.out.print("How much did this customer's purchase cost? "); cost = keyboard.nextDouble(); cust.makeTransaction(cost); System.out.println(cust.displayBalance()); } }

> Customer + displayName(): String + displayBalance() : String + addToBalance(deposit : double) : void + make Transaction(cost : double) : void A RegularCustomer - name : String - balance : double + displayName(): String + displayBalance(): String + addToBalance(deposit : double): void + makeTransaction(cost : double) : void Platinum Customer - name : String - balance : double + displayName(): String + displayBalance(): String + addToBalance(deposit : double): void + make Transaction(cost : double) : void
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
