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
In the 1960s, techniques were developed that allowed individuals to fool the phone system into providing free access to long dis
ycow [4]

Answer:

A

Explanation:

4 0
3 years ago
Which function of a web page relies on responsive web design
navik [9.2K]

Answer:

Adding extra horizontal scroll, Blocking mobile devices from viewing, Eliminating extra links, Resizing content to fit a screen.

Explanation:

3 0
3 years ago
Which lines of the code, marked by Q, are legally declared based on the scope of the variable?​
WINSTONCH [101]

inside a function or a block which is called local variables

4 0
2 years ago
Which of the following is NOT an algorithm?
Nata [24]

Answer:

d) rolling a pair of dice in monopoly

Explanation:

an algorithm is a process or set of rules followed in a particular order to perform a certain task. all of the other answers are a set of instructions that lead to something except for rolling a pair of dice. rolling a pair of dice can be a part of instruction but its not a process in itself.

hope this makes sense!

3 0
3 years ago
A painting company has determined that for every 112 square feet of wall space, one gallon of paint and eight hours of labor wil
zmey [24]

Answer:

The answer is C

Explanation:

7 0
2 years ago
Other questions:
  • Your computer is crashing on a regular basis. Which of the following is an operation available to the user that should help rese
    6·2 answers
  • Which of the following is true about occupations within the STEM fields? Many occupations use mathematics, even if it is not the
    11·2 answers
  • Types of operating systems
    5·2 answers
  • _____ are types of changes that occur when text has been omitted from a document and must be inserted later.
    8·2 answers
  • You have answered 4 of 18 questions.
    12·2 answers
  • Write a class Example() such that it has a method that gives the difference between the size of strings when the '-' (subtractio
    6·1 answer
  • The term that refers to the standard computer language for creating web pages is called:
    6·1 answer
  • PLEASE GO SUPPORT I JUST STARTED 3 WEEKS AGO AND I GET NO VIEWS
    12·2 answers
  • Which web browser was created by Google?
    5·2 answers
  • Miley met up with a bunch of her college friends after several years. She told them that she works for the sound department of a
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!