Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I can't get the first if statement to run only if the person has selected yes to the service.. if they select no it should

I can't get the first if statement to run only if the person has selected yes to the service.. if they select no it should immediately go to the else message .. but it asks the room message first then goes to the end message, works fine with the burst pipes if. Please help!

import java.util.Scanner; public class Plumber { String service; int numberRooms; int burstPipes; int numberPipes; double roomsCost; double pipesCost; int NumberRooms; double cFlood1 = 300.00; double cFlood2 = 500.00; double cFlood3 = 750.00; double cPipe1 = 50; double cPipe2 = 70; double cPipe3 =100; double cost; String BurstPipes =""; public static String message1 = ""; public static String message2 =""; Plumber(String srv, int numRms, int bstPipes, int numPipes) { service = srv; numberRooms = numRms; burstPipes = bstPipes; numberPipes = numPipes; } Plumber(String 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 "; String p2 = "1 room "; String p3="2 rooms "; String p4="3 or more rooms "; String p5=" no burst pipes "; String p6=" 1 burst pipe "; String p7=" 2 burst pipes "; String p8=" 3 burst pipes "; if(this.service.equals("Y") || this.service.equals("y")); { Scanner userInput = new Scanner(System.in); System.out.print(" How many rooms were flooded - 1, " + "2, " + "or 3" + "+ >>"); numberRooms = userInput.nextInt(); System.out.print(" Were there any burst pipes? Please enter Y for yes " + "or" + " N for no >> "); BurstPipes = userInput.next(); switch(this.numberRooms) { case 0: message1 =p1; case 1: this.roomsCost += this.cFlood1; message1 =p2; break; case 2: this.roomsCost += this.cFlood2; message1 =p3; break; case 3: this.roomsCost += this.cFlood3; message1 =p4; break; } if(this.BurstPipes.equals("Y") || this.BurstPipes.equals("y")) { System.out.print(" How many pipes burst? - 1, " + "2, " + "or 3" + ">>"); numberPipes = userInput.nextInt(); switch(this.numberPipes) { case 0: message2 = p5; break; case 1: this.pipesCost += this.cPipe1; message2 = p6; break; case 2: this.pipesCost += this.cPipe2; message2 = p7; break; case 3: this.pipesCost += this.cPipe3; message2 = p8; } } } } public void ComputePrice() { if(this.service.equals ("y") || this.service.equals("Y")) { System.out.println(" You are being charged for a natural flood"); this.cost = this.roomsCost + this.pipesCost; if(!(this.numberRooms==0)) System.out.printf("Room Flood Repair for " + message1+ "= $" + roomsCost,numberRooms,roomsCost); if(!(this.numberPipes==0)) System.out.printf(" Pipe Repair for" + message2+ "= $"+ 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) { String service = "Y"; int numberRooms = 2; String burstPipes = "Y" ; int numberPipes = 1; Scanner userInput = new Scanner(System.in); System.out.print("Do you need a plumbing services? Enter Y for Yes" + " or No for No>>"); service = userInput.nextLine(); Plumber firstCustomer = new Plumber(service, numberRooms, burstPipes,numberPipes); firstCustomer.display(); firstCustomer.ComputePrice(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago