Question

In: Computer Science

Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter,...

Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter, and pi is declared as double. Create the following for the Circle object:

● Implicit constructor (default constructor)

● Void method Calculate (double pi, int radius) to calculate the area of the Circle object. The method must include a system.out statement that displays the area value. Use the following formula to calculate area of the circle:

Area = pi * (r * r)

Your program includes a main class called Shape with a reference c1 to the Circle object. Pass the following values to the object Circle:

radius = 4

diameter = 8

pi = 3.14

Include output statements to view the values passed to the object Circle.

Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter, and pi is declared as double. Create the following for the Circle object:

● Implicit constructor (default constructor)

● Void method Calculate (double pi, int radius) to calculate the area of the Circle object. The method must include a system.out statement that displays the area value. Use the following formula to calculate area of the circle:

Area = pi * (r * r)

Your program includes a main class called Shape with a reference c1 to the Circle object. Pass the following values to the object Circle:

radius = 4

diameter = 8

pi = 3.14

Include output statements to view the values passed to the object Circle.

Solutions

Expert Solution

/*
 *  Circle.java file
 */

class Circle {
  private int radius;
  private int diameter;
  private double pi;

  public Circle()
  {
    this.radius = 0;
    this.diameter = 0;
    this.pi = 3.14;
  }

  public Circle(int rad, int dia, double pi)
  {
    this.radius = rad;
    this.diameter = dia;
    this.pi = 3.14;
  }

  public void Calculate(double pi, int radius)
  {
    this.radius = radius;
    this.pi = pi;
    System.out.println("Area: " + this.pi*this.pi*this.radius);
  }
}




/*
 *  Main.java file
 */

class Main {
  public static void main(String[] args)
  {
    int radius = 4;
    int diameter = 8;
    double pi = 3.14;

    Circle c1 = new Circle(4, 8, 3.14);
    c1.Calculate(pi, radius);
  }
}

Note: For example drop queries.


Related Solutions

Create a C# Application. Create a class object called “Employee” which includes the following private variables:...
Create a C# Application. Create a class object called “Employee” which includes the following private variables: firstN lastN idNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: constructor properties CalcPay(): Calculate the regular pay and overtime pay. Create...
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
follow pseudo 1) Create class called Node Declare private integer called data (or any other name)...
follow pseudo 1) Create class called Node Declare private integer called data (or any other name) Declare private Node called link (or any other name) 2) Declare constructor Should be public (ex: Node) where: link is equal to null data is equal to zero 3) Declare another constructor public Node with parameters integer d, Node n where: data is equal to d link is equal to n 4) Declare function to set link to next Node link equal to n...
7) Create the following using Java. Create a scanner Declare double variables for price and tax...
7) Create the following using Java. Create a scanner Declare double variables for price and tax Declare character variable reply Create do while loop Inside of do loop Prompt the console to display headline Product Price Check Prompt the user to enter initial price and relate to scanner Prompt the user to enter the tax rate and relate to scanner Calculate price which is equal to price multiply (1+tax/100) Display in console the cost after tax which is price Check...
Write a Circle class that has the following member variables: radius as a double PI as...
Write a Circle class that has the following member variables: radius as a double PI as a double initialized with 3.14159 The class should have the following member functions: Default constructor Sets the radius as 0.0 and pi as 3.14159 Constructor Accepts the radius of the circles as an argument setRadius A mutator getRadius An accessor getArea Returns the area of the circle getDiameter Returns the diameter of the circle getCircumference Returns the circumference of the circle Write a program...
Java language (a) Write code segments to perform the following: (i) declare and create an integer...
Java language (a) Write code segments to perform the following: (i) declare and create an integer array freqArray of size 8 (ii) declare and initialize an array weight (with suitable type) which contains 48.5, 80 and 68 (iii) declare a Mouse array of size 2 with name mouse and initialize it with Mouse objects using one statement (b) A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3};...
8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable...
8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable radius = -999 declare character choice create do while loop inside of do loop write: System.out.println(); System.out.println("*** CIRCLE CALCULATIONS ***"); System.out.println(); System.out.println("1. Enter the radius of the circle"); System.out.println("2. Display the area of the circle"); System.out.println("3. Display the circumference of the circle"); System.out.println("4. Quit"); System.out.println(); System.out.println("Enter a number from 1 - 4"); System.out.println(); Declare choice character and relate to scanner declare switch (choice) case...
an object is moving along a circle of radius 400.0m with a speed of 20.0m/s. the...
an object is moving along a circle of radius 400.0m with a speed of 20.0m/s. the centripetal force acting on the object is 500.0N a) find the mass of the object b) find the work done by the centripetal force c) what is the angular velocity of the object
Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.”
Programming Problem 2 - Cycle[A] Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.” Create a constructor with two parameters, using the same variable names in the parameter list. Assign each variable to numberOfWheels” and “weight” respectively. Write a separate application to test the class and display its properties. Note: Do not change the names of the instance variables or the variables listed in the constructor’s parameter list.[B] Edit your class Cycle by...
myLinkedList.java>>>>>>>> public class MyLinkedList implements MiniList<Integer>{ /* Private member variables that you need to declare: **...
myLinkedList.java>>>>>>>> public class MyLinkedList implements MiniList<Integer>{ /* Private member variables that you need to declare: ** The head pointer ** The tail pointer */ public class Node { // declare member variables (data and next) // finish these constructors public Node(int data, Node next) {} public Node(int data) {} // HINT: use this() with next = null } // Initialize the linked list (set head and tail pointers) public MyLinkedList() {} @Override public boolean add(Integer item) { return false; }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT