Question

In: Computer Science

I need an answer only for the bold part of the question. 1. Circle: The class...

I need an answer only for the bold part of the question.

1. Circle:

The class has two private instance variables: radius (of the type double) and color (of the type String).

The class also has a private static variable: numOfCircles (of the type long) which at all times will keep track of the number of Circle objects that were instantiated.

Construction:

A constructor that constructs a circle with the given color and sets the radius to a default value of 1.0.

A constructor that constructs a circle with the given, radius and color.

Once constructed, the value of the radius must be immutable (cannot be allowed to be modified)

Behaviors:

Accessor and Mutator aka Getter and Setter for the color attribute

Accessor for the radius.

getArea() and getCircumference() methods, hat return the area and circumference of this Circle in double.

Hint: use Math.PI (https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#PI (Links to an external site.))

2. Rectangle:

The class has two private instance variables: width and height (of the type double)

The class also has a private static variable: numOfRectangles (of the type long) which at all times will keep track of the number of Rectangle objects that were instantiated.

Construction:

A constructor that constructs a Rectangle with the given width and height.

A default constructor.

Behaviors:

Accessor and Mutator aka Getter and Setter for both member variables.

getArea() and getCircumference() methods, that return the area and circumference of this Rectangle in double.

a boolean method isSquare(), that returns true is this Rectangle is a square.

Hint: read the first 10 pages of Chapter 5 in your text.

3. Container

The class has two private instance variables: rectangle of type Rectangle and circle of type Circle.

Construction:

No explicit constructors.

Behaviors:

Accessor and Mutator aka Getter and Setter for both member variables.

an integer method size(), that returns 0, if all member variables are null, 1 either of the two member variables contains a value other than null, and 2, if both, the rectangle and circle contain values other than null.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________


1)

// Circle.java

public class Circle {
   private double radius;
   private String color;
   private static long noOfCircles;

   public Circle(double radius, String color) {

       this.radius = radius;
       this.color = color;
       noOfCircles++;
   }

   public Circle(String color) {

       this.radius = 1.0;
       this.color = color;
       noOfCircles++;
   }

   public double getRadius() {
       return radius;
   }

   public String getColor() {
       return color;
   }

   public void setColor(String color) {
       this.color = color;
   }

   public double getArea()
   {
       return Math.PI*radius*radius;
   }
   public double getCircumference()
   {
       return 2*Math.PI*radius;
   }
  
}
_____________________________

2)

// Rectangle.java

public class Rectangle {
   private double height;
   private double width;
   private long numOfRectangles;

   public Rectangle(double height, double width, long numOfRectangles) {
       this.height = height;
       this.width = width;
       this.numOfRectangles++;
   }

   public Rectangle() {
       this.height = 1;
       this.width = 1;
       this.numOfRectangles++;

   }

   public double getArea() {
       return width * height;
   }

   public double getCircumference() {
       return 2 * (width + height);
   }

   public boolean isSquare() {
       if (width == height)
           return true;
       else
           return false;
   }

  
}
_______________________

3)

// Container.java

public class Container {
   private Rectangle rectangle;
   private Circle circle;

   public Rectangle getRectangle() {
       return rectangle;
   }

   public void setRectangle(Rectangle rectangle) {
       this.rectangle = rectangle;
   }

   public Circle getCircle() {
       return circle;
   }

   public void setCircle(Circle circle) {
       this.circle = circle;
   }

   public int size() {
       int val = 0;
       if (rectangle == null && circle == null) {
           val = 0;
       } else if (rectangle != null || circle != null) {
           val = 1;
       } else if (rectangle != null && circle != null) {
           val = 2;
       }
       return val;
   }
}

_______________Could you plz rate me well.Thank You


Related Solutions

I was able to get questions 1 - 4 answer and only need question 5 and...
I was able to get questions 1 - 4 answer and only need question 5 and its sub-parts. Asymmetric Information and Separating Equilibrium A population has two equal-sized members of "healthy" and "unhealthy" individuals. Members of each type have the same, identical, utility function: U = 20Y0.5 (i.e. 20 x Y raised to the 0.5 power), where Y is annual income.                            Assume each individual, in either group, has disposable income (after normal expenses) of $19,000 a year. If in...
ONLY ANSWER QUESTION IN BOLD Geoffrey is the owner of a small grocery store, and is...
ONLY ANSWER QUESTION IN BOLD Geoffrey is the owner of a small grocery store, and is considering buying a car to help him transport his wares. He has found a suitable used car online that he was able to negotiate to a price of $32,000. After doing a bit more research, he has found the following additional expenses involved in the purchase: Insurance and registration will cost $440 per year, payable at the start of each year Based on mileage...
**only need part c and d answered below. It is in bold. In java, please implement...
**only need part c and d answered below. It is in bold. In java, please implement the classes below. Each one needs to be created. Each class must be in separate file. The expected output is also in bold. I have also attached the driver for part 4. 2. The StudentRoster class should be in the assignment package. a. There should be class variable for storing multiple students (the roster), semester and year. All class variables of the Student class...
I need the answer for PART B and PART C of this question: You have recently...
I need the answer for PART B and PART C of this question: You have recently been appointed management accountant for Rugby Coffee Mugs Pty Ltd. The company commenced its operations on 1 July 2019 manufacturing one size coffee mugs with individual club names and club logos of rugby union clubs playing in the New South Wales, Queensland, Victoria and Western Australia local rugby union competition. The company currently does not have any management accounting controls and part of your...
I have this question in my nursing class I just need someone to answer it for...
I have this question in my nursing class I just need someone to answer it for me Reflect on an occasion where you experienced ineffective leadership (doesn't have to be in the hospital/healthcare). What behaviors did they display? What factors may have influenced their leadership style?
Just to be clear, I only want the answer to the third part The typedset question...
Just to be clear, I only want the answer to the third part The typedset question pls. Implement a class Box that represents a 3-dimensional box. Follow these guidelines: constructor/repr A Box object is created by specifying calling the constructor and supplying 3 numeric values for the dimensions (width, height and length) of the box. These measurements are given in inches. Each of the three dimensions should default to 12 inches. The code below mostly uses integers for readability but...
(i just need an answer for question 4) (i just need an answer for just question...
(i just need an answer for question 4) (i just need an answer for just question 4) you have two facilities, one in Malaysia and one in Indonesia. The variable cost curve in the Malaysian plant is described as follows: VCM = q­ + .0005*q2 , where q is quantity produced in that plant per month. The variable cost curve in the Indonesian plant is described by VCI = .5q + .00075q2, where q is the quantity produced in that...
**Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class...
**Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class must be in separate file. Draw an UML diagram with the inheritance relationship of the classes. 1. The Athlete class a. All class variables of the Athlete class must be private. b.is a class with a single constructor: Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender). All arguments of the constructor should be stored as class variables. There should only...
I have the answer to part A to D. I need the answer to the rest....
I have the answer to part A to D. I need the answer to the rest. Please help. CVP and Sensitivity Analysis (Single Product). Victoria, Inc., has annual fixed costs totaling $240,000 and variable costs of $6 per unit. Each unit of product is sold for $30. Victoria expects to sell 12,000 units this year (this is the base case). Required: Find the break-even point in units. How many units must be sold to earn an annual profit of $100,000?...
I need answer for the second part of the question (in detail). Thanks.   Explain how leading...
I need answer for the second part of the question (in detail). Thanks.   Explain how leading and lagging foreign currency cash flows can mitigate currency risk. What are limitations to this method?.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT