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]
4 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]4 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
Engineers are problem-solvers who use math, science, creativity and other knowledge and skills to solve problems. They use every
Elena-2011 [213]
Different types of engineers solve different kinds of problems. A mechanical engineer might design a rollercoaster that is fun and safe using knowledge of physics and mechanics,

this person is an engineer

just so u know I don't know if this is correct
8 0
3 years ago
Read 2 more answers
The MIQ inventory measures how much you value status. What are measures of status?
Alina [70]
When we're taking about measures of status, we're talking about either a socioeconomic perspective or something else. When we're talking about a socioeconomic perspective of status, there are two important measures. One would be social standing of a person and the other would be his economic standing. 
3 0
4 years ago
Ashley Baker has been the webmaster for Berryhill Finance only ten days when she received an e-mail that threatened to shut down
Natasha_Volkova [10]

Answer:

cyber-extortion

Explanation:

Ashley Baker has been the webmaster for Berryhill Finance only ten days when she received an e-mail that threatened to shut down Berryhill's website unless Ashley wired payment to an overseas account. Ashley was concerned that Berryhill Finance would suffer huge losses if its website went down, so she wired money to the appropriate account. The author of the e-mail successfully committed cyber-extortion.

7 0
3 years ago
3.5.6 Introduce Yourself, Part 2<br><br><br> please hellllpp it keeps saying the code is wrong
dalvyx [7]

Answer:

In Python:

name = "Arthur"

age = "62"

print("Hi! My name is "+name+" and I am "+age+" years old")

Explanation:

Given

See attachment

Required

Write a code to introduce yourself

Initialize name

name = "Arthur"

Initialize age

age = "62"

Print introduction

print("Hi! My name is "+name+" and I am "+age+" years old")

3 0
3 years ago
Witch is a game story device
natulia [17]
A PS4 because there the most popular game out right now
5 0
3 years ago
Other questions:
  • Which keyword helps you remember how to operate an extinguisher? A. MASH B. PASS C. PASH D. DASH
    11·2 answers
  • Theâ ______ is a large worldwide collection of networks that use a common protocol to communicate with one another.
    5·1 answer
  • A contact list is a place where you can store a specific contact with other associated information such as a phone number, email
    8·1 answer
  • Omar wants to know how his organization has been doing financially over the last year. He wants to also compare this information
    5·2 answers
  • Write a for loop that sets each array element in bonusScores to the sum of itself and the next element, except for the last elem
    11·2 answers
  • Should the federal government have bug bounty programs? Why or why not?
    9·2 answers
  • Select three functions of the cell membrane.
    15·2 answers
  • if I make an Xfinity account can I turn off parental controls that my sister put on with her Xfinity account?
    10·1 answer
  • Schuyler is making a list of the parts of a computer that are software. Which of the following will be on the list?
    13·2 answers
  • jelaskan tiga kemungkinan sebab pengasah pensil itu tidak dapat berfungsi secara tiba-tiba (translate: explain three possible re
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!