new to I.T. need help about the problem analysis ,algorithm design, formatting the output
package gasolinestation;
import javax.swing.JOptionPane;
public class GasolineStation
{
public static void main(String[] args)
{
float total, money;
String yesno;
JOptionPane.showMessageDialog(null, "Welcome to Gasoline Station!");
do
{
String select = JOptionPane.showInputDialog(null, "1 = Diesel .................... $ 39.00\n"
+ "2 = Unleaded .................... $ 49.95\n"
+ "3 = Extreme ................ $ 51.95\n"
+ "4 = Kerosene ................ $ 00.00\n\n"
+ "Enter the number of your choice:");
if("1".equals(select))
{
String liter = JOptionPane.showInputDialog(null, "How many liters of Diesel?");
total = (float)(39.00*Float.parseFloat(liter));
JOptionPane.showMessageDialog(null, "Total price: $ "+total);
String pera = JOptionPane.showInputDialog(null, "Enter your money!");
money = Float.parseFloat(pera);
if(money>total)
{
JOptionPane.showMessageDialog(null, "Your change is: $ "+(money-total));
}
else
{
JOptionPane.showMessageDialog(null, "Insufficient money!");
}
}
else if("2".equals(select))
{
String liter = JOptionPane.showInputDialog(null, "How many liters of Unleaded?");
total = (float)(49.95*Float.parseFloat(liter));
JOptionPane.showMessageDialog(null, "Total price: $ "+total);
String pera = JOptionPane.showInputDialog(null, "Enter your money!");
money = Float.parseFloat(pera);
if(money>total)
{
JOptionPane.showMessageDialog(null, "Your change is: $ "+(money-total));
}
else
{
JOptionPane.showMessageDialog(null, "Insufficient money!");
}
}
else if("3".equals(select))
{
String liter = JOptionPane.showInputDialog(null, "How many liters of Extreme?");
total = (float)(51.95*Float.parseFloat(liter));
JOptionPane.showMessageDialog(null, "Total price: $ "+total);
String pera = JOptionPane.showInputDialog(null, "Enter your money!");
money = Float.parseFloat(pera);
if(money>total)
{
JOptionPane.showMessageDialog(null, "Your change is: $ "+(money-total));
}
else
{
JOptionPane.showMessageDialog(null, "Insufficient money!");
}
}
else if("4".equals(select))
{
String liter = JOptionPane.showInputDialog(null, "How many liters of Kerosene?");
total = (float)(00.00*Float.parseFloat(liter));
JOptionPane.showMessageDialog(null, "Total price: $ "+total);
String pera = JOptionPane.showInputDialog(null, "Enter your money!");
money = Float.parseFloat(pera);
if(money > total)
{
JOptionPane.showMessageDialog(null, "Your change is: $ "+(money-total));
}
else
{
JOptionPane.showMessageDialog(null, "Insufficient money!");
}
}
else
{
JOptionPane.showMessageDialog(null, "Invalid number!");
}
String repeat = JOptionPane.showInputDialog(null, "Would you like to try again? (Y/N): ");
yesno = String.valueOf(repeat);
}
while("Y".equals(yesno) || "y".equals(yesno));
}
}
Inline Code Example Here