Question

In: Computer Science

8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable...

8) Create the following program using Java.

Circle calculation using methods

Create scanner
declare double variable radius = -999
declare character choice

create do while loop
inside of do loop write:
System.out.println();
System.out.println("*** CIRCLE CALCULATIONS ***");
System.out.println();
System.out.println("1. Enter the radius of the circle");
System.out.println("2. Display the area of the circle");
System.out.println("3. Display the circumference of the circle");
System.out.println("4. Quit");
System.out.println();
System.out.println("Enter a number from 1 - 4");
System.out.println();


Declare choice character and relate to scanner

declare switch (choice)

case 1 radius which is equal to option1 method

case 2 call option2(radius)

case 3 call option3(radius)

case 4 quit

default
prompt the user to enter numbers from 1 - 4
close bracket
while condition choice !='4'

create method static double option1 gets the user to enter the radius of the circle
declare myradius variable double
declare a scanner
prompt the user to enter the radius of circle and relate to variable above with scaner
return the variable

create method static void option2 with parameter double radiusin
check condition id radiusin is equal to -999 display the message in console no radius is entered

else

declare variable double area
area is equal to 3.14 * radiusin * radiusin
display in console the area


create method static void option3 with parameter double radiusin
check condition id radiusin is equal to -999 display the message in console no radius is entered

else

declare variable double circumference
circumference is equal to 2 * 3.14 * radiusin
display in console the circumference

Solutions

Expert Solution

package learning;
import java.util.*;

public class Main{
        static double option1() {
                double myradius;
                Scanner input = new Scanner(System.in);
                System.out.print("Enter the radius of the circle : ");
                myradius = input.nextDouble();
                return myradius;
        }
        static void option2(double radiusin) {
                if(radiusin == -999) {
                        System.out.println("No radius entered!!");
                        return;
                }
                double area = 3.14 * radiusin * radiusin;
                System.out.println("Area : " + area);
        }
        static void option3(double radiusin) {
                if(radiusin == -999) {
                        System.out.println("No radius entered!!");
                        return;
                }
                double circumference;
                circumference = 2 * 3.14 * radiusin;
                System.out.println("Circumference : " + circumference );
        }
        
    public static void main(String[] args){
        
        Scanner input = new Scanner(System.in);
        double radius = -999;
        char choice;
        
        while(true) {
                System.out.println();
                System.out.println("*** CIRCLE CALCULATIONS ***");
                System.out.println();
                System.out.println("1. Enter the radius of the circle");
                System.out.println("2. Display the area of the circle");
                System.out.println("3. Display the circumference of the circle");
                System.out.println("4. Quit");
                System.out.println();
                System.out.println("Enter a number from 1 - 4");
                System.out.println();
                
                choice = input.next().charAt(0);
                
                switch(choice) {
                case '1':
                        radius = option1();
                        break;
                case '2':
                        option2(radius);
                        break;
                case '3':
                        option3(radius);
                        break;
                default:
                        return;
                }
        }
        
      
    }

}

OUTPUT:


Related Solutions

7) Create the following using Java. Create a scanner Declare double variables for price and tax...
7) Create the following using Java. Create a scanner Declare double variables for price and tax Declare character variable reply Create do while loop Inside of do loop Prompt the console to display headline Product Price Check Prompt the user to enter initial price and relate to scanner Prompt the user to enter the tax rate and relate to scanner Calculate price which is equal to price multiply (1+tax/100) Display in console the cost after tax which is price Check...
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
5) Create the following in a Java program Create a scanner Prompt the user to enter...
5) Create the following in a Java program Create a scanner Prompt the user to enter the name where the box of mail is shipping from and create the variable and relate to scanner Prompt the user to enter the name of destination where the box of mail will be shipped and create the variable and relate to scanner Prompt the user to enter the weight of the package and create variable to relate to scanner Calculate cost of shipping...
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter,...
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter, and pi is declared as double. Create the following for the Circle object: ● Implicit constructor (default constructor) ● Void method Calculate (double pi, int radius) to calculate the area of the Circle object. The method must include a system.out statement that displays the area value. Use the following formula to calculate area of the circle: Area = pi * (r * r) Your...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered this week. come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. Your program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye” message. Remember to...
4.) Create a Java program using the “extends” and “runnable” methods. You will be creating your...
4.) Create a Java program using the “extends” and “runnable” methods. You will be creating your own threaded program using the threadExtend.java code and the threadRunnable.java code. A.) Focus the threadExtend.java code DETAILS TO NOTE: - It creates 4 instances of the same thread. This means that the thread code is actually running 4 separate times - The thread accepts 2 parameters, an INTEGER from 1 to 4, as well as an ID - Note the parameters are hard coded...
in java my code double price[] = {26.99, 22.99, 13.99, 56.99, 38.99}; // Variable Declaration Scanner...
in java my code double price[] = {26.99, 22.99, 13.99, 56.99, 38.99}; // Variable Declaration Scanner keyIn = new Scanner(System.in); //Header System.out.println( "----------------------------------------\n" + " Grocery Shop Price Calculator \n" + "----------------------------------------\n") ; System.out.print ("Please enter the quantities for each item in the list? "); double totalCost = 0; double fishAmount = 0; for(int i=0; i<price.length; i++) { int items = Integer.parseInt(keyIn.nextLine()); if(i==4) fishAmount = price[i]*items; else totalCost = totalCost + price [i]*items; } System.out.print("Do you have the membership(Y/N) ");...
Write a program in java that uses methods to input data for calculation, calculate, and display...
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Double Linked List. 5. Insert a new node at the end of a DoubleLinked List 6. Insert a new node after the value 5 of Double Linked List 7. Delete the node with value 6. 8. Search an existing element in a...
A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String...
A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String variable called myString1 and initialize it to "Programming". C) Declare a String variable called myString2 and initialize it to "Language". D) Print the concatenation of myString0 + " is a " + myString1 + " " + myString2 + ".". E) Print the sum of the lengths of myString1 and myString2 (must call the length() method). F) Print the 2nd, 4th, and 7th character...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT