Question

In: Computer Science

This was my prompt, and I'm not quire sure what to do. 1. Circle: Implement a...

This was my prompt, and I'm not quire sure what to do.

1. Circle:

Implement a Java class with the name Circle. It should be in the package edu.gcccd.csis.

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:

Implement a Java class with the name Rectangle. It should be in the package edu.gcccd.csis.

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

Implement a Java class with the name Container. It should be in the package edu.gcccd.csis.

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

Code

Circle.java


package edu.gcccd.csis;

public class Circle
{
private double radius;
private String color;
private static int numOfCircles=0;

public Circle() {
this.radius=0;
numOfCircles++;
}

  
public Circle(double radius, String color)
{
this.radius = radius;
this.color = color;
numOfCircles++;
}

public String getColor() {
return color;
}

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

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

Rectangle.java


package edu.gcccd.csis;

public class Rectangle
{
private double width, height ;
private static int numOfRectangles=0;

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

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

public double getWidth() {
return width;
}

public void setWidth(double width) {
this.width = width;
}

public double getHeight() {
return height;
}

public void setHeight(double height) {
this.height = height;
}
public double getArea()
{
return width*height;
}
public double getCircumference()
{
return 2*(height+width);
}
public boolean isSquare()
{
return width==height;
}
}

Container.java


package edu.gcccd.csis;

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()
{
if(rectangle==null && circle==null)
return 0;
else if (rectangle!=null || circle!=null)
return 1;
else
return 2;
}
}

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator...
I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator is 0 it throws the ZeroDenominatorException and the catch catches to guarantee that the denominator is never 0. /** * The main class is the driver for my Rational project. */ public class Main { /** * Main method is the entry point to my code. * @param args The command line arguments. */ public static void main(String[] args) { int numerator, denominator =...
I'm not sure if my calculations are correct: Part A: Solving for Calorimeter Constant TRIAL 1...
I'm not sure if my calculations are correct: Part A: Solving for Calorimeter Constant TRIAL 1 Involving 50 mL of 1.83M HCl and 50 mL of 2.08M NaOH, trial 1 lasted for 9 minutes, temperature rose from 21.5 celsius to 34.3 celsius in 3.15 minutes and then fell to 32.3 celsius at the end of the 9 minutes Solutions Temperature change >>>> 12.80 celsius Average temperature change >>>> 1.2 celsius / sec Mass of solution, g >>>> 7.50g Solution heat...
(PLEASE SHOW STEPS TO SOLUTIONS. I'M GETTING STUCK IN MY PROCESS AND NOT SURE WHERE I'M...
(PLEASE SHOW STEPS TO SOLUTIONS. I'M GETTING STUCK IN MY PROCESS AND NOT SURE WHERE I'M GOING WRONG AND WHAT TO DO NEXT.) Skycell, a major European cell phone manufacturer, is making production plans for the coming year. Skycell has worked with its customers (the service providers) to come up with forecasts of monthly requirements (in thousands of phones) as shown in the table below (e.g., demand in Jan. is 1,000,000 units.) Manufacturing is primarily an assembly operation, and capacity...
I'm not sure if I am able to do these in excel, but if so what...
I'm not sure if I am able to do these in excel, but if so what are the functions for them? (2 pts) The weights of 8-week-old French Bulldog puppies follow a normal distribution. What percent of puppies weigh more than 2.35 standard deviations below the mean? (4 pts) If a Chevy Trailblazer lasts for an average of 170,000 miles and a standard deviation of 25,000 miles, assuming mileage follows a normal distribution, what is the probability that the Trailblazer...
1. Circle: Implement a Java class with the name Circle. It should be in the package...
1. Circle: Implement a Java class with the name Circle. It should be in the package edu.gcccd.csis. 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...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
I'm being ask to design an experiment about enzymes. I'm not sure about how to do...
I'm being ask to design an experiment about enzymes. I'm not sure about how to do that. To test for the presence of monosaccharides and reducing disaccharide sugars in food, the food sample is dissolved in water, and a small amount of Benedict's reagent is added. The solution should progress in the colors of blue (with no glucose present), green, yellow, orange, red, and then brick red when there is a large amount of glucose present. Design an experiment where...
I'm trying to study for my General Chemistry II Exam, but I want to make sure...
I'm trying to study for my General Chemistry II Exam, but I want to make sure that I don't miss anything important! If you could provide your input on the following concepts, that would be greatly appreciated! Thank you so much!(: Chapter 17 – Chemical Equilibrium I. Chemical Equilibria             A. Equilibrium constant             B. Homogeneous equilibria             C. Heterogeneous equilibria             D. Molar concentrations             E. Contribution of a pure liquid or a pure solid to the equilibrium constant...
I'm trying to study for my General Chemistry II Exam, but I want to make sure...
I'm trying to study for my General Chemistry II Exam, but I want to make sure that I don't miss anything important! If you could provide your input on the following concepts, that would be greatly appreciated! Thank you so much!(: Chapter 16 - Chemical Kinetics I. Reaction Rates             A. Definition of reaction rate             B. Mathematical expression for Reaction rate             C. Instantaneous rate             D. Initial rate             E. Rate constant             F. Rate law             G....
For my assignment, I'm not sure how to start making a stack implemented via linked list...
For my assignment, I'm not sure how to start making a stack implemented via linked list of arrays. I'm stuck on how to approach the very first steps (Stack class members and constructor.) I'm familiar with allocating memory, arrays, and linked lists, but putting them together has me lost. How should I create a Stack with a dynamic linked list of arrays? Stack name (number of elements); Creates a stack of strings with name “name.” Internally, each unit of memory...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT