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
List two items that are required to make a text file into a bash script.
Olenka [21]

Answer:

Explanation:

First a header is needed indicating which bash will be used (sh, zsh, bash, etc.), then it is necessary to change the file extension so that the system recognizes it as an executable file and no longer as text

6 0
3 years ago
Alexa hoped that a good outline will accomplish which of the following for her<br> presentation?
atroni [7]

Answer: A. Help her distinguish between main topics and subtopics.

Explanation: APEX

6 0
3 years ago
Read 2 more answers
Filtering is a function of _____.
Levart [38]
The answer is: switches.

Explanation:

Filtering is a function of switches.
3 0
2 years ago
If a touch screen chrome is not charging what is wrong with it
AysviL [449]
Look it up on a best buy website ion know
5 0
3 years ago
Read 2 more answers
The blank method returns an integer between the two provided numbers. It can take the value of either of the provided numbers
Elis [28]

Answer:random

Explanation:

A random method returns a number between zero and one.

4 0
2 years ago
Other questions:
  • Match terms in the first column with the order descriptions in column two.
    11·1 answer
  • Which of the following tasks is least effective at preventing a computer virus?
    14·2 answers
  • Suppose company A wants to develop a program that duplicates the functionality of a programm by company B. Describe how company
    8·1 answer
  • Through the use of a _____ system, information on prospective, current, and past customers is stored and analyzed for future pla
    15·1 answer
  • Over the last few years, security cameras and other devices have become more common. Some people argue that these measures viola
    14·2 answers
  • Write a function called activity which takes an integer parameter X that does the following:
    6·1 answer
  • An attacker tried to hack into the database of a reputed organization. The attacker inserted malicious code into the query of a
    14·1 answer
  • Please create C program, the task is to implement a function edoublepowerx that has an input parameter x of floating-point value
    11·1 answer
  • All of the following are used to fund private schools except ______
    14·2 answers
  • Compare gigabytes GB, kilobytes and terabytes.​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!