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

Can someone help me put JOptionPane dialog boxes for all input and output. impor

ID: 645226 • Letter: C

Question

Can someone help me put JOptionPane dialog boxes for all input and output.

import java.util.*;
public class program7 {
public static void main (String [] args) {
Scanner myScanner = new Scanner (System.in);
Scanner console = new Scanner(System.in);
String buffer;
char shape=' ';
double pi=3.14159;
double vol;
double height;
double diameter;
double width;
double length;
  
//Prompt program to read in the type of shape by pulling of first character of word input.
while(shape !='q'){
System.out.print("Is the room rectangular or circular => ");
buffer=console.nextLine(); //get entire line
shape=buffer.charAt(0); //pulls off the first character
  
if(shape =='Q'){
shape = 'q';
}
  
if(shape=='R'){
shape='r';
}
if(shape=='C'){
shape='c';
}
  
if((shape=='C')||(shape== 'c')){
  
//Prompt for volume of circle
System.out.print("What is the height => ");
height=myScanner.nextDouble();
System.out.print("What is the diameter => ");
diameter=myScanner.nextDouble();
  
vol = (( pi* ((diameter/2.0) * (diameter/2.0)) * height));
  
System.out.print(("The room has a volume of ") + vol);
System.out.print("");
System.out.print("cubic meters.");
  
if ( vol <= 1000 ) {
System.out.println("The Stinker will be effective.");
}
else {
System.out.println("The Stinker will be ineffective.");
}
}
  
//Prompt for volume of a rectangle
else if (shape =='r') {

System.out.print("What is the height => ");
height=myScanner.nextDouble();
System.out.print("What is the width => ");
width=myScanner.nextDouble();
System.out.print("What is the length => ");
length=myScanner.nextDouble();

vol = ( length * width * height);

System.out.print(("The room has a volume of ") + vol);
System.out.print("");
System.out.print("cubic meters.");
  
if (vol <= 1000) {
System.out.println("The Stinker will be effective.");
}
else {
System.out.println("The Stinker will be ineffective.");
}
}
  
// Prompt for other shape besides circular or rectanglar
  
else if (shape =='q') {
System.out.print("Program ended.");
}
else {
System.out.println("Sorry-invalid input.");
}
}
  
}
}

Explanation / Answer

import java.util.*;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Program7 {
   public static void main(String[] args) {
       Scanner myScanner = new Scanner(System.in);
       Scanner console = new Scanner(System.in);
       String buffer;
       char shape = ' ';
       double pi = 3.14159;
       double vol;
       double height;
       double diameter;
       double width;
       double length;

       // Prompt program to read in the type of shape by pulling of first
       // character of word input.
       while (shape != 'q') {
           buffer = JOptionPane
                   .showInputDialog("Is the room rectangular or circular => ");
           shape = buffer.charAt(0); // pulls off the first character

           if (shape == 'Q') {
               shape = 'q';
           }

           if (shape == 'R') {
               shape = 'r';
           }
           if (shape == 'C') {
               shape = 'c';
           }

           if ((shape == 'C') || (shape == 'c')) {

               // Prompt for volume of circle
               height = Double.parseDouble(JOptionPane
                       .showInputDialog("What is the height => "));
               diameter = Double.parseDouble(JOptionPane
                       .showInputDialog("What is the diameter => "));

               vol = ((pi * ((diameter / 2.0) * (diameter / 2.0)) * height));

               JOptionPane.showMessageDialog(new JFrame("Output"),
                       ("The room has a volume of ") + vol + " cubic meters.");

               if (vol <= 1000) {
                   JOptionPane.showMessageDialog(new JFrame("Output"),
                           "The Stinker will be effective.");
               } else {
                   JOptionPane.showMessageDialog(new JFrame("Output"),
                           "The Stinker will be ineffective.");
               }
           }

           // Prompt for volume of a rectangle
           else if (shape == 'r') {

               height = Double.parseDouble(JOptionPane
                       .showInputDialog("What is the height => "));
               width = Double.parseDouble(JOptionPane
                       .showInputDialog("What is the width => "));
               length = Double.parseDouble(JOptionPane
                       .showInputDialog("What is the length => "));

               vol = (length * width * height);

               JOptionPane.showMessageDialog(new JFrame("Output"),
                       ("The room has a volume of ") + vol + " cubic meters.");

               if (vol <= 1000) {
                   JOptionPane.showMessageDialog(new JFrame("Output"),
                           "The Stinker will be effective.");
               } else {
                   JOptionPane.showMessageDialog(new JFrame("Output"),
                           "The Stinker will be ineffective.");
               }
           }

           // Prompt for other shape besides circular or rectanglar

           else if (shape == 'q') {
               JOptionPane.showMessageDialog(new JFrame("Output"),
                   "Program ended.");
           } else {
               JOptionPane.showMessageDialog(new JFrame("Output"),
                       "Sorry-invalid input.");
           }
       }

   }
}

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