Question

In: Computer Science

1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...

1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in
Java.

Circle
Circle
Radius: double
Circle()
Circle(newRadius: double)
getArea(): double
setRadius(newRadius: double): void
getRadius(): double

After creating the Circle class, you should test this class from the main() method by passing objects of this
class to a method “ public static void printAreas(Circle c, int times)”
You should display the area of the circle object 5 times with different radii.

Solutions

Expert Solution

Explanation:I have completed the code have also shown the output, please find the images attached with the answer.Please upvote if you liked my answer and comment if you need any modification or explanation

//code

public class Circle {

   private double radius;

   public Circle() {

   }

   public Circle(double radius) {
       this.radius = radius;
   }

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

   public double getRadius() {
       return radius;
   }

   public void setRadius(double radius) {
       this.radius = radius;
   }
   public static void printAreas(Circle c, int times) {
       for (int i = 0; i < times; i++) {
           System.out.println(c.getArea());
       }
   }
   public static void main(String[] args) {
       Circle c1 = new Circle(2.5);
       Circle.printAreas(c1, 1);
       Circle c2 = new Circle(1.5);
       Circle.printAreas(c2, 1);
       Circle c3 = new Circle(2.0);
       Circle.printAreas(c3, 1);
       Circle c4 = new Circle(1.8);
       Circle.printAreas(c4, 1);
       Circle c5 = new Circle(1.0);
       Circle.printAreas(c5, 1);

   }

}

Output:


Related Solutions

1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you...
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you need to define: 1a.) +setName(value:String):void 1b.) +setGPA(value:double):void 1c.) +setID(value: String):void 1d.) +getName(): String 1e.) +getLastName():String 2.) Working with constructors 2a.) +Student() : This is the default constuctor. For the Strings properties, initialize them to null. The order is String ID, String name, String lastName, and double GPA. 2b.) +Student(value:String) - This constructor receives just the ID. 2c.) +Student(value:String, var: String) - This constructor receives...
C++ 1. Start with a UML diagram of the class definition for the following problem defining...
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...
Create a UML Class Diagram of a Food Supermarket. Show inheritance of common methods. Upload image.
Create a UML Class Diagram of a Food Supermarket. Show inheritance of common methods. Upload image.
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
Complete the following class UML design class diagram by filling in all the sections based on...
Complete the following class UML design class diagram by filling in all the sections based on the information given below.         The class name is Boat, and it is a concrete entity class. All three attributes are private strings with initial null values. The attribute boat identifier has the property of “key.” The other attributes are the manufacturer of the boat and the model of the boat. Provide at least two methods for this class. Class Name: Attribute Names: Method...
Given the following UML class diagram, implement the class as described by the model. Use your...
Given the following UML class diagram, implement the class as described by the model. Use your best judgment when implementing the code inside of each method. +---------------------------------------------------+ | Polygon | +---------------------------------------------------+ | - side_count : int = 3 | | - side_length : double = 1.0 | +---------------------------------------------------+ | + Polygon() | | + Polygon(side_count : int) | | + Polygon(side_count : int, side_length : double) | | + getSides() : int | | + setSides(side_count : int) | |...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
Draw UML diagram Define a class named Document that contains a member variable of type string...
Draw UML diagram Define a class named Document that contains a member variable of type string named text that stores any textual content for the document. Create a function named getText that returns the text field and a way to set this value. Next, define a class for Email that is derived from Document and that includes member variables for the sender , recipient , and title of an e-mail message. Implement appropriate accessor and mutator functions. The body of...
A UML class diagram has the following description about a member of the class: + getHeaderField(name:String):String...
A UML class diagram has the following description about a member of the class: + getHeaderField(name:String):String Which of the following is a correct declaration of the member in Java? 1 public String getHeaderField(String name) 2 public String getHeaderField; 3 public String getHeaderField(String) 4 public static String getHeaderField( name) ------------------------------------------------------------------------------------------------------------------------------------- Note: all answers are case sensitive. Inside a class, the declaration of a constructor looks like the following: public JButton(String text) 1. From the constructor, you infer that the name of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT