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
বর্তমান করােনার ন্যায় পরিস্থিতি অর্থাৎ স্বাভাবিক শ্রেণি কার্যক্রম পরিচালনা সম্ভব
Zarrin [17]

Answer:

ayo fam

Explanation:

I dont think this is supposed to be here lol

5 0
3 years ago
Read 2 more answers
To test for the current date in a query, type ____ in the criteria row of the appropriate column.
lyudmila [28]

Answer:

zxc

Explanation:

zc

6 0
3 years ago
What is another name for a blue screen error which occurs when processes running in kernel mode encouter a problem and windows m
Sonbull [250]
Another name for a blue screen error is Blue screen of death
7 0
3 years ago
Who invented the Graphical User Interface (GUI)?
Ludmilka [50]
The Graphical User Interface was invented by <span>Xerox PARC by </span>Alan Kay<span>, </span>Douglas Engelbart
5 0
3 years ago
When a machine is having issues, an IT Support Specialist has to file an RMA, or Return Merchandise Authorization form, with the
melamori03 [73]

Answer:

The answer is "Option b"

Explanation:

This method is also known as the model is continuously developed, evaluated, applied and enhanced. It enables firms to manage transactions with its all-out returns, they can be used to calculate the final 7 digits of the Online charge level, and the wrong option can be described as follows:

  • In option a, It first find then arranging all the data.  
  • In option c, It provides essential updates and saves into the file.
  • In option d, It is an ideal plan for a lifetime operation.
5 0
3 years ago
Read 2 more answers
Other questions:
  • Which one of these is the most commonly used hardware interface for attaching peripherals to a microcomputer?
    8·1 answer
  • One vital component of your professional behavior with regard to computing systems today is the creation of​ _________.
    14·1 answer
  • What were the goals of the “paperless society” ideal?
    14·2 answers
  • What's the answer to the image? True or False
    15·1 answer
  • 50 points for each person brainless goes to the best answer
    14·2 answers
  • The Windows Remote Desktop Web connection that allows users to connect to a work or home computer and access files is considered
    7·2 answers
  • According to the video, some workers who work for themselves, such as Actors, Musicians, or Writers, may have what sort of worke
    7·1 answer
  • Can someone help me write an algorithm and a flow chart pls for question 3
    7·1 answer
  • Help me please. I dont really understand this.
    12·2 answers
  • What happens when you create a variable in a video game program?​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!