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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!