Question

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 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. Hint: read the first 10 pages of Chapter 5 in your text.

Homework Answers

Answer #1
// Rectangle.java
package edu.gcccd.csis;

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

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

        public double getWidth() {
                return width;
        }

        public double getHeight() {
                return height;
        }

        public long getNumOfRectangles() {
                return numOfRectangles;
        }

        public Rectangle() {
                this(1, 1);
        }

        public boolean isSquare() {
                return (width == height);
        }

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

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

// Circle.java
package edu.gcccd.csis;

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

        public Circle(String color) {
                this(color, 1);
        }

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

        public double getRadius() {
                return radius;
        }

        public String getColor() {
                return color;
        }

        public long getNumOfCircles() {
                return numOfCircles;
        }

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

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

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

// 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() {
                int count = 0;
                if (circle != null) {
                        count++;
                }
                if (rectangle != null) {
                        count++;
                }
                return count;
        }
}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Design a class with the following requirements: 1- give the class a name from your choice....
Design a class with the following requirements: 1- give the class a name from your choice. 2- write some code that creates three instance variables, choose a name and type for each one of them. (must have two private and one public variables) 3- Initialize the variables using two different constructors. 4- Use mutator and accessor methods (set and get) for the private data members. 5- Display the value of each member variable using a method. 6- In the main,...
Design a class with the following requirements: 1- give the class a name from your choice....
Design a class with the following requirements: 1- give the class a name from your choice. 2- write some code that creates three instance variables, choose a name and type for each one of them. (must have two private and one public variables) 3- Initialize the variables using two different constructors. 4- Use mutator and accessor methods (set and get) for the private data members. 5- Display the value of each member variable using a method. 6- In the main,...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Write the program in java Implement a class Product. Create instance variables to store product name...
Write the program in java Implement a class Product. Create instance variables to store product name and price and supply the values through constructor. For example new Product(“Toaster’, 29.95). Create methods, getName, getPrice. Write a method productPrinter that prints the product name and its price after reducing it by $5. Create a main class and necessary constructs in the main class to run the Product class.
java Consider the following class definition: public class Circle { private double radius; public Circle (double...
java Consider the following class definition: public class Circle { private double radius; public Circle (double r) { radius = r ; } public double getArea(){ return Math.PI * radius * radius; } public double getRadius(){ return radius; } } a) Write a toString method for this class. The method should return a string containing the radius and area of the circle; For example “The area of a circle with radius 2.0 is 12.1.” b) Writeaequalsmethodforthisclass.ThemethodshouldacceptaCircleobjectasan argument. It should return...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with the default values denoted by dataType name : defaultValue - String animal : empty string - int lapsRan : 0 - boolean resting : false - boolean eating : false - double energy : 100.00 For the animal property implement both getter/setter methods. For all other properties implement ONLY a getter method Now implement the following constructors: 1. Constructor 1 – accepts a String...
For the following class Book: 1- Write a default constructor to give default values (title= Intro...
For the following class Book: 1- Write a default constructor to give default values (title= Intro to Programming and price = 20) to the class’s variables. 2 - Write a parameterized constructor to allow the user to initialize the class variables. 3- Write getter & setter for each variable of this class. 4- Then write a main code to create an instance of this class using parameterized constructor, ask user for inputs to initialize the variables of this instance and...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java file) and a sub class of Animal named Cat (assuming in Cat.java file).   The Animal class has the following protected instance variables: boolean vegetarian, String eatings, int numOfLegs and the following public instance methods: constructor without parameters: initialize all of the instance variables to some default values constructor with parameters: initialize all of the instance variables to the arguments SetAnimal: assign arguments to all...
Write the following problem in Java Create a class Dog, add name, breed, age, color as...
Write the following problem in Java Create a class Dog, add name, breed, age, color as the attributes. You need to choose the right types for those attributes. Create a constructor that requires no arguments. In this constructor, initialize name, breed, age, and color as you wish. Define a getter and a setter for each attribute. Define a method toString to return a String type, the returned string should have this information: “Hi, my name is Lucky. I am a...
Part 1 Given the following code: public class MyClass { private double score; private String studentID;...
Part 1 Given the following code: public class MyClass { private double score; private String studentID; //code of the class ..... } //end of MyClass Code a default constructor and an overloaded constructor of MyClass that will assign values to its two instance fields: Please write in JAVA Part 2 Continue from question about, code an mutator of instance field called studentID:
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT