Question
Q complete the program with switch method in java import java.util.*; /** === COMPLETE THIS APPLICATION AND MAKRE SURE TO DOCUMENT THE CODE === An
Q complete the program with switch method in java
import java.util.*; /** === COMPLETE THIS APPLICATION AND MAKRE SURE TO DOCUMENT THE CODE === An application simulating the servicing management software at a mechanic auto shop. "An auto mechanic shop wants to keep track of their clients so that they can send invoices for customers with balance or email reminders of upcoming services. Please design and implement a client class with at least 5 attributes, constructors, a print invoice method, and a generate email reminder method(this method just generate the text for the email only). Note: a shop has many clients, and a client can have multiple services, each service carries a charge" */ public class AutoShop { public static void main(String[] args){ //a shop has a list of clients ArrayList customers = new ArrayList(); //creating your list of Client objects
System.out.println("Creating a service"); Service s = new Service("Oil Change", "3/21/2014", 30.0); System.out.print(s);
Service s2 = new Service("Tire Rotation", "2/21/2018", 20.0); s2.pay(6.0);
Client c = new Client("abc ", "123", "mail.com"); c.getService(s); //give the customer a service c.getService(s2);
System.out.println( " " + c);
// main menu to service customer /* 1. add a new client - keep it as a current client 2. find a client with a given name - keep it as a current client 3. add a service for the curent client 4. print the current client's balance 5. print the current client's histoy of services 6. print all the clients' balances 7. exit [save all the data to a file option and retrieve it back when the program starts]
*/ } } /** Encapsulating of a service performed by a shop */ class Service{ private String name, when; private double charge, paidAmount; public Service (String name, String when, double charge){ this.name = name; this.when = when; this.charge = charge; this.paidAmount = 0; }
public double pay(double amt){ this.paidAmount = amt; return this.charge - this.paidAmount; //amount owed }
public double getAmtOwe(){ return this.charge - this.paidAmount; }
public String toString(){ return " Service Name: " + this.name + " Cost: $" + this.charge + " Paid: $" + this.paidAmount + " Balance: $" + (this.charge - this.paidAmount); } }
/** encapsulating of a client's personal information and services done */ class Client { private Service[] services; private String name, addr, email; private final int MAX_SERVICES_KEPT = 10; private int nextServiceLoc;
public Client(String name, String addr, String email){ this.name = name; this.addr = addr; this.email = email; this.services = new Service[MAX_SERVICES_KEPT]; this.nextServiceLoc = 0; } // add a new service into tte client public void getService(Service s){ if(this.nextServiceLoc >= this.services.length - 1){ this.services[this.nextServiceLoc] = s; this.nextServiceLoc = 0; //go back to the beginning }else this.services[this.nextServiceLoc++] = s; }
//calculating the balance of all service done private double getBal(){ double bal = 0; if(this.services != null){ for(int i = 0; i < this.services.length; i++) if(this.services[i] != null) bal += this.services[i].getAmtOwe(); } return bal; } //return the client as a string public String toString(){ return " Customer's name: " + this.name + " Address: " + this.addr + " Email: " + this.email + " Balance: $" + getBal(); } }
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