Question

In: Computer Science

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

Solutions

Expert Solution

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

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


Related Solutions

I am currently having trouble understanding/finding the errors in this python code. I was told that...
I am currently having trouble understanding/finding the errors in this python code. I was told that there are 5 errors to fix. Code: #!/usr/bin/env python3 choice = "y" while choice == "y": # get monthly investment monthly_investment = float(input(f"Enter monthly investment (0-1000):\t")) if not(monthly_investment > 0 and monthly_investment <= 100): print(f"Entry must be greater than 0 and less than or equal to 1000. " "Please start over.")) #Error 1 extra ")" continue # get yearly interest rate yearly_interest_rate = float(input(f"Enter...
I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
My code does not compile, I am using vim on terminal and got several compiling errors...
My code does not compile, I am using vim on terminal and got several compiling errors this is C++ language I need help fixing my code below is the example expected run and my code. Example run (User inputs are highlighted): Enter your monthly salary: 5000 Enter number of months you worked in the past year: 10 Enter the cost of the car: 36000 Enter number of cars you’ve sold in the past year: 30 Enter number of misconducts observed...
Hello, I am having trouble getting started on my project and building these functions. How do...
Hello, I am having trouble getting started on my project and building these functions. How do I build a function that continuously adds new "slices" to the list if they are below/above the size limit? I didn't copy the entire problem, but just for reference, when the code is run it will take user input for size limit (L), time cost for a random slice(R), and time cost for an accurate slice(A). Question: In real life, a steak is a...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
Develop the following code for quiz (i am getting some errors)in python in such a manner...
Develop the following code for quiz (i am getting some errors)in python in such a manner that it shoulde be having extra 3 attempts(for wrong answrs) for all questions if the user entered wrong answer · for ex: If the user entered correct answer for first question #then 3 attempts will be carried to next questions. If the user entered 3 times wrong answer in 1st question itself means it sholud display as no more attempts and you got o...
I am having trouble with a C++ code that I'm working on. It is a spell...
I am having trouble with a C++ code that I'm working on. It is a spell checker program. It needs to compare two arrays, a dictionary, and an array with misspelled strings that are compared to the strings in the dictionary. the strings that are in the second array that is not in the Dictionary are assumed to be misspelled. All of the strings in the dictionary are lowercase without any extra characters so the strings that are passed into...
For some reason I am having a hard time getting this program to compile properly. Could...
For some reason I am having a hard time getting this program to compile properly. Could you help me debug it? Write the prototypes and functions to overload the given operators in the code //main.cpp //This program shows how to use the class rectangleType. #include <iostream> #include "rectangleType.h" using namespace std; int main() {     rectangleType rectangle1(23, 45);                     //Line 1     rectangleType rectangle2(12, 10);                     //Line 2     rectangleType rectangle3;                             //Line 3     rectangleType rectangle4;                             //Line 4     cout << "Line...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
I am having a hard time getting started on how to do this assignment. I would...
I am having a hard time getting started on how to do this assignment. I would like some ideas on how to start the MEMO. and maybe some ideas on what you would include. But I don't necessarily need the assignment completed for me. just need ideas!!! One routine negative message in the form of an internal memo. 400-500 word message. Single-spaced, with 1-inch margins on all sides. Objective: To announce organizational restructuring, one routine negative message addressed to employees....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT