Question

I am having trouble with my assignment and getting compile errors on the following code. The...

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." );
}
}

Homework Answers

Answer #1

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:

  1. Line 37
  2. Line 57
  3. Line 59
  4. Line 63

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." );
    }
}

=======================

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I have a 2 class code and it works everything is fine and runs as it...
I have a 2 class code and it works everything is fine and runs as it supposed too. What will the UML be for both classes. Here's the code, any help will be awsome, Thanks. import java.util.Scanner; public class PayRollDemo { public static void main(String[] args) { double payRate; int hours; PayRoll pr = new PayRoll(); Scanner keyboard = new Scanner(System.in); for (int index = 0; index < 7 ; index++ ) { System.out.println(); System.out.println("EmployeeID:" + pr.getEmployeeID(index)); System.out.println(); System.out.println("Enter the...
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
I need to get the Min and Max value of an array when a user inputs...
I need to get the Min and Max value of an array when a user inputs values into the array. problem is, my Max value is right but my min value is ALWAYS 0. how do i fix this? any help please!!! _________________________________________________________________________________________________ import java.util.Scanner; public class ArrayMenu{ static int count; static Scanner kb = new Scanner(System.in);             public static void main(){ int item=0; int[] numArray=new int[100]; count=0;       while (item !=8){ menu(); item = kb.nextInt();...
What's wrong with this code? #Java Why I am getting error in : int BusCompare =...
What's wrong with this code? #Java Why I am getting error in : int BusCompare = o1.numberOfBusinesses.compareTo(o2.numberOfBusinesses); public class TypeComparator implements Comparator<Type> { @Override public int compare(Type o1, Type o2) { // return o1.name.compareTo(o2.name); int NameCompare = o1.name.compareTo(o2.name); int BusCompare = o1.numberOfBusinesses.compareTo(o2.numberOfBusinesses); // 2-level comparison using if-else block if (NameCompare == 0) { return ((BusCompare == 0) ? NameCompare : BusCompare); } else { return NameCompare; } } } public class Type implements Comparable<Type> { int id; String name; int...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
Hello, I am having trouble getting my files to work together for this problem. Here is...
Hello, I am having trouble getting my files to work together for this problem. Here is the question and thank you for taking the time to answer it :) (1) Write an application that displays a menu of three items for the Jivin’ Java Coffee Shop as follows: American 1.99 Expresso 2.50 Latte 2.15 Prompt the user to choose an item using the number (1, 2, or 3) that corresponds to the item, or to enter 0 to quit the...
I am not sure what I am doing wrong in this coding. I keep getting this...
I am not sure what I am doing wrong in this coding. I keep getting this error. I tried to change it to Circle2D.java but it still comes an error: Compiler error: class Circle2D is public, should be declared in a file named Circle2D.java public class Circle2D { public class Exercise10_11 { public static void main(String[] args) {     Circle2D c1 = new Circle2D(2, 2, 5.5);     System.out.println("area: " + c1.getArea());     System.out.println("perimeter: " + c1.getPerimeter());     System.out.println("contains(3, 3): "...
i need to fix this java code. it not working on Repl.it website online compiler. error...
i need to fix this java code. it not working on Repl.it website online compiler. error -----------------------------------------------  javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . Main.java  java -classpath .:/run_dir/junit-4.12.jar:target/dependency/* Main Exception in thread "main" java.io.FileNotFoundException: C:\\Users\\Carter Collins\\Downloads\\input.txt (No such file or directory) at java.base/java.io.FileInputStream.open0(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:219) at java.base/java.io.FileInputStream.(FileInputStream.java:157) at java.base/java.util.Scanner.(Scanner.java:639) at Main.main(Main.java:18) exit status 1 ------------------------------------------------ codes:: import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner scan = new Scanner(System.in); Scanner sc...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT