In: Computer Science
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();
}
}
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)