Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java 1.6 or later[[[[ Question ]]]]]: when i run this code on repl.it it gives me: exit status 1 Main.java:47: error: class RectangleTest is public,

Java 1.6 or later[[[[ Question ]]]]]: when i run this code on repl.it it gives me:

exit status 1

Main.java:47: error: class RectangleTest is public, should be declared in a file named RectangleTest.java public class RectangleTest ^ 1 error 

Link to code on repl.it website : https://repl.it/repls/PerfectRoyalConfig

Output should be:

Enter Length of rectangle: 4.8 Enter width of rectangle: 3.7 Length: 4.8 Width: 3.7 Perimeter: 17.0 Area : 17.76

Code is about: Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide methods that calculate the rectangles perimeter and area. It has set and get methods for both length and width. The set methods should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0. Write a program to test class Rectangle.

import java.io.*; import java.util.Scanner; RectangleTest.java; class Rectangle { private double length, width; public Rectangle () { setLength ( 1.0 ); setWidth ( 1.0 ); } public Rectangle ( double theLength, double theWidth ) { setLength( theLength); setWidth(theWidth); } public void setLength ( double theLength) { length = ( theLength > 0.0 && theLength < 20.0 ? theLength : 1.0 ); }

public void setWidth ( double theWidth) { width = ( theWidth > 0 && theWidth < 20.0 ? theWidth : 1.0 ); } public double getLength () { return length; } public double getWidth() { return width; } public double perimeter () { return 2 * length + 2 * width ; } public double area () { return length * width; } public String toRectangleString () { return (" Length: " + length + " " + " Width: " + width + " " + " Perimeter: " + perimeter() + " " + " Area : " + area()); } } public class RectangleTest { public static void main (String args []) { Rectangle rect1=new Rectangle (); double length, width; Scanner input=new Scanner (System.in); System.out.println ("Enter Length of rectangle: "); length=input.nextDouble (); System.out.println ("Enter width of rectangle: "); width=input.nextDouble (); rect1.setLength(length); rect1.setWidth(width); System.out.println(rect1.toRectangleString()); System.exit (0); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

answer only

Answered: 1 week ago