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

Write in C programming using if and else statements only please!!! Write a program that plays...
Write in C programming using if and else statements only please!!! Write a program that plays the following card game: The user starts out with a pot of $100. At each hand of the game, the dealer and the player are dealt a random number between 1 and 52. The player wins $20 if his/her number is greater than the dealer's number; otherwise they lose $20.
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...
JAVA 1 PROGRAMMING QUESTION In this program you will be writing a class that will contain...
JAVA 1 PROGRAMMING QUESTION In this program you will be writing a class that will contain some methods. These will be regular methods (not static methods), so the class will have to be instantiated in order to use them. The class containing the main method will be provided and you will write the required methods and run the supplied class in order to test those methods. ? Specifications There are two separate files in this program. The class containing the...
***In Java language***The first programming project involves writing a program that computes the salaries for a...
***In Java language***The first programming project involves writing a program that computes the salaries for a collection of employees of different types. This program consists of four classes. 1. The first class is the Employee class, which contains the employee's name and monthly salary, which is specified in whole dollars. It should have three methods: a. A constructor that allows the name and monthly salary to be initialized. b. A method named annualSalary that returns the salary for a whole...
Java Programming Write a program that displays the following pattern *                         *       &nbsp
Java Programming Write a program that displays the following pattern *                         *          *          * *          *          *          *          *          *          *          *          *          *          *          *             *          *          *          *          *                         *          *          *                                     * Printing Pattern A * ** *** **** ***** ****** ******* Printing Pattern B ******* ****** ***** **** *** ** * Printing Pattern C * ** *** **** ***** ****** *******
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT