Hi this is what i am supposed to do:
RoomDimension: First, you should create a class named RoomDimension that has two fields: one for the length of the room, and one for the width. The RoomDimension class should have a method that returns the area of the room.
RoomCarpet : Next you should create a RoomCarpet class that has a RoomDimension object as a field. It should also have a field for the cost of the carpet per square foot. The RoomCarpet class should have a method that returns the total cost of the carpet. Use the UML diagram in figure 9-21 (pg. 599) as a guide to creating these classes.
RoomPriceDemo : Finally, you will create a RoomPriceDemo application program that asks the user to enter:
• the dimensions of a room
• and the price per square foot of the desired carpet
Your program should then calculate and display the total cost of the carpet.
here is my code:
Other classHTML Code:package Program_5; public class RoomDimensions { private int roomLength=0; private int roomWidth=0; public void setRoomLength(int roomlength) { this.roomLength = roomlength; } public void setRoomWidth(int roomwidth) { this.roomWidth = roomwidth; } public RoomDimensions() { } public int getRoomArea() { return roomLength*roomWidth; } }
Here is my demo:HTML Code:package Program_5; public class RoomCarpet{ private RoomDimensions thisRoomDimension; final int carpetUnitCost=8; public void setRoomDimension(RoomDimensions thisroomdimension) { this.thisRoomDimension = thisroomdimension; } public int getTotalAMount() { return thisRoomDimension.getRoomArea()* carpetUnitCost; } }
my problem is my room1.getRoomArea()); print statement is not working. everything else seems correct but when i try and run it it gives me an error at the room1.getRoomArea()): method in the System.out.println is underlined red and that is the only problem i have and cant figure out how to fix itHTML Code:package Program_5; import java.util.Scanner; public class RoomPriceDemo { public static void main(String[] args) { int roomLength; int roomWidth; //Create Scanner object Scanner keyboard= new Scanner(System.in); System.out.println("Enter The Length Of The Room"); roomLength= keyboard.nextInt(); System.out.println("Enter The Width Of The Room"); roomWidth = keyboard.nextInt(); RoomDimensions roomd = new RoomDimensions(); roomd.setRoomLength(roomLength); roomd.setRoomWidth(roomWidth); //instantiating carpet class RoomCarpet room1 = new RoomCarpet(); //function call to set dimensions room1.setRoomDimension(roomd); //displaying data System.out.println("Room dimensions: "); System.out.println("Length: " + roomLength + " Width: " + roomWidth + "Area: " + room1.getRoomArea()); System.out.println("Carpet cost:$" + room1.getTotalAMount()); } }