Question

In: Computer Science

Java Logic - the idea is for this Plumbers.java to ask the customer if there house...

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="\n no burst pipes apparent\n",
             p6="\n and 1 burst pipe apparent\n",
             p7="\n and 2 burst pipes apparent\n",
             p8="\n and 3 burst pipes apparent\n";
              
          
              
               if(service == 1)
              
                   {
                        System.out.println("\nYou 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("\n%s Room Flood Repair = $%s\n",numberRooms,roomsCost);
     
         if(!(pipesCost==0))
       
         {
            System.out.printf("%s Pipe Repair = $%s\n",numberPipes,pipesCost);
     
         System.out.printf("                 ------------\n" +
         "Estimated Amount Due: $%s\n\n",cost);
     
         System.out.print("** Please Have This Amount Available -" +
         "   Fees Are Due At Time Of Service.\n   This Is An Estimate Only." +
         " Final Bill Will Be Based On Onsite Evaluation." +
         "\n   All Work Will Be Discussed And Agreed Upon Prior To Repairs. **\n\n");
      }
  
      else
    
         System.out.printf("If you need services, please come visit us again.\n\n");        
               
           
    }




   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("\nPlease enter 1 "+ "if there was flood damage>>");
   service = userInput.nextInt();
   System.out.print("\n How many rooms were flooded - 1" + "2" + "3" + "or more >>");
   numberRooms = userInput.nextInt();
   burstPipes = userInput.nextLine();
   System.out.print("\n Were there any burst pipes? Please enter Y" + "or" + "N >>");
   burstPipes = userInput.nextLine();
   System.out.print("\n How many pipes burst? - 1" + "2" + "3" + "or more>>");
   numberPipes = userInput.nextInt();


   Plumber firstCustomer = new Plumber(service, numberRooms, burstPipes,numberPipes);

   firstCustomer.ComputePrice();
   firstCustomer.display();

   }

}

Solutions

Expert Solution


import java.util.Scanner;

                
public class Plumber
{
    //class variable declarations
    //modified
    int service;
    int numberRooms;
    int burstPipes;
    int numberPipes;
    double roomsCost;
   double pipesCost;
    private int NumberRooms;
    double cFlood1 = 300;
   double cFlood2 = 500;
   double cFlood3 = 750;
   double cPipe1 = 50;
   double cPipe2 = 70;
   double cPipe3 =100;
   double cost;
   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) {
       // throw new UnsupportedOperationException("Not yet implemented");
        this.service = service;
      this.numberRooms = numberRooms;
      this.BurstPipes = burstPipes;
      this.numberPipes = numberPipes;
    }


  
     public void display()
          {
            String p1 = " no rooms flooded";
            String p2 = "1 room flooded";
            String p3="with 2 rooms flooded";
            String p4="with 3 or more rooms flooded";////modified
            String p5="\n no burst pipes apparent\n";
            String p6="\n and 1 burst pipe apparent\n";
            String p7="\n and 2 burst pipes apparent\n";//modified
            String p8="\n and 3 burst pipes apparent\n";
                
            
                
               if(this.service == 1)//changed
                
                   {
                        System.out.println("\nYou have stated that the damage to your house involves a natural flood.");
                         
                            switch(this.NumberRooms)//changed
                            {
                                case 0:
                                    System.out.printf("%s",p1);
                             
                                case 1:
                                    this.roomsCost += this.cFlood1;//changed
                                    System.out.printf("%s",p2);
                                    break;
                                case 2:
                                    this.roomsCost += this.cFlood2;//changed
                                    System.out.printf("%s",p3);
                                    break;
                                case 3:
                                    this.roomsCost += this.cFlood3;//changed
                                    System.out.printf("%s",p4);
                                    break;
                                  
                                }
                                
                                  
                    if(this.BurstPipes.equals("Y") || this.BurstPipes.equals("y"))//changed
                         {
                            switch(this.numberPipes)//changed
                            {
                              
                                case 0:
                                     System.out.printf("%s",p5);
                                     break;
                                case 1:
                                    this.pipesCost += this.cPipe1;//changed
                                    System.out.printf("%s",p6);
                                    break;
                                case 2:
                                    this.pipesCost += this.cPipe2;//changed
                                    System.out.printf("%s",p7);
                                    break;
                                case 3:
                                    this.pipesCost += this.cPipe3;//changed
                                    System.out.printf("%s",p8);
                            }
                          
                      
                        }
                      
                    }
                 
                }
   
   
   public void ComputePrice()
   {
       //changed
      if(this.service ==1) //this (w two nested ifs) could be: if(needSrvc==1 && (!ttlRoom==0))
      {
      
         this.cost = this.roomsCost + this.pipesCost;//changed
       
         if(!(this.roomsCost==0))//changed
            System.out.printf("\n%s Room Flood Repair = $%s\n",numberRooms,roomsCost);
       
         if(!(this.pipesCost==0))//changed
            System.out.printf("%s Pipe Repair = $%s\n",numberPipes,pipesCost);
       
         System.out.printf("                 ------------\n" +
         "Estimated Amount Due: $%s\n\n",cost);
       
         System.out.print("** Please Have This Amount Available -" +
         "   Fees Are Due At Time Of Service.\n   This Is An Estimate Only." +
         " Final Bill Will Be Based On Onsite Evaluation." +
         "\n   All Work Will Be Discussed And Agreed Upon Prior To Repairs. **\n\n");
      }
    
      else System.out.printf("If you need services, please come visit us again.\n\n");          
                 
             
    }

   
   
  
   public static void main(String[] args)
   {

   double cFlood1 = 300;
   double cFlood2 = 500;
   double cFlood3 = 750;
   double cPipe1 = 50;
   double cPipe2 = 70;
   double cPipe3 =100;
   double roomsCost;
   double pipesCost;
   int cost = 0;
   int service;
   int numberRooms;
   int numberPipes;
   String burstPipes ="";

    
    
    
    



   Scanner userInput = new Scanner(System.in);
    
   System.out.print("\nPlease enter 1"+ "if there was flood damage>>");
   service = userInput.nextInt();
   System.out.print("\n How many rooms were flooded - 1" + "2" + "3" + "or more >>");
   numberRooms = userInput.nextInt();
   burstPipes = userInput.nextLine();
   System.out.print("\n Were there any burst pipes? Please enter Y" + "or" + "N >>");
   burstPipes = userInput.nextLine();
   System.out.print("\n How many pipes burst? - 1" + "2" + "3" + "or more>>");
   numberPipes = userInput.nextInt();

   /*
   srv.service;
   numRms.numberRooms;
   bstPipes.burstPipes;
   numPipes.numberpipes;
   return srv, numRms, bstPipes, numPipes;

   */
   //modified
   Plumber firstCustomer = new Plumber(service, numberRooms, burstPipes,numberPipes);//
   firstCustomer.display();
   firstCustomer.ComputePrice();


    
               
                
               
                    
   }              
        
}

//check this code. any issue ask me

output:-

run:

Please enter 1if there was flood damage>>1

How many rooms were flooded - 123or more >>2

Were there any burst pipes? Please enter YorN >>Y

How many pipes burst? - 123or more>>2

You have stated that the damage to your house involves a natural flood.
no rooms flooded1 room flooded
and 2 burst pipes apparent

2 Room Flood Repair = $300.0
2 Pipe Repair = $70.0
                 ------------
Estimated Amount Due: $370.0

** 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. **

BUILD SUCCESSFUL (total time: 8 seconds)


Related Solutions

Java The whole idea is for me to gain a better understanding of the logic. If...
Java The whole idea is for me to gain a better understanding of the logic. If possible, can you go off of what I have started and not just give me a whole new written program? Also, don't simplify result. Implement a class named “Fraction” with the following properties: numerator: int type, private denominator: int type, private and the following methods: one default constructor which will create a fraction of 1/1. one constructor that takes two parameters which will set...
Using Java, Ask for the runner’s name Ask the runner to enter a floating point number...
Using Java, Ask for the runner’s name Ask the runner to enter a floating point number for the number of miles ran, like 3.6 or 9.5 Then ask for the number of hours, minutes, and seconds it took to run A marathon is 26.219 miles Pace is how long it takes in minutes and seconds to run 1 mile. Example Input: What is your first name? // user enters Pheidippides How far did you run today? 10.6 // user enters...
Using Java, Ask for the runner’s name Ask the runner to enter a floating point number...
Using Java, Ask for the runner’s name Ask the runner to enter a floating point number for the number of miles ran, like 3.6 or 9.5 Then ask for the number of hours, minutes, and seconds it took to run Format the numbers with leading 0's if the pace is 8 minutes and 3 second, it should be 8:03 and for marathon time, if its 1 hour and 15 minutes and 9 seconds, it should be 1:15:09 Please read through...
In Java INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the...
In Java INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the computer user to enter his/her: • Name: a string representing the user’s first name • month of birthday: an integer representing the month of the user’s birthday • day of birthday: an integer representing the day of the user’s birthday • year of birthday: an integer representing the year of the user’s birthday Consider the following aspects that your program shall perform: VALIDATE USER’S...
Write a java program that will ask for a Star Date and then convert it into...
Write a java program that will ask for a Star Date and then convert it into the corresponding Calendar date. without using array and methods.
Java Programming Compound Logic and nested if statement For a student to be accepted in XYZ...
Java Programming Compound Logic and nested if statement For a student to be accepted in XYZ College, the student must meet the following requirements: GPA must be 3.75 or higher. Family income must be more than $60,000 Applicant must be a New Jersey resident. XYZ college asked you to write a program to implement the above requirements. Write the program using compound logic (AND, OR) whichever is applicable. Modify the program using nested if statement. Submit: Source code for both...
Java Programming Compound Logic and nested if statement For a student to be accepted in XYZ...
Java Programming Compound Logic and nested if statement For a student to be accepted in XYZ College, the student must meet the following requirements: GPA must be 3.75 or higher. Family income must be more than $60,000 Applicant must be a New Jersey resident. XYZ college asked you to write a program to implement the above requirements. Write the program using compound logic (AND, OR) whichever is applicable. Modify the program using nested if statement. This means there will be...
Is it possible to take the idea of “the customer is always right” too far so...
Is it possible to take the idea of “the customer is always right” too far so that it becomes a negative on the company? Why or why not?
This is in java, thank you! Problem2: In this problem you ask the user for a...
This is in java, thank you! Problem2: In this problem you ask the user for a month and day. You will then calculate the season based on the month and day. Create a class named Problem2 Create two integer instance variables, month and day. Create a constructor to initialize the both variables. The constructor should accept two arguments as parameters, m and d. Initialize the instance variables with these two values. Create a method called calcSeason. It should not have...
Questions about logic. Please Solve them ALL! (I have the right to ask the last question.)...
Questions about logic. Please Solve them ALL! (I have the right to ask the last question.) Please write in a legible and annotated way, thank you. Q1A) Let P(x) be the statement “x can swim” and let Q(x) be the statement “x can play the guitar.” Express each of these sentences in terms of P(x), Q(x), quantifiers, and logical connectives. The domain for quantifiers consists of all students in your school. a) No student in your school can swim or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT