Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java program that will calculate the area of circle orsquare depending u

ID: 3618192 • Letter: W

Question

Write a java program that will calculate the area of circle orsquare depending upon the user choice. First you will display yourVU id on screen.

Then you will ask the user for his/her choice.

If user will enter 1 your program will ask the user to input thelength of the side of the square and then your program will computeand display the area of square.

If user will enter 2. You will ask the user to enter and theradius of circle, and then your program will compute and displaythe area of circle.

If user will enter other then 1 or 2 as choice your code shoulddisplay wrong choice message.

Explanation / Answer

import javax.swing.*; public classAssignment {     public staticvoid main(String[] args) {         int choice=0;         double area=0;         String str;         //please change your ID        JOptionPane.showMessageDialog(null, "My ID isMCXXXXXXXXXX");        JOptionPane.showMessageDialog(null, "You canCalculate Area of Circle " +                "or Square with my Program Enter 1 for Square and2 for Circle");         str =JOptionPane.showInputDialog("Enter yourchoice");         choice =Integer.parseInt(str);         switch(choice)         {            case 1:                str = JOptionPane.showInputDialog("Enter thelength of the side of the square");                int side =Integer.parseInt(str);                area = side * side;                JOptionPane.showMessageDialog(null, "The Area ofsquare is " + area);                break;            case 2:                str = JOptionPane.showInputDialog("Enter theradius of circle");                int radius =Integer.parseInt(str);                area = Math.PI * (radius * radius);                JOptionPane.showMessageDialog(null, "The Area ofcircle is " + area);                break;            default:                JOptionPane.showMessageDialog(null, "Invalidchoice");                break;         }     } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote