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
What option in the alignment settings for a cell should be used to put text in a diagonal fashion?
tigry1 [53]

Answer:

The orientation option

Explanation:

Orientation in excel allows you to rotate text in several different ways. We can used this option to spice things up a bit. There are several kinds of orientation. There is one where the orientation can be rotated and the other one where the text can be either be put in a vertical or diagonal fashion.

5 0
3 years ago
Read 2 more answers
Which of the following is an example of a runtime error?
Rina8888 [55]

Answer:

missing quotation marks around a string literal

6 0
3 years ago
Which of the following best describes the infrastructure ISPs provide?
svet-max [94.6K]

Answer:

cables, towers, and underground tubes

Explanation:

Its certainly the above one, and through this internet service is being provided. So internet service is self-understood, and what ISP firstly provides are cables, underground tubes, and the towers. And it is only these all through which the ISP provides internet service. And remember we are in this question dealing with the infrastructure and not the services or products. Hence, phone service, websites, and files, as well as the emails, search engines, and the videos, are not the solution here as they are not the infrastructure. And ISPs never provide the computers, ethernet cables or keyboards.

Hence, the correct answer is as mentioned in the answer section.

4 0
3 years ago
The program that solves problem 2 (a) on p.275 should be named as proj4_a.c. It must include and implement the following functio
avanturin [10]

Answer:

#include <iostream>

#include <cstring>

using namespace std;

bool isAPalindrome(char* palindrome);

int main()

{

   char palindrome[30];

   bool palindrome_check;

   cout << "Please enter an word or phrase.\n";

   cin.getline(palindrome, 30);

   palindrome_check = isAPalindrome(palindrome);

   if (palindrome_check = true)

   {

       cout << "Input is a palindrome\n";

   }

   else

   {

       cout << "Inputis not a palindrome\n;";

   }

system("pause");

return 0;

}

bool isAPalindrome(char* palindrome)

{

   char* front;  

   char* rear;  

front = palindrome;// starts at the left side of the c string

rear = (palindrome + strlen(palindrome)) - 1;//starts at the right side of the c-string. adds the c string plus the incriment value of s

while (front <= rear)

{

 if (front = rear)

 {

  front++;

  rear--;

 }

 else

 {

  return false;

 }

}

   return true;

}

7 0
3 years ago
Is this good connection to be able to record edit and post videos?
Sholpan [36]

Answer:

The answer to your query is Yes and the details are in explanation section.

Explanation:

The general rule video is

  • if you have 3 MB speed is enough for normal video.
  • 5 MB for HD
  • 25 MB for HDR or 4K

For the above it is clear that yes your connection is good enough for videos.

but it lack in HDR or 4K  videos.

4 0
2 years ago
Other questions:
  • Which social networking site became a gaming platform after 2009
    10·1 answer
  • 3. Under the Driver Responsibility Program, you may be assigned a number of points for:
    11·2 answers
  • Which type of financial institution typically has membership requirements?
    14·1 answer
  • JPG is considered a lossy file format. What does this mean?
    15·2 answers
  • State three advantages of using a printer​
    15·1 answer
  • NEED HELP ASAP!!!!!!
    7·2 answers
  • Your task is to build a palindrome from an input string.A palindrome is a word that readsthe same backward or forward. Your code
    12·1 answer
  • How would you describe binary to someone ??<br> PLEASE ANSWER I WILL GIVE U BRAINLY!!
    15·2 answers
  • What is Data rate?<br> What is BAUD RATE?<br> What is bandwidth?
    8·1 answer
  • I WILL GIVE BRAINLIST THING TO WHOEVER GIVES ME THE CORRECT ANSWER
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!