Question
Java Logic - the idea is for this Plumbers.java to ask the customer if there house is flooded , how many rooms, if pipes were
Java Logic - the idea is for this Plumbers.java to ask the customer if there house is flooded , how many rooms, if pipes were damaged and if so how many.. then to pas that information into the plumber constructore and the bill for the services. The ComputePrice() isn't displaying the info and the switches aren't taking in the informations in the display().
import java.util.Scanner;
public class Plumber { int service; int numberRooms; int burstPipes; int numberPipes; double roomsCost; double pipesCost; private int NumberRooms; double cFlood1 = 300.00; double cFlood2 = 500.00; double cFlood3 = 750.00; double cPipe1 = 50.00; double cPipe2 = 70.00; double cPipe3 =100.00; double cost = 0; String BurstPipes ="";
private Plumber(int srv, int numRms, int bstPipes, int numPipes) { service = srv; numberRooms = numRms; burstPipes = bstPipes; numberPipes = numPipes; }
private Plumber(int service, int numberRooms, String burstPipes, int numberPipes) { this.service = service; this.numberRooms = numberRooms; this.BurstPipes = burstPipes; this.numberPipes = numberPipes; }
public void display() { String p1 = " no rooms flooded", p2 = "1 room flooded", p3="with 2 rooms flooded", p4="with 3 or more rooms flooded", p5=" no burst pipes apparent ", p6=" and 1 burst pipe apparent ", p7=" and 2 burst pipes apparent ", p8=" and 3 burst pipes apparent "; if(service == 1) { System.out.println(" You have stated that the damage to your house involves a natural flood."); switch(NumberRooms) { case 0: System.out.printf("%s",p1); case 1: roomsCost += cFlood1; System.out.printf("%s",p2); break; case 2: roomsCost += cFlood2; System.out.printf("%s",p3); break; case 3: roomsCost += cFlood3; System.out.printf("%s",p4); break; } if(BurstPipes.equals("Y") || BurstPipes.equals("y")) { switch(burstPipes) { case 0: System.out.printf("%s",p5); break; case 1: pipesCost += cPipe1; System.out.printf("%s",p6); break; case 2: pipesCost += cPipe2; System.out.printf("%s",p7); break; case 3: pipesCost += cPipe3; System.out.printf("%s",p8); } } } } public void ComputePrice() { if(service ==1) cost = roomsCost + pipesCost; if(!(roomsCost==0)) System.out.printf(" %s Room Flood Repair = $%s ",numberRooms,roomsCost); if(!(pipesCost==0)) { System.out.printf("%s Pipe Repair = $%s ",numberPipes,pipesCost); System.out.printf(" ------------ " + "Estimated Amount Due: $%s ",cost); System.out.print("** Please Have This Amount Available -" + " Fees Are Due At Time Of Service. This Is An Estimate Only." + " Final Bill Will Be Based On Onsite Evaluation." + " All Work Will Be Discussed And Agreed Upon Prior To Repairs. ** "); } else System.out.printf("If you need services, please come visit us again. "); }
public static void main(String[] args) {
double cFlood1 = 300.00; double cFlood2 = 500.00; double cFlood3 = 750.00; double cPipe1 = 50.00; double cPipe2 = 70.00; double cPipe3 =100.00; double roomsCost; double pipesCost; double cost = 0.00; int service; int numberRooms; int numberPipes; String burstPipes ="";
Scanner userInput = new Scanner(System.in); System.out.print(" Please enter 1 "+ "if there was flood damage>>"); service = userInput.nextInt(); System.out.print(" How many rooms were flooded - 1" + "2" + "3" + "or more >>"); numberRooms = userInput.nextInt(); burstPipes = userInput.nextLine(); System.out.print(" Were there any burst pipes? Please enter Y" + "or" + "N >>"); burstPipes = userInput.nextLine(); System.out.print(" How many pipes burst? - 1" + "2" + "3" + "or more>>"); numberPipes = userInput.nextInt();
Plumber firstCustomer = new Plumber(service, numberRooms, burstPipes,numberPipes);
firstCustomer.ComputePrice(); firstCustomer.display(); } }
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