Untitled
unknown
java
3 years ago
2.3 kB
7
Indexable
public static void main(String args[]) {
String[] shape = { "Circle", "Square", "Oval", "Rectangle" };
var selected = JOptionPane.showOptionDialog(null, "Enter the shape of your pizza", "Pizza Slices Calculator, 0, 3, null, shape, shape[0]);
if (selected == 0) {
string input = JOptionPane.showInputDialog("Enter the radius of circular pizza");
double radius = Double.parseDouble(input);
circle(radius);
}
if (selected == 1) {
string input = JOptionPane.showInputDialog("Enter the side of a squared pizza");
double side = Double.parseDouble(input);
slices = square(side);
JOptionPane.showMessageDialog(null, "The max number of slices is: " + slices);
}
if (selected == 2) {
string input1 = JOptionPane.showInputDialog("Enter the major axis of oval pizza");
double majorAxis = Double.parseDouble(input);
string input2 = JOptionPane.showInputDialog("Enter the minor axis of oval pizza");
double minorAxis = Double.parseDouble(input);
oval(majorAxis, minorAxis);
}
if (selected == 3) {
string input1 = JOptionPane.showInputDialog("Enter the length of rectangular pizza");
double length = Double.parseDouble(input1);
string input2 = JOptionPane.showInputDialog("Enter the width of rectangular pizza");
double width = Double.parseDouble(input2);
slices = rectangle(length, width);
JOptionPane.showMessageDialog(null, "The max number of slices is: " + slices);
}
}
public static void circle(double radius){
double area = Math.pi * radius * radius;
int slices = (int) Math.floor(area/40);
JOptionPane.showMessageDialog(null, "The max number of slices is: " + slices);
}
public static int square(double radius){
double area = side * side;
int slices = (int) Math.floor(area/40);
return slices
}
public static void oval(double majorAxis, double minorAxis){
double area = Math.pi * majorAxis * minorAxis;
int slices = (int) Math.floor(area/40);
JOptionPane.showMessageDialog(null, "The max number of slices is: " + slices);
}
public static int rectangel(double length, double width){
double area = length * width
int slices = (int) Math.floor(area/40);
return slices
}
Editor is loading...