the question is from chapter 9 3pc... i did write the code but it has errors in
ID: 3620580 • Letter: T
Question
the question is from chapter 9 3pc...i did write the code but it has errors in it..
import java .io.*;
import java.util.Scanner; //to be able to read from the keyboard
public class RoomDimension
{
//identifier declarations
double room;
double length;
double width;
double area; //total are of all rooms
double cost; //cost for per feet
double total; //estimated total
public RoomDimension(double lnth, double wdth, double cot)
{
length = lnth;
width = wdth;
cost = cot
}
public RoomDimension(RoomDimension object2)
{
length = object2.length;
width = object2.width;
cost = object2.cost;
}
public RoomDimension(RoomDimension object3)
{
length = object3.length;
width = object3.width;
cost = object3.cost;
}
public void setLength(Double lnth)
{
length = lnth;
}
public void setWidth(Double wdth)
{
width = wdth;
}
public void setCost(Double cot)
{
cost = cot;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public double getCost()
{
return cost;
}
public double getRoom()
{
return length * width;
}
public double getArea()
{
return room++;
}
public double getTotal()
{
return area * cost;
}
public String toString()
{
//Create a string representing the object.
String str = "Length: "+ length+
" Width: "+ width+
" Room: "+ room +
" Cost: "+cost+
" Area: "+area;
//Return the string.
return str;
}
}
//main
public class RoomCarpet
{
public static void main(String[] args)
{
//identifier declarations
double room1; //bed room
double room2; //master bed room
double room3; //living room
double length1; //length in feet
double length2; //length in feet
double length3; //length in feet
double width1; //width in feet
double width2; //width in feet
double width3; //width in feet
double cost1,cost2,cost3; //cost of the carpet per sqft
double area; //total are of all rooms
double total; //estimated total
Scanner keyboard = new Scanner(System.in);
RoomDimension object1=new RoomDimension();
RoomDimension object2=new RoomDimension();
RoomDimension object3=new RoomDimension();
//dispay prompts and get input
System.out.println("Vishal Patel");
System.out.println("Lab 3B");
System.out.println("Page#598#3");
//input for Room1
System.out.print("Please enter the length of room: ");
length1 = keyboard.nextLine();
System.out.println("");
System.out.print("Please enter the width of room: ");
width1 = keyboard.nextLine();
System.out.println("");
System.out.print("what is the cost of the carpet per sq foot?: ");
cost1 = keyboard.nextLine();
System.out.println("");
System.out.println("-----------------------------------------------------------");
//input for Room2
System.out.print("Please enter the name of the first person: ");
length2 = keyboard.nextLine();
System.out.println("");
System.out.print("Please enter the width of room: ");
width2 = keyboard.nextLine();
System.out.println("");
System.out.print("what is the cost of the carpet per sq foot?: ");
cost2 = keyboard.nextLine();
System.out.println("");
System.out.println("-----------------------------------------------------------");
//input for Room3
System.out.print("Please enter the name of the first person: ");
length3 = keyboard.nextLine();
System.out.println("");
System.out.print("Please enter the width of room: ");
width3 = keyboard.nextLine();
System.out.println("");
System.out.print("what is the cost of the carpet per sq foot?: ");
cost3 = keyboard.nextLine();
System.out.println("");
System.out.println("-----------------------------------------------------------");
object1.setLength(lnth1);
object1.setWidth(wdth1);
object1.setCost(cost1);
object2.setLength(lnth2);
object2.setWidth(wdth2);
object2.setCost(cost2);
object3.setLength(lnth3);
object3.setWidth(wdth3);
object3.setCost(cost3);
}
}
Explanation / Answer
cost = object3.cost; fill in default constructorRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.