In: Computer Science
Problem Description A local veterinarian at The Pet Boutique has asked you to create a program for her office to create invoices for her patient’s office visits. When a customer brings their pet to the boutique, the clerk gets the Customer’s name, address, phone number and email address, as well as the pets name, pet type, pet age, and pet weight. After the customer sees the Veterinarian, the clerk determines the charges for the services, and medications for the office visit and prints the invoice for the customer’s records. The invoice should include the Customer’s name, address, phone, and email address, the pet’s name, type, age, and weight, service charges, medication charges, sales tax, and the total charges for the office visit. All calculations should take place in the class methods. All display should use method calls to the get methods from the classes to display the appropriate information. Do not accept any numbers that are less than or equal to zero. Calculate the sales tax using a constant equal to .0925 and limit the display to two decimal places. in Java
check out the solution and do COMMENT for any doubts or modifications.
---------------------------------------------------------------------------------------
// import required classess
import java.util.*;
// class 'botique'
class Botique {
// class variables
String cname, caddress, cemail, pname, ptype;
int cphone, page, pweight;
// all calculations are done with class methods
// setters - sets the given variable values to class
variables
void setCName(String cname) {
this.cname = cname;
}
void setCAddress(String a) {
this.caddress = a;
}
void setCEmail(String e) {
this.cemail = e;
}
void setPName(String pname) {
this.pname = pname;
}
void setPType(String pt) {
this.ptype = pt;
}
void setCPhone(int ph) {
this.cphone = ph;
}
void setPAge(int age) {
this.page = age;
}
void setPWeight(int pw) {
this.pweight = pw;
}
// does the calculations for charges
// getters - gets the class variables values
String getCName() {
return cname;
}
String getCAddress() {
return caddress;
}
String getCEmail() {
return cemail;
}
String getPName() {
return pname;
}
String getPType() {
return ptype;
}
int getCPhone() {
return cphone;
}
int getPAge() {
return page;
}
int getPWeight() {
return pweight;
}
// charges
double getSCharge() {
// as formula or criteria not specified for charges
calculations.
// assuming some random values between 200 - 500 for service and
medication charge.
double scharge;
scharge = (Math.random()*((500.0-200.0)+1))+200.0;
return scharge;
}
double getMCharge() {
double mcharge;
mcharge = (Math.random()*((500.0-200.0)+1))+200.0;
return mcharge;
}
// pass service and medication charge to find total charge along
with sales tax
double getTCharge(double sc,double mc) {
double tcharge;
// given sales tax
double stax = 0.0925;
tcharge = sc + mc + stax;
return tcharge;
}
}
// main class
public class MyClass {
public static void main(String args[]) {
// required declarations
String cname, caddress, cemail, pname, ptype;
int cphone, page, pweight;
// create a Scanner class object to read user input
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
// create a botique object to access its elements
Botique bq = new Botique();
System.out.println("Input the details : ");
System.out.print("Customer's Name : ");
cname = sc.nextLine();
System.out.print("Address : ");
caddress = sc.nextLine();
// validation for integers
while(1) {
System.out.print("Input Valid Phone number : ");
cphone = sc.nextInt();
if (cphone > 0)
break;
}
System.out.print("Email address : ");
cemail = sc.next();
System.out.print("Pet's Name : ");
pname = sc.nextLine();
System.out.print("Pet's Type : ");
ptype = sc.nextLine();
// validation for integers
while(1) {
System.out.print("Input Valid Pet's age : ");
page = sc.nextInt();
if (page > 0)
break;
}
while(1) {
System.out.print("Input Valid Pet's Weight : ");
pweight = sc1.nextInt();
if (page > 0)
break;
}
// set the user input to class variables
bq.setCName(cname);
bq.setCAddress(caddress);
bq.setCEmail(cemail);
bq.setPName(pname);
bq.setPType(ptype);
bq.setCPhone(cphone);
bq.setPAge(page);
bq.setPWeight(pweight);
// print as required with 'get()' methods
System.out.println("\n\n------------Invoice--------------");
System.out.println("Customer's Name : " + bq.getCName());
System.out.println("Address : " + bq.getCAddress());
System.out.println("Phone number : " + bq.getCPhone());
System.out.println("Email address : " + bq.getCEmail());
System.out.println("Pet's Name : " + bq.getPName());
System.out.println("Pet's Type : " + bq.getPType());
System.out.println("Pet's age : " + bq.getPAge());
System.out.println("Pet's Weight : " + bq.getPWeight());
double scharge = bq.getSCharge();
double mcharge = bq.getMCharge();
double tcharge = bq.getTCharge(scharge, mcharge);
System.out.printf("\nService charges : $ %.2f" , scharge);
System.out.printf("\nMedication charges : $ %.2f" , mcharge);
System.out.printf("\nSales tax : $ 0.0925");
System.out.printf("\n\nTotal charges : $ %.2f" , tcharge);
}
}