Skip to content

Instantly share code, notes, and snippets.

@fayimora
Forked from anonymous/ExamProg
Last active December 29, 2015 17:59
Show Gist options
  • Save fayimora/7707519 to your computer and use it in GitHub Desktop.
Save fayimora/7707519 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");
String message = "";
if (input.equalsIgnoreCase("Crisps"))
{
message = "Crisps: That is 0.9g of sodium per 100g. The salt content is very high";
}
else if (input.equalsIgnoreCase("Yoghurt"))
{
message = "Yoghurt: That is 0.06g of sodium per 100g. THe salt content is low";
}
else if (input.equalsIgnoreCase("Soup"))
{
message = "Soup: That is 0.22 of sodium per 100g. The salt content in medium";
}
else if (input.equalsIgnoreCase("Baked Beans"))
{
message = "Baked Beans: That is 0.4g of sodium per 100g. The salt content is high";
}
else if (input.equalsIgnoreCase("END"))
{
message = "Eat healthily, goodbye";
System.exit(0);
}
else
{
message = "Sorry I don't know that one";
}
JOptionPane.showMessageDialog(null, message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment