I need to ask the user how much a meal costs.
Once they put in the price, I need to take their input and add 8% sales tax.
Print on the screen the
Order: $15.00
Tax: $1.20
Total $ 16.20
Then in a separate method
created suggested tips and print
Suggested Tips:
12% - $1.94
15% - $2.43
20% - $3.24
At first I had this as all one method with local variables. I did not have any compiling issues, but the question never appeared at the bottom of the screen like it has in past exercises.
I need to have the Question and the first part as a separate method from the generating taxes statement.
I am not sure if I run through both methods and put all showText statements as a separate method or if what I have should work.
I have the same problem as I did in the beginning. The Question is not showing up for me to get any input so I have no idea where any mistakes may be hiding.
Here is my code.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.text.DecimalFormat;
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 600, 1);
}
double taxPercentage = .08;
double orderPrice;
double price;
double total;
public void calculateTax ()
{
DecimalFormat money = new DecimalFormat("$0.00");
orderPrice = Double.parseDouble(Greenfoot.ask("How much did the odrer cost?"));
taxPercentage = orderPrice * taxPercentage;
price= orderPrice * taxPercentage + orderPrice;
showText("Price: " + money.format(orderPrice), getWidth()/2, getHeight()/2);
showText("Tax: " + money.format(taxPercentage), getWidth()/2,getHeight()/2+10);
showText("Total: " + money.format(price),getWidth()/2,getHeight()/2+20);
}
private void tips()
{
double tips12 = .012;
double tips15 = .015;
double tips20 = .020;
double price = orderPrice * taxPercentage + orderPrice;
DecimalFormat money = new DecimalFormat("$0.00");
tips12 = price * tips12 + price;
tips15 = price * tips15 + price;
tips20 = price * tips20 + price;
showText("Suggested Tips: ", getWidth()/2, getHeight() / 2 +35);
showText("12% - " + money.format(tips12), getWidth() /2 , getHeight() /2 +45);
showText("15% - " + money.format(tips15), getWidth() /2 , getHeight() /2 +55);
showText("20% - " + money.format(tips20), getWidth() /2 , getHeight() /2+65);
Greenfoot.stop();
}
}

