Can you please write a class for circle, and rectangle(private) in java. then do Driver---Scanner. the Driver should have both.
class CalculateArea
{
public static void main (String[] args)
{
Rectangle r = new Rectangle(40.0,50.0);
System.out.println("Rectangle\n--------- ");
System.out.println("Area : "+r.getArea());
System.out.println();
Circle c = new Circle(30.0);
System.out.println("Circle\n--------- ");
System.out.println("Area : "+c.getArea());
}
static class Rectangle
{
private double length,width;
public Rectangle(double length,double width) // constructor
{
this.length = length;
this.width = width;
}
public double getArea()
{
return length*width;
}
}
static class Circle
{
private double radius;
public Circle(double radius) // constructor
{
this.radius = radius;
}
public double getArea()
{
return 3.14*radius*radius;
}
}
}
Output:
Rectangle --------- Area : 2000.0 Circle --------- Area : 2826.0
Do ask if any doubt. Please upvote.
Can you please write a class for circle, and rectangle(private) in java. then do Driver---Scanner. the...
package rectangle; public class Rectangle { private int height; private int width; public Rectangle(int aHeight, int aWidth) { super(); height = aHeight; width = aWidth; } public int getHeight() { return height; } public int getWidth() { return width; } public void setHeight(int aHeight) { height = aHeight; } public void setWidth(int aWidth) { width = aWidth; } public int...
In Java programming language. For this assignment, you must write a class Rectangle and a tester RectangleTest. The Rectangle class should have only the following public methods (you can add other non-public methods): Write a constructor that creates a rectangle using the x, y coordinates of its lower left corner, its width and its height in that order. Creating a rectangle with non-positive width or height should not be allowed, although x and y are allowed to be negative. Write...
For this question you must write a java class called Rectangle and a client class called RectangleClient. The partial Rectangle class is given below. (For this assignment, you will have to submit 2 .java files: one for the Rectangle class and the other one for the RectangleClient class and 2 .class files associated with these .java files. So in total you will be submitting 4 files for part b of this assignment.) // A Rectangle stores an (x, y) coordinate...
Please program in the Java language. a) Write driver class that instantiates 5 objects of class Circle with radius is an even number from 2 to 10 b) Write/define the class Circle
Please write in Java Language Write an abstract class Shape with an attribute for the name of the shape (you'll use this later to identify a particular shape). Include a constructor to set the name of the shape and an abstract calculateArea method that has no parameters and returns the area of the shape. Optionally, include a constructor that returns the name of the shape and its area (by calling the calculateArea method). Write a Rectangle class that inherits from...
Within NetBeans, write a Java program for EACH of the following problems. (The Rectangle class) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: · Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. · A no-arg constructor that creates a default rectangle. · A constructor that creates a...
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...
A class Scanner in Java can be used to get user input and its methods can be used after the following statement is executed: Scanner input = new Scanner(System.in); One of its methods nextDouble() returns the next double value from the keyboard. Now you are requested to write a method enterHeight() which displays the message "Input height: " and uses the method input.nextDouble() to get the user input. The process should be repeated until the input is non-negative. Finally the...
(a) A class Scanner in Java can be used to get user input and its methods can be used after the following statement is executed: Scanner input = new Scanner(System.in); One of its methods nextDouble() returns the next double value from the keyboard. Now you are requested to write a method enterHeight() which displays the message "Input height: " and uses the method input.nextDouble() to get the user input. The process should be repeated until the input is non-negative. Finally...
Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String input =""; System.out.println("Welcome to the easy square program"); while(true) { System.out.println("Enter the length of the side of a square or enter QUIT to quit"); try { input = keyboard.nextLine(); if(input.equalsIgnoreCase("quit")) break; int length = Integer.parseInt(input); Square s = new Square(); s.setLength(length); s.draw(); System.out.println("The area is "+s.getArea()); System.out.println("The perimeter is "+s.getPerimeter()); } catch(DimensionException e)...