Question
help me elaborate ( explain the code line by line) import javax.swing.JOptionPane; public class calculateamount { public static void main (String[] args) { // Assigning
help me elaborate ( explain the code line by line)
import javax.swing.JOptionPane;
public class calculateamount {
public static void main (String[] args) {
// Assigning value in the String
String str="\t Welcome to Rotary Club Price for an adult lunch set is $20 and price for kids set is $12. Customers can buy more than one adult set and kid set."
+ " Side orders can be added on at a separate price which includes $4 for salad and $5 for dessert.";
//It is used to create an information-message dialog titled "Message"
JOptionPane.showMessageDialog(null,str);
// Getting input from the user
int adult=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the number of adult person",0));
int kid=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the number of kid",0));
int salad=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the number of salad (if any)"));
int dessert=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the number of desert (if any)"));
// Calculating the total amount that needs to be paid
int total = adult*20+kid*12+salad*4+dessert*5;
// Printing the total cost
JOptionPane.showMessageDialog(null,"You have to pay $"+total+" Thank you! Have a great lunch");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started