1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Lisa [10]
3 years ago
15

Program 7 - Circle You write ALL the code, then run it - Produce the correct output. Turn in code and screen print of successful

run, for credit * Write a class for a Circle * Input only the radius. * Write functions that Calculate the circles Circumference, Area and Diameter, and print out the value of the radius * Include error checking for radius, must be greater than zero. Test all combinations

Computers and Technology
1 answer:
fgiga [73]3 years ago
7 0

Answer:

Here is the Circle class:

public class Circle {   // class definition

private int radius;    // private data member of type int of class Circle named radius that stores the value of radius

public Circle(int r) {   // parameterized constructor of class Circle that takes radius as argument

 radius = r;  }    // sets value of radius as r

public int getRadius() {   // accessor method to get the value of radius

 return radius;  }   // returns the current value of radius

public int Diameter() {   // method to compute diameter of a circle

 return radius * 2;  }   // multiply radius value by 2 to compute diameter of Circle

 

public double Area() {   // method to compute area of a circle

 return Math.PI  * Math.pow(radius, 2);   }   //the formula of area is

π x radius² where value of π is get using Math.PI

 

 public double Circumference() {   // // method to compute circumference of a circle

 return 2* Math.PI * radius;   }   }  //the formula of circumference is

2 x π x radius where value of π is get using Math.PI

Explanation:

Here is the Main class:

import java.util.Scanner;  //to accept input from user

public class Main {  //definition of Main class

public static void main(String[] args) {  //start of main method

   

    Scanner scanner = new Scanner (System.in);  //creates Scanner object to take input from user

    System.out.println("Enter radius: ");  //prompts user to enter radius

    int r = scanner.nextInt();  //reads the value of radius from user

 Circle c = new Circle(r);  // calls Constructor of Circle passing r as argument to it using the object c of class Circle

 

    if(c.getRadius()<=0){  //calls getRadius method to get current value of radius using objec and checks if this value (input value of r ) is less than or equal to 0

        System.out.println("Error!");   }  //when above if condition evaluates to true then print this Error! message

    else {  //if the value of radius is greater than 0

System.out.println("the radius of this Circle is: " +c.getRadius());  //calls getRadius method to return current value of r (input value by user)

System.out.println("the diameter of this Circle  is: " + c.Diameter());  //calls Diameter method to compute the diameter of Circle and display the result on output screen

System.out.printf("the circumference of this Circle  is: %.2f", c.Circumference());  //calls Circumference method to compute the Circumference of Circle and display the result on output screen

System.out.println();  //prints a line

System.out.printf("the Area of this Circle  is: %.2f", c.Area()); } }  }

//calls Area method to compute the Area of Circle and display the result on output screen

The program and its output is attached.

You might be interested in
Why did they removed the watch video button to view answers?​
MA_775_DIABLO [31]

Answer:

Umm I’m not sure

Explanation:

7 0
3 years ago
Which of the following can you not code in a subclass? Select one: a. a method with the same signature as a method in the superc
Ray Of Light [21]
<h2>Option D: a call to a private method of the superclass</h2>

Explanation:

Option a: a method with the "same signature" is allowed in the subclass. There will not be any confusion because the object which is trying to call the method will decide whether to call the sub class or super class.

Option b: a call to a super class constructor is possible because, when you create an object of sub class automatically the super class constructor will be called. Even the sub class constructor can call the super class constructor explicitly.

Option c: A subclass can create method that's not defined by the super class

Option D: a private method is private inside the class and hence even the object of that class cannot access.

8 0
3 years ago
I need help ASAP please and thank you!
S_A_V [24]

Answer:

Explanation: For the best approach, It would say Option 3, you're supporting the waiter and making the rude customer feel as if they got what they wanted of complaining to the manager.

The worst approach I think would be Option 4, but this feels opinion based. Choose what you feel would be the best approach for this one.

6 0
3 years ago
What utility in windows xp allows technicians to troubleshoot missing files, corrupt boot sectors?
Serggg [28]
Why are you windows xp skids here?
3 0
4 years ago
What is access 2016?
Goryan [66]

Access 2016 is what it is

4 0
3 years ago
Other questions:
  • Write a method void Print(int LastNumber, int numbersPerLine) that receives two integers
    15·1 answer
  • Which type of address defines a single network interface in a computer or other device?
    7·1 answer
  • A _______________ is software that can guess passwords.
    5·1 answer
  • What is labor and how does it relate to automobile!!!! NEED HELP PLEASEE
    13·1 answer
  • Create a goal seek analysis to determine what the price should be to generate demand of 2,625,000 tablets given that the supplie
    10·1 answer
  • You dad has given you his old digital scanner for your new computer. you plug it into the usb drive on your windows 8 computer b
    8·1 answer
  • in a typical e-mail address, the "host" is A. an account designated by a user name B. CPU processor 2500 C. the receiver of an e
    12·2 answers
  • Hello can you please help with this if you want to thank you!
    15·2 answers
  • AI structure question. Please help
    9·1 answer
  • What is the minimum amount of hard drive space required for a 64-bit Windows 10 installation?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!