Your goal is to ask for the total bill and the amount that the user gave as a tip and determine based on a set of criteria whether that tip was a good amount.Create an algorithm, pseudocode and flowchart for this problem Code the solution for this problem prompt the user for the total bill amount.Prompt the user for the tip that they left Use the following equation to calculate the tip percentage: tip amount/total bill.Based on the tip percentage that was calculated, determine a message to display that will tell the user how good their tip was. Criteria: Tip less then 0 or greater than 1Tip is between 0 (including 0) and 0.05 (including 0.05)Tip is between 0.05 (not including 0.05) and 0.1 (including 0.1) Tip is between 0.1 (not including 0.1) and 0.2 (including 0.2) Tip is between 0.2 (not including 0.2) and 0.3 (including 0.30) Tip is greater than 0.3 Display the tip percentage that the user left along with a message as to how they rank as a tipper in an output box.
Pseudocode:
Start
Declare variables tipAmount,totalBill,tipPercentage
Read the total bill amount
Read the tip that they left
tipPercentage = tipAmount / totalBill
if tipPercentage >= 0 and tipPercentage <= 0.05 then
Display "You left " + (tipPercentage * 100.0) + "% tip.Tip was a poor amount."
if tipPercentage > 0.05 and tipPercentage <= 0.1 then
Display "You left " + (tipPercentage * 100.0) + "% tip.Tip was a fair amount."
if tipPercentage > 0.1 and tipPercentage <= 0.2 then
Display "You left " + (tipPercentage * 100.0) + "% tip.Tip was a good amount."
if tipPercentage > 0.2 and tipPercentage <= 0.3 then
Display "You left " + (tipPercentage * 100.0) + "% tip.Tip was a very good amount."
if tipPercentage > 0.3 then
Display "You left " + (tipPercentage * 100.0) + "% tip.Tip was an excellent amount."
Stop
flowchart
Java code:
import javax.swing.JOptionPane;
public class App {
/**
* The start point of the program
*
* @param args
*/
public static void main(String[] args) {
// Prompt the user for the total bill amount.
double totalBill = Double.parseDouble(JOptionPane.showInputDialog("Enter the total bill amount: "));
// Prompt the user for the tip that they left
double tipAmount = Double.parseDouble(JOptionPane.showInputDialog("Enter the tip that they left: "));
// Use the following equation to calculate the tip percentage:
// tip amount/total bill.
double tipPercentage = tipAmount / totalBill;
// Based on the tip percentage that was calculated,
// determine a message to display
// that will tell the user how good their tip was.
// Criteria:
// Tip less then 0 or greater than 1 Tip is between 0 (including 0) and 0.05
// (including 0.05)
if (tipPercentage >= 0 && tipPercentage <= 0.05) {
JOptionPane.showMessageDialog(null,
"You left " + (tipPercentage * 100.0) + "% tip.\nTip was a poor amount.");
}
// Tip is between 0.05 (not including 0.05) and 0.1 (including 0.1)
if (tipPercentage > 0.05 && tipPercentage <= 0.1) {
JOptionPane.showMessageDialog(null,
"You left " + (tipPercentage * 100.0) + "% tip.\nTip was a fair amount.");
}
// Tip is between 0.1 (not including 0.1) and 0.2 (including 0.2)
if (tipPercentage > 0.1 && tipPercentage <= 0.2) {
JOptionPane.showMessageDialog(null,
"You left " + (tipPercentage * 100.0) + "% tip.\nTip was a good amount.");
}
// Tip is between 0.2 (not including 0.2) and 0.3 (including 0.30)
if (tipPercentage > 0.2 && tipPercentage <= 0.3) {
JOptionPane.showMessageDialog(null,
"You left " + (tipPercentage * 100.0) + "% tip.\nTip was a very good amount.");
}
// Tip is greater than 0.3 Display the tip percentage that the user left along
// with a message as to how they rank as a tipper in an output box.
if (tipPercentage > 0.3) {
JOptionPane.showMessageDialog(null,
"You left " + (tipPercentage * 100.0) + "% tip.\nTip was an excellent amount.");
}
}
}
Comments
Leave a comment