I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments.
/*
Chapter 5, Exercise 2
-Write a class "Plumbers" that handles emergency plumbing
calls.
-The company handles natural floods and burst pipes.
-If the customer selects a flood, the program must prompt the user
to determine the amount of
damage for pricing.
-Flood charging is based on the numbers of damaged rooms.
1 room costs $300.00, 2 rooms cost $500.00, and 3 or more rooms
cost $750.00.
-Pipe bursting is based on the number of pipes: 1 pipe costs
$50.00, 2 pipes cost $70.00,
and 3 or more pipes cost $100.00.
-The Plumber class should contain a nested class to handle
billing charges.
Use And, Or, and Not in the if statements to obtain the customers'
inputs.
*/
import java.util.Scanner; //Import scanner
public class Plumbers //create Plumbers class
{
private void getData()
{
double rmsPrice = 0;
double pipesPrice = 0;
double roomOne = 300.00;
double roomTwo = 500.00;
double roomThreePlus = 750.00;
double pipeOne = 50.00;
double pipeTwo = 70.00;
double pipeThreePlus = 100.00;
Scanner scanner = new Scanner(System.in);
//Ask about flooding
System.out.println("Thank you for calling. If you are flodding
please enter 1 for yes and 2 for no: ");
int userInput1 = scanner.nextInt();
//Ask about how many rooms are flooded if 1
if (userInput1 == 1)
System.out.println("How many pipes?. Please enter 1 for 1 pipe, 2
for 2 pipes, or 3 for 3 or more: ");
int userInput2 = scanner.nextInt();
if (userInput2 == 1)
rmsPrice = roomOne;
else
if (userInput2 == 2)
rmsPrice = roomTwo;
else
if (userInput2 == 3)
rmsPrice = roomThree;
//Ask about broken pipes
System.out.println("Do you have broken pipes? Please enter 1 for
yes and 2 for no: ");
int userInput3 = scanner.nextInt();
//Ask about how many pipes are busted if 1
if (userInput3 == 1)
System.out.println("How many pipes?. Please enter 1 for 1 pipe, 2
for 2 pipes, or 3 for 3 or more: ");
int userInput4 = scanner.nextInt();
if (userInput4 == 1)
pipesPrice = pipeOne;
else
if (userInput4 == 2)
pipesPrice = pipeTwo;
else
if (userInput4 == 3)
pipesPrice = pipeThree;
if (userInput1 == 1 && userInput3 == 1 &&
userinput4 >= 3 && userInput2 >= 3)
System.out.println("Wow! You have some Biblical flodding going on
there!");
System.out.println("Your total is: $" + (rmsPrice +
pipesPrice));
else
if ((userInput1 == 1 && userInput3 == 1) || (userInput1 ==
0 && userInput3 == 1) || (userInput1 == 1 &&
userInput3 == 0))
System.out.println("Your total is: $" + (rmsPrice +
pipesPrice));
else
if ((userInput1 == 0 && userInput3 == 0))
System.out.println("Please enter an amount of rooms or pipes."
);
}
}
You have done simple mistakes like variable names using incorrectly, else without if.
Please check the lines in the below picture to get out of compile-time errors:
I have marked them bold.
FINAL CODE:
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the
below screenshot is neatly indented for better
understanding.
import java.util.Scanner; //Import scanner public class Plumbers //create Plumbers class { private void getData() { double rmsPrice = 0; double pipesPrice = 0; double roomOne = 300.00; double roomTwo = 500.00; double roomThreePlus = 750.00; double pipeOne = 50.00; double pipeTwo = 70.00; double pipeThreePlus = 100.00; Scanner scanner = new Scanner(System.in); //Ask about flooding System.out.println("Thank you for calling. If you are flodding please enter 1 for yes and 2 for no: "); int userInput1 = scanner.nextInt(); //Ask about how many rooms are flooded if 1 if (userInput1 == 1) System.out.println("How many pipes?. Please enter 1 for 1 pipe, 2 for 2 pipes, or 3 for 3 or more: "); int userInput2 = scanner.nextInt(); if (userInput2 == 1) rmsPrice = roomOne; else if (userInput2 == 2) rmsPrice = roomTwo; else if (userInput2 == 3) rmsPrice = roomThreePlus; //Ask about broken pipes System.out.println("Do you have broken pipes? Please enter 1 for yes and 2 for no: "); int userInput3 = scanner.nextInt(); //Ask about how many pipes are busted if 1 if (userInput3 == 1) System.out.println("How many pipes?. Please enter 1 for 1 pipe, 2 for 2 pipes, or 3 for 3 or more: "); int userInput4 = scanner.nextInt(); if (userInput4 == 1) pipesPrice = pipeOne; else if (userInput4 == 2) pipesPrice = pipeTwo; else if (userInput4 == 3) pipesPrice = pipeThreePlus; if (userInput1 == 1 && userInput3 == 1 && userInput4 >= 3 && userInput2 >= 3) System.out.println("Wow! You have some Biblical flodding going on there!"); System.out.println("Your total is: $" + (rmsPrice + pipesPrice)); if ((userInput1 == 1 && userInput3 == 1) || (userInput1 == 0 && userInput3 == 1) || (userInput1 == 1 && userInput3 == 0)) System.out.println("Your total is: $" + (rmsPrice + pipesPrice)); else if ((userInput1 == 0 && userInput3 == 0)) System.out.println("Please enter an amount of rooms or pipes." ); } }
=======================
Get Answers For Free
Most questions answered within 1 hours.