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
Jlenok [28]
3 years ago
7

Write a Java program that can calculate and print out the area of a circle. The user enters data of the radius and its measureme

nt unit ("in" for inch, "ft" for feet, "cm" for centimeter, and "m" for meter) from the console. The program should check to be sure that the radius is not negative and the measurement unit must be one among the listed-above units.
Computers and Technology
1 answer:
mezya [45]3 years ago
5 0

Answer:

// program in java.

// package

import java.util.*;

// class definition

class Main

{

   // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

  // Scanner object to read input

Scanner scr=new Scanner(System.in);

 // variables

double rad;

String unit1="in";

String unit2="ft";

String unit3="cm";

String unit4="m";

// ask user to enter radius

System.out.print("Enter the radius: ");

 // read radius

rad=scr.nextDouble();

 // check radius is negative or not

while(rad<0)

{

    System.out.println("Radius can't be negative:");

     // ask again to enter radius

    System.out.print("Enter the Radius again:");

     // read radius again

    rad=scr.nextInt();

}

// ask user to enter the unit of measurement

System.out.print("Enter the unit (\"in\" for inch, \"ft\" for feet, \"cm\" for centimeter, and \"m\" for meter):");

 // read unit

 String unt=scr.next();

 // calculate area

double area=3.14*rad*rad;

 // print area and unit

if(unt.equals(unit1))

    System.out.println(area+" inch.");

else if(unt.equals(unit2))

    System.out.println(area+" feet.");

else if(unt.equals(unit3))

    System.out.println(area+" centimeter.");

else if(unt.equals(unit4))

    System.out.println(area+" meter.");

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read radius of circle from user with Scanner object and assign it to variable "rad".Check the radius is negative or not.If the radius is negative ask user to enter radius again until user enters a positive radius.Then read the unit of measurement.calculate the area of circle and print area with unit.

Output:

Enter the radius: -4

Radius can't be negative:

Enter the Radius again:6

Enter the unit ("in" for inch, "ft" for feet, "cm" for centimeter, and "m" for meter):cm

Area of circle is 113.03999999999999 centimeter.

You might be interested in
During the troubleshooting of a pc that will not boot, it is suspected that the problem is with the ram modules. the ram modules
Damm [24]
The modules were somehow disconnected
8 0
3 years ago
what is the name of the program that enables the device and operating system to communicate with each other?
Fittoniya [83]

Answer:

Explain Operating System working: OS works as an intermediate between the user and computer. It helps the user to communicate with the computer without knowing how to speak the computer's language. The kernel is the central component of a computer operating systems.

Explanation:

3 0
2 years ago
For this problem, you will write a function standard_deviation that takes a list whose elements are numbers (they may be floats
Evgesh-ka [11]

Answer:

  1. import math  
  2. def standard_deviation(aList):
  3.    sum = 0
  4.    for x in aList:
  5.        sum += x  
  6.    
  7.    mean = sum / float(len(aList))
  8.    sumDe = 0
  9.    for x in aList:
  10.        sumDe += (x - mean) * (x - mean)
  11.    
  12.    variance = sumDe / float(len(aList))
  13.    SD = math.sqrt(variance)
  14.    return SD  
  15. print(standard_deviation([3,6, 7, 9, 12, 17]))

Explanation:

The solution code is written in Python 3.

Firstly, we need to import math module (Line 1).

Next, create a function standard_deviation that takes one input parameter, which is a list (Line 3). In the function, calculate the mean for the value in the input list (Line 4-8). Next, use the mean to calculate the variance (Line 10-15). Next, use sqrt method from math module to get the square root of variance and this will result in standard deviation (Line 16). At last, return the standard deviation (Line 18).

We can test the function using a sample list (Line 20) and we shall get 4.509249752822894

If we pass an empty list, a ZeroDivisionError exception will be raised.

3 0
3 years ago
Betty set up an account on a popular social networking website. She wants to know whether the privacy policy is effective for he
Ahat [919]

the info needed to log in

-This would show what is protected in the privacy policy and its related to you since it would show personal data.

-A good Privacy Policy depends on understanding these matters - showing that this is not an agreement to take for granted.

7 0
3 years ago
Which of the following are screen objects used to maintain, view, and print data from a database
amid [387]

Answer:

The correct answer to the following question will be "A spreadsheet".

Explanation:

  • A spreadsheet is a software device used to access and stores data from such a database. The interaction between separate entities (in separate tables) is controlled by their specific columns.
  • It's a programming program for arranging, evaluating and storing data in tabular format.
  • The spreadsheets have been developed as computer-controlled analogs to paper reporting worksheets. The system runs on data decided to enter in table cells.

Therefore, a Spreadsheet is the right answer.

8 0
3 years ago
Other questions:
  • Which of the following is a special-purpose computer that functions as a component in a larger product?
    6·1 answer
  • You want to join your computer to a homegroup but you don't see any homegroups on your home network
    11·1 answer
  • A _____ attack floods a network or server with service requests to prevent legitimate users' access to the system. phishing back
    5·1 answer
  • _____ is a predefined format used for text the can include multiple font formatting features
    13·1 answer
  • write a function that given an integer Y and 3 non-empty string A,B,W, denotingthe year of vacations, the beginning month, the e
    5·1 answer
  • Q. Which protocol would best serve to authorize users to access directory services?
    8·1 answer
  • Write out a shorthand version of the border property which will apply border that is 5 px wide, colored in lightgreen, and solid
    9·1 answer
  • Which bug type would you suggest for the following bug? The button label "Add to cart" is not fully visible.
    5·1 answer
  • Many digital libraries have much more information than traditional libraries
    13·1 answer
  • You are asked to write a program that prompts the user for the size of two integer arrays, user input for the size must not exce
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!