package lord1;
import javax.swing.JOptionPane;
public class carcontent {
private boolean istrue;
public carcontent()
{
istrue=true;
}
public void setgetistop(boolean stopistrue)
{
this.istrue=stopistrue;
}
public boolean getistop()
{
return istrue;
}
public static void main(String[]args)
{
carcontent set =new carcontent ();
String choice="";
double litre=0,maximum_gas=10,numberofgas=0,holddata=0,gascontent=0;
int loop=0;
do{
choice=JOptionPane.showInputDialog(null,"R--->run \nL--->Load gas \nS--->stop car \nC--->gas content \nE--->exit");
choice=choice.toUpperCase();
if(choice.equals("R")==true)
{
if(litre==0)
{
JOptionPane.showMessageDialog(null,"Gas is empty");
}
else if(litre<0.3 && litre!=0)
{
JOptionPane.showMessageDialog(null,"Warning please refill it");
}
else if(litre==10)
{
JOptionPane.showMessageDialog(null,"Gas is full\nPlease proceed");
set.setgetistop(false);
}
else
{
JOptionPane.showMessageDialog(null,"Car must stop");
}
}
if(choice.equals("L")==true)
{
if(litre==10)
{
JOptionPane.showMessageDialog(null,"Gas is full");
}
else
{
if(set.getistop()==true)
{
do{
loop=0;
numberofgas=Double.parseDouble(JOptionPane.showInputDialog(null,"The tank is full of fuel when it reaches 10 litres \nEnter number of gas"));
holddata=litre+numberofgas;
if(holddata > maximum_gas)
{
JOptionPane.showMessageDialog(null,"Please try again\n The maximum of gas content is 10 litre");
numberofgas=0;
loop=1;
}
else
{
litre=litre+numberofgas;
}
}
while(loop==1);
}
else
{
JOptionPane.showMessageDialog(null,"Car must stop");
}
}
}
if(choice.equals("S")==true)
{
set.setgetistop(true);
JOptionPane.showMessageDialog(null,"Car is stop");
}
if(choice.equals("C")==true)
{
if(litre==0)
{
JOptionPane.showMessageDialog(null,"Gas content is: " + litre + "\n The car is not yet travel");
}
else
{
gascontent=Double.parseDouble(JOptionPane.showInputDialog(null,"Enter number of travel in km"));
gascontent = gascontent * 0.5;
litre=litre-gascontent;
JOptionPane.showMessageDialog(null,"Gas content is: " + litre);
}
}
}//do
while(!choice.equals("E"));
JOptionPane.showMessageDialog(null,"System terminated");
}
}
No comments:
Post a Comment