This code is in java.
Create a Java class that has the private double data of length,
width, and price. Create the gets and sets methods for the
variables. Create a No-Arg constructor and a constructor that
accepts all three values.
At the end of the class add a main method that accepts variables
from the user as input to represent the length and width of a room
in feet and the price of carpeting per square foot in dollars and
cents.
(order of input: L W $)
Assign appropriate values to the variables.
Compute and use the gets methods to display the
data as shown in the example.
The numbers should be a double data type
Example Output:
With carpet at $10.00 per sq ft, a room 9.0 ft long by 8.0 ft wide
will cost $720.00 to carpet.
A refresher on System.out.printf(...) is on page 163-172 of the
book. A refresher on the "Scanner" object is on 85 - 91 in the
book.
import java.util.*;
/* Header information
*
*/
public class Carpet {
// put code here
private double length, width, price;
public Carpet() {
}
public Carpet(double l, double w, double p) {
length = 9;
width = 8;
price = 10;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the length:");
double l = scan.nextDouble();
System.out.println("Enter the width:");
double w = scan.nextDouble();
System.out.println("Enter the price:");
double p = scan.nextDouble();
Carpet c1 = new Carpet(l, w, p);
System.out.println("Carpet cost : $" + (c1.getLength() * c1.getWidth() * c1.getPrice()));
}
}

import java.util.*;
/* Header information
*
*/
public class Carpet {
// put code here
private double length, width, price;
public Carpet() {
}
public Carpet(double l, double w, double p) {
length = l;
width = w;
price = p;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the length:");
double l = scan.nextDouble();
System.out.println("Enter the width:");
double w = scan.nextDouble();
System.out.println("Enter the price:");
double p = scan.nextDouble();
Carpet c1 = new Carpet(l, w, p);
System.out.println("Carpet cost : $" + (c1.getLength() * c1.getWidth() * c1.getPrice()));
}
}
please upvote. Thanks!
This code is in java. Create a Java class that has the private double data of length, width, and price. Create the gets...
My assignment is to create a rectangle class in java. •Create a MyRectangleClass •There are two private instance variables, length l and width w with double data type. •There is a constructor with two parameter •There are 4 public methods which are circumference, area, getWidth, and getLength. •circumference method will return circumference to the caller.(the formula for circumference is 2 *l + 2*w ) •Area method Return the area to the caller(:l*w) •getLength method will return length to the caller....
Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...
Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override the toString method for Rectangle. Override the equals method for Rectangle. Implement the comparable Interface for Rectangle (Compare by area) Rectangle class: public class Rectangle { private double length; private double width; public Rectangle(double l, double w) { length = l; width = w; } public double getLength() { ...
Programming Language: Java Write a class named ColoredRectangle that extends the Rectangle class (given below). The ColoredRectangle class will have an additional private String field named Color. The ColoredRectangle class should have four constructors: a no-arg constructor; a three-arg constructor; a two-arg constructor that accepts a Rectangle object and a color; and a copy constructor. The ColoredRectangle class should have an Equals and toString methods. The ColoredRectangle class should have mutators and accessors for all three fields. public class Rectangle...
In the code (C++) below, if you input 2 as length and 4 as width, the output is: Enter the rectangle's length: 2 Enter the rectangle's width: 4 Length: 2 | Width: 4 | Area: 8 | Perimeter:12 We worked on this code during class, but there were some things that I did not understand. 1) how does compiler read"l" as length, "w" as width, etc.? I thought you had to update it first, like "w=width." 2) i thought you...
In Java Create a testing class that does the following to the given codes below: To demonstrate polymorphism do the following: Create an arraylist to hold 4 base class objects Populate the arraylist with one object of each data type Code a loop that will process each element of the arraylist Call the first ‘common functionality’ method Call the second ‘common functionality’ method Call the third ‘common functionality’ method Verify that each of these method calls produces unique results Call...
Why are obj1 and obj2 printing the same areas? I'm trying to learn about Comparable interface. Couldn't figure it out. the compare to method should print 0, 1, or -1 import java.util.*; public class RectangleMain { public static void main(String [] args) throws CloneNotSupportedException { /*ComparableRectangleAlsoCloneable obj1 = new ComparableRectangleAlsoCloneable(4, 5); ComparableRectangleAlsoCloneable obj2 = (ComparableRectangleAlsoCloneable)obj1.clone(); System.out.println(obj1.toString()); System.out.println(obj1 == obj2); //false System.out.println(obj2.toString());*/ Scanner...
Consider the Rectangle2 java class definition below. Write the definition of an equals) method that checks if two Rectangle objects have the same dimensions Write a Java program to test the equals method public class Rectangle2 K private int width, length; public Rectangle2(int w, int 1) { setWidth(w); setLength(1); System.out.println("Inside parameterized!!!"); } public void setWidth(int w) { width = w;} public void setLength(int i) { length = 1;} int getWidth() { return width; } int getLength() { return length; }...
****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...
I have this program: It passes on certain test cases. The Demo five has the %.1f to cut down the number to one decimal place. But I get a failed attempt such as: Enter length: \n Enter width: \n You entered: 87.3, 2.0, and 174.7\n -- Rectangle info --\n Length: 87.34\n Width: 2.0\n Area: 174.68\n And I know it is because the length and area both have 2 decimal places. Could you help me fix this? Thank you. Program Content:...