Question: Hi, I got my code done for my assignment I just need help splitting it into 3 separate java files: RoomCarpet, RoomDimension and CarpetCalculator. here

Hi,

I got my code done for my assignment I just need help splitting it into 3 separate java files: RoomCarpet, RoomDimension and CarpetCalculator. here is my code.....

import java.text.DecimalFormat; import java.util.Scanner; //room dimension class for room class RoomDimension{ //instance variables length & width double length; double width; //constructor public RoomDimension(double length, double width) { super(); this.length = length; this.width = width; } //to get the area of the room using length and wdith public double getArea(){ return length*width; } @Override public String toString() { return "RoomDimension [length=" + length + ", width=" + width + "]"; } } class RoomCarpet{ //instance variables RoomDimension roomDimension; double carpetCost; public RoomCarpet(RoomDimension roomDimension, double carpetCost) { super(); this.roomDimension = roomDimension; this.carpetCost = carpetCost; } //to get total cost for area of room dimension public double getTotalCost(){ return roomDimension.getArea()*carpetCost; } @Override public String toString() { return "RoomCarpet [roomDimension=" + roomDimension + ", carpetCost=" + carpetCost + "]"; } } public class CarpetCalc { public static void main(String[] args) { double length; double width; double price; Scanner sc = new Scanner(System.in); //taking input until user enter a valid value for length and width while(true) { System.out.print("Enter length : "); length = sc.nextDouble(); if(length>0) break; else System.out.println("Enter positive value for length"); } while(true) { System.out.print("Enter width : "); width = sc.nextDouble(); if(width>0) break; else System.out.println("Enter positive value for width"); } while(true) { System.out.print("Enter price : "); price = sc.nextDouble(); if(price>0) break; else System.out.println("Enter positive value for price"); } RoomDimension roomDimension = new RoomDimension(length, width); RoomCarpet roomCarpet = new RoomCarpet(roomDimension, price); System.out.println(" Room dimensions:"); System.out.println("Length: "+length); System.out.println("Width: "+width); System.out.println("Price: "+price); System.out.println(" Area: "+roomDimension.getArea()); System.out.println(" Carpet Cost: $"+String.format("%.2f", roomCarpet.getTotalCost())); } }

I use blueJ with java. Thanks!!!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!