Skip to content

Instantly share code, notes, and snippets.

Created November 29, 2013 15:33
Show Gist options
  • Save anonymous/7707377 to your computer and use it in GitHub Desktop.
Save anonymous/7707377 to your computer and use it in GitHub Desktop.
import javax.swing.*;
class examprog
{
public static void main (String[] param)
{
askfood();
System.exit(0);
}
public static void askfood()
{
String[] food = {"Crisps","Yoghurt","Soup","Baked Beans"};
String stop = "END";
String input = JOptionPane.showInputDialog("I can tell you about the salt content of the following food: \nCrisps, Yoghurt, Soup, Baked Beans \nPlease type one of the above foods or END to exit");
while (input!="END")
{
input = JOptionPane.showInputDialog("I can tell you about the salt content of the following food: \nCrisps, Yoghurt, Soup, Baked Beans \nPlease type one of the above foods or END to exit");
if (input.equalsIgnoreCase("Crisps"))
{
JOptionPane.showMessageDialog(null, "Crisps: That is 0.9g of sodium per 100g. The salt content is very high");
}
else if (input.equalsIgnoreCase("Yoghurt"))
{
JOptionPane.showMessageDialog(null, "Yoghurt: That is 0.06g of sodium per 100g. THe salt content is low");
}
else if (input.equalsIgnoreCase("Soup"))
{
JOptionPane.showMessageDialog(null, "Soup: That is 0.22 of sodium per 100g. The salt content in medium");
}
else if (input.equalsIgnoreCase("Baked Beans"))
{
JOptionPane.showMessageDialog(null, "Baked Beans: That is 0.4g of sodium per 100g. The salt content is high");
}
else if (input.equalsIgnoreCase("END"))
{
JOptionPane.showMessageDialog(null, "Eat healthily, goodbye");
System.exit(0);
}
else
{
JOptionPane.showMessageDialog(null, "Sorry I don't know that one");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment