Question

In: Computer Science

This is for Java programming. Please use ( else if,) when writing the program) Write a...

This is for Java programming. Please use ( else if,) when writing the program)

Write a java program to calculate the circumference for the triangle and the square shapes:

The circumference for: Triangle = Side1 + Side2 +Sid3

Square = 4 X Side

When the program executes, the user is to be presented with 2 choices.

Choice 1 to calculate the circumference for the triangle

Choice 2 to calculate the circumference for the square

Based on the user's selection the selected shape's circumference is calculated

Hand in: The Design in pseudocode

                  The output for both shapes

                  The Source codes (java program)

  

Note the output should look like :

Square:

               Side =

             Circumference =

Triangle:

               Side1 =  

Side2 =

Side 3 =

             Circumference =

Solutions

Expert Solution

Please up vote ,comment if any query . Be safe.

Psuedo Code :

print "1. Circumference of Triangle."
print "1. Circumference of Square."
print "Enter choice: "

input choice

if choice equals to 1

        input side 1,side 2,side 3

        calculate circumference

        print "Triangle :"

       print "side1="

       print "side2="

       print "side3="

      print "Circumference="

if choice equals to 2

      input side of square

       calculate circumference

     

print "Square:""

       print "side1="

      print "Circumference="

Program : ***************Main.java******************************

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);//scanner object
        System.out.println("1. Circumference of Triangle."); //print menu
        System.out.println("1. Circumference of Square.");
        System.out.print("Enter choice: "); //prompt for choice
        int choice=sc.nextInt(); //read choice

        if(choice==1)//if choice is 1
        { //get all sides
            System.out.print("Entet all three sides : ");
            double side1=sc.nextDouble();
            double side2=sc.nextDouble();
            double side3=sc.nextDouble();
            //print sides and circumference
            System.out.println("Triangle=");
            System.out.println("\tSide1="+side1);
            System.out.println("\tSide2="+side2);
            System.out.println("\tSide3="+side3);
            System.out.println("\tCircumference = "+(side1+side2+side3));
        }
        else if(choice==2)
        {
            //prompt for side
            System.out.print("Entet side : ");
            double side1=sc.nextDouble();
            //print circumference
            System.out.println("Square:");
            System.out.println("\tSide= "+side1);
            System.out.println("\tCircumference = "+(side1*4));
        }
        else//print if choice not 1 or 2
            System.out.println("Invalid Choice try again.");
    }
  
}

Output :

Please upvote ,comment if any query .


Related Solutions

JAVA Program 2: In Order Using an IF/ELSE IF/ELSE structure, write a program that will prompt...
JAVA Program 2: In Order Using an IF/ELSE IF/ELSE structure, write a program that will prompt the user for three numbers and displays them in ascending order. First, the program will prompt the user for each of the three numbers. Next, find the smallest value of the three. Then decide which of the other two is the next smallest. Then have the program display the three numbers in ascending order. Be sure to do the following: Determine what the input...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester. The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester.    The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
***Please answer the question using the JAVA programming language. Write a program that calculates mileage reimbursement...
***Please answer the question using the JAVA programming language. Write a program that calculates mileage reimbursement for a salesperson at a rate of $0.35 per mile. Your program should interact (ask the user to enter the data) with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading > 13505.2 Enter ending odometer reading > 13810.6 You traveled 305.4 miles. At $0.35 per mile, your reimbursement is $106.89. ** Extra credit 6 points: Format the answer (2 points),...
Write the following program in java please. a. Include a good comment when you write the...
Write the following program in java please. a. Include a good comment when you write the method described below: Method method1 receives an integer, n, and a real number, d, and returns a real number. If the integer is positive it returns the square root of the real number added to the integer. If the integer is negative or zero it returns the absolute value of the integer multiplied by the real number. b. Write the statements from the main...
THIS IS JAVA PROGRAMMING Guessing the Capitals. Write a program Lab5.java that repeatedly prompts the user...
THIS IS JAVA PROGRAMMING Guessing the Capitals. Write a program Lab5.java that repeatedly prompts the user to enter a capital for a state (by getting a state/capital pair via the StateCapitals class. Upon receiving the user’s input, the program reports whether the answer is correct. The program should randomly select 10 out of the 50 states. Modify your program so that it is guaranteed your program never asks the same state within one round of 10 guesses.
Java Programming: Write a program that allows the user to compute the power of a number...
Java Programming: Write a program that allows the user to compute the power of a number or the product of two numbers. Your program should prompt the user for the following information: • Type of operation to perform • Two numbers (the arguments) for the operation to perform The program then outputs the following information: • The result of the mathematical operation selected. Menu to be displayed for the user: MATH TOOL 1. Compute the power of a number 2....
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT