Friday, September 27, 2013

Exercise no. 42

package lord1;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JSeparator;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JButton;
import javax.swing.event.CaretListener;
import javax.swing.event.CaretEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.InputMethodEvent;

public class caculate extends JFrame {

private JPanel contentPane;
private JTextField tfNumforCH;
private JTextField tfNumforT;
private JTextField tfNumforA;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {caculate frame = new caculate();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public caculate() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblWelcomeToPeoples = new JLabel("Welcome to Peoples Park Davao");
lblWelcomeToPeoples.setFont(new Font("Times New Roman", Font.BOLD, 20));
lblWelcomeToPeoples.setBounds(85, 11, 282, 25);
contentPane.add(lblWelcomeToPeoples);

JLabel lblEntranceFeeFor = new JLabel("Entrance fee for");
lblEntranceFeeFor.setBounds(108, 48, 109, 25);
contentPane.add(lblEntranceFeeFor);

JLabel lblChildrenBelow = new JLabel("Children below 8");
lblChildrenBelow.setBounds(108, 84, 98, 14);
contentPane.add(lblChildrenBelow);

JLabel lblNewLabel = new JLabel("Tennager 17 below");
lblNewLabel.setBounds(108, 109, 109, 14);
contentPane.add(lblNewLabel);

JLabel lblAdult = new JLabel("Adult");
lblAdult.setBounds(108, 134, 81, 14);
contentPane.add(lblAdult);

JLabel lblFees = new JLabel("Fees");
lblFees.setBounds(269, 52, 46, 14);
contentPane.add(lblFees);

JLabel lblphp = new JLabel("5 php");
lblphp.setBounds(269, 84, 46, 14);
contentPane.add(lblphp);

JLabel lblphp_1 = new JLabel("7 php");
lblphp_1.setBounds(269, 109, 46, 14);
contentPane.add(lblphp_1);

JLabel lblphp_2 = new JLabel("10 php");
lblphp_2.setBounds(269, 134, 46, 14);
contentPane.add(lblphp_2);

JLabel lblNewLabel_1 = new JLabel("Payment Here:");
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 11));
lblNewLabel_1.setBounds(10, 160, 98, 14);
contentPane.add(lblNewLabel_1);

JLabel lblNewLabel_2 = new JLabel("Children");
lblNewLabel_2.setBounds(108, 175, 45, 15);
contentPane.add(lblNewLabel_2);

JLabel lblTeenager = new JLabel("Teenager");
lblTeenager.setBounds(108, 195, 81, 15);
contentPane.add(lblTeenager);

JLabel label_1 = new JLabel("Children");
label_1.setBounds(108, 215, 45, 15);
contentPane.add(label_1);

tfNumforCH = new JTextField();
tfNumforCH.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent arg0) {
int num1 = Integer.parseInt(tfNumforCH.getText());
int total = num1 * 5;
textField.setText(""+total);

textField_3.setText(""+total);
}
});
tfNumforCH.setBounds(270, 175, 35, 15);
contentPane.add(tfNumforCH);
tfNumforCH.setColumns(10);

tfNumforT = new JTextField();
tfNumforT.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
int num1 = Integer.parseInt(tfNumforT.getText());
int num2 = Integer.parseInt(tfNumforCH.getText());
int total = num1 * 7;
textField_1.setText(""+total);
int total1 = total + num2;
textField_3.setText(""+total1);
}
});
tfNumforT.setColumns(10);
tfNumforT.setBounds(270, 195, 35, 15);
contentPane.add(tfNumforT);

tfNumforA = new JTextField();
tfNumforA.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
int num1 = Integer.parseInt(tfNumforA.getText());
int total = num1 * 10;
textField_2.setText(""+total);

int num01 = Integer.parseInt(textField.getText());
int num02 = Integer.parseInt(textField_1.getText());
int num03 = Integer.parseInt(textField_2.getText());
int total1 = num01 + num02 + num03;

textField_3.setText(""+total1);
}
});
tfNumforA.setColumns(10);
tfNumforA.setBounds(269, 215, 35, 15);
contentPane.add(tfNumforA);

JSeparator separator = new JSeparator();
separator.setBounds(345, 233, 50, 2);
contentPane.add(separator);

JLabel lblNewLabel_3 = new JLabel("Total");
lblNewLabel_3.setBounds(310, 237, 46, 14);
contentPane.add(lblNewLabel_3);

textField = new JTextField();
textField.setEditable(false);
textField.setEnabled(false);
textField.setColumns(10);
textField.setBounds(349, 175, 35, 15);
contentPane.add(textField);

textField_1 = new JTextField();
textField_1.setEnabled(false);
textField_1.setEditable(false);
textField_1.setColumns(10);
textField_1.setBounds(349, 195, 35, 15);
contentPane.add(textField_1);

textField_2 = new JTextField();
textField_2.setEnabled(false);
textField_2.setEditable(false);
textField_2.setColumns(10);
textField_2.setBounds(349, 215, 35, 15);
contentPane.add(textField_2);

textField_3 = new JTextField();
textField_3.setEnabled(false);
textField_3.setEditable(false);
textField_3.setColumns(10);
textField_3.setBounds(350, 236, 35, 15);
contentPane.add(textField_3);

JButton submit = new JButton("Submit");
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, "OK");
}
});
submit.setBounds(230, 235, 75, 21);
contentPane.add(submit);
}
}

Exercise no. 27

package lord1;

import java.util.Arrays;

import javax.swing.JOptionPane;

public class sort {
   
    public static void main(String[] args) {
       
        String [] names = {"Lord","Welhim","Mitch","Lucker"};

        String output = "";

        Arrays.sort(names);


        for ( String name: names ){

            output = output+"\n"+name;

        }

        JOptionPane.showMessageDialog(null, output);

    }

}

Exercise no. 24

package lord1;

import java.util.Arrays;
import javax.swing.JOptionPane;

public class elementarray {
   
    public static void main(String[] args) {
       
        int [] num = {11,200,32,44,5,10,15,20,60};
        String output = "";
        Arrays.sort(num);
       
        for ( int x: num ){
           
            output = output+"\n"+x;
           
        }
       
        JOptionPane.showMessageDialog(null, output);
}

}


Thursday, September 26, 2013

Exercise no. 40

package lord1;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;


public class positivenegativeoe extends JFrame implements ActionListener
{
    private Container con=getContentPane();
    JButton ok;
    JLabel number;
    JTextField fieldnumber;
    JPanel one,two,main;
  
  
    public void actionPerformed(ActionEvent e)
    {
      
        try{
        Double x=(double) 0;
      
        if(e.getSource().equals(ok))
        {
            x=Double.parseDouble(fieldnumber.getText());
          
          
          
            if(x>0)
            {
                //positive
                if(x%2==0)
                {
                    JOptionPane.showMessageDialog(main," EVEN-POSITIVE");
                    fieldnumber.setText("");
                  
                }
                else
                {
                    JOptionPane.showMessageDialog(main," ODD-POSITIVE");
                    fieldnumber.setText("");
                }
            }
            else
            {
                //negative
                if(x%2==0)
                {
                    JOptionPane.showMessageDialog(main," EVEN-NEGATIVE");
                    fieldnumber.setText("");
                }
                else
                {
                    JOptionPane.showMessageDialog(main," ODD-NEGATIVE");
                    fieldnumber.setText("");
                }
            }
          
        }
        }catch(Exception f)
        {
            JOptionPane.showMessageDialog(main,"Please try again");
            fieldnumber.setText("");
        }
    }
  
    public positivenegativeoe()
    {
        ok=new JButton("OK");
        ok.setBackground(Color.gray);
        ok.setForeground(Color.WHITE);
        number=new JLabel("Enter number :");
        fieldnumber=new JTextField(10);
      
    ok.addActionListener(this);
      
        one=new JPanel(new GridLayout(1,2));
        one.add(number);
      
        two=new JPanel(new GridLayout(1,2));
        two.add(fieldnumber);
        two.add(ok);
      
        main=new JPanel(new GridLayout(2,1));
        main.add(one);
        main.add(two);
      
      
    setLayout(new FlowLayout());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    con.setBackground(Color.green);
    con.add(main);
    setSize(300,150);
    setVisible(true);  
    }
  
public static void main(String[]args)
{
    positivenegativeoe out=new positivenegativeoe();
    out.setLocationRelativeTo(null);
}
}

Exercise no. 39

package lord1;

import javax.swing.*;
import javax.swing.border.Border;

import java.awt.event.*;
import java.awt.*;
import java.awt.event.ActionListener;

public class d5 extends JFrame implements  ActionListener
{
   
  private Container con=getContentPane();
 JLabel first ;
 JButton ok,cancel;
 JTextField firstnum,secondnum,result;
JPanel firstpanel,secondpanel,mainpanel1,mainpanel;
JPanel field1,field2,results;

public void actionPerformed(ActionEvent e)
{
  
    if(e.getSource().equals(ok))
    {
      
        String textFieldValue1="";
        String divisible="";
         String textFieldValue2="";
        Integer result2=0;
         
        if(firstnum.getText().equals("") || secondnum.getText().equals(""))
        {
          
            {
              
            }
            JOptionPane.showMessageDialog(firstpanel, "Please try again");
            firstnum.setText("");
            secondnum.setText("");
        }
        else
        {
            try{
              
            textFieldValue1=firstnum.getText();
            textFieldValue2 = secondnum.getText();
          
          
          
           int x=Integer.parseInt(textFieldValue1);
           int y=Integer.parseInt(textFieldValue2);
         
        
         
              result2=x+y;
            
              if(result2 % 5==0)
              {
                  divisible="and is divisible by 5.";
              }
              else
              {
                  divisible="and is not divisible by 5.";
              }
            
              result.setText("The sum is : "+result2+"\t"+divisible);
            }
            catch (Exception f)
            {
                 JOptionPane.showMessageDialog(firstpanel, "Please use number");
                 firstnum.setText("");
                 secondnum.setText("");
              
            }
        }
      
    }
    else if(e.getSource().equals(cancel))
    {
        firstnum.setText("");
        secondnum.setText("");
        result.setText("");
  
      
    }
}

public d5()
{
    first=new JLabel("Enter first number :");
    ok=new JButton("OK");
    ok.setBackground(Color.gray);
    ok.setForeground(Color.WHITE);
    cancel=new JButton("CANCEL");
    cancel.setBackground(Color.gray);
    cancel.setForeground(Color.WHITE);
    firstnum=new JTextField(10);
    secondnum=new JTextField(10);
    result=new JTextField(20);
  
    result.setEditable(false);
  
    secondpanel=new JPanel(new GridLayout(1,2));
  
    ok.addActionListener(this);
    cancel.addActionListener(this);

    secondpanel.add(ok);
    secondpanel.add(cancel);
  
     Border border = BorderFactory.createLineBorder(Color.orange, 5);
     firstnum.setBorder(border);
     secondnum.setBorder(border);

    firstpanel=new JPanel(new GridLayout(3,1));
    firstpanel.add(first);
    firstpanel.add(firstnum);
    firstpanel.add(secondnum);

  
  

  
    results=new JPanel();
  
  
  
    mainpanel1=new JPanel(new GridLayout(2,1));
    mainpanel1.add(firstpanel);
    mainpanel1.add(secondpanel);
  
  
  
  
  
  
    mainpanel=new JPanel(new GridLayout(1,2));
    mainpanel.add(mainpanel1);
  
    mainpanel.setBackground(Color.GREEN);
  
    con.setLayout(new GridLayout(1,2));
    con.add(mainpanel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    con.setBackground(Color.green);
    con.setLayout(new FlowLayout());
    con.add(results);
  
    results.add(result);
    results.setBackground(Color.orange);
  
  
  
    setSize(500, 200);
    setVisible(true);

}


  
  
    public static void main(String[]args)
    {
        d5 d =new d5();
    }

}

Exercise no. 38

package lord1;

import javax.swing.*;

import java.awt.*;

public class guiframe extends JFrame
{
    private static final Color yellowgreen = null;
  
private Container con=getContentPane();
final int width_of_Frame=400;
final int height_of_Frame=150;
JLabel first=new JLabel ("  Enter first number  :");
JLabel second=new JLabel("Enter second number :");
JTextField firstfield=new JTextField(10);
JTextField secondfield=new JTextField(10);
JButton ok = new JButton    ("  1OK" );
JButton Cancel = new JButton("Cancel"); 


public guiframe()
{
    super("My JFrame");
    setSize(width_of_Frame,height_of_Frame);
JPanel firstfieldpane =new JPanel();
JPanel secondfieldpane =new JPanel();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    con.setBackground(Color.green);
    con.setLayout(new FlowLayout());
    con.add(first);
    con.add(firstfieldpane);
    con.add(ok);
    con.add(second);
    con.add(secondfieldpane);
    con.add(Cancel);
 
    ok.setBackground(Color.green);
    Cancel.setBackground(Color.green);
 
    firstfieldpane.add(firstfield);
    firstfieldpane.setBackground(Color.orange);
    secondfieldpane.add(secondfield);
    secondfieldpane.setBackground(Color.orange);
 
 
 
 
}
 
public static void main(String[]args)
{
    guiframe myframe=new guiframe();
    myframe.setVisible(true);
 
}
}

Exercise no. 28

package lord1;

import javax.swing.JOptionPane;

public class mmultiplication {

    public static void main(String[]args)
    {
     
Integer []ratepeproduct=new Integer[3];
Integer [][]item_order_perday=new Integer[3][4];
Integer []result=new Integer[4];


Integer beef=0,chicken=0,vegetable=0;

Integer orderitem=0,datecurrent=0,beef2=0,chicken2=0,vegetable2=0;


String day[]=new String []{"Monday","Tuesday","Wednesday","Thursday"};

int sum=0;



    for(int y=0;y<3;y++)
    {
     
        if( y==0)
        {
        beef=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Price for Beef"));
        ratepeproduct[y]=beef;
        }
        if(  y==1)
        {
        chicken=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Price for chicken"));
        ratepeproduct[y]=chicken;
        }
        if(  y==2)
        {
        vegetable=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Price for vegetable"));
        ratepeproduct[y]=vegetable;
        }
    }


for(int xx=0;xx<3;xx++)
{
    for(int yy=0;yy<4;yy++)
    {
     
        orderitem=Integer.parseInt(JOptionPane.showInputDialog(null,day[yy] ));
        item_order_perday[xx][yy]=orderitem;
        orderitem=0;
    } 
}
     


  
   for ( int d = 0 ; d < 4 ; d++ )
   { 
      for ( int k = 0 ; k < 3 ; k++ )
      {
     
          if(k==0)
          {
           beef2 = beef2 + ratepeproduct[k]*item_order_perday[k][d];
          }
          if(k==1)
          {
          chicken2 = chicken2 + ratepeproduct[k]*item_order_perday[k][d];
          }
          if(k==2)
          {
           vegetable2 = vegetable2 + ratepeproduct[k]*item_order_perday[k][d];
          }
       
          sum = sum + ratepeproduct[k]*item_order_perday[k][d];
      }

      result[d] = sum;
      sum = 0;



}

   for (int d = 0 ; d < 4 ; d++ )
   {
  
       JOptionPane.showMessageDialog(null,day[d]+" Income : "+result[d]);
    
   }
   JOptionPane.showMessageDialog(null,"Total Income in beef from monday to thursday is : P" +beef2);
   JOptionPane.showMessageDialog(null,"Total Income in chicken from monday to thursday is : P" +chicken2);
   JOptionPane.showMessageDialog(null,"Total Income in vegetable from monday to thursday is : P" +vegetable2);

}
  
       
    }

Exercise no. 26

package lord1;

import java.util.Arrays;

import javax.swing.JOptionPane;


public class multiplication {
  
    public static void main(String[]args)
    {
        Integer [][]etimes=new Integer[25][4];
        int time=0,loop=1;
        Integer answer=0;
        String container="Multiplication Table   \n";
        for(int x=0;x<25;x++)
        {
            for(int y=0;y<4;y++)
            {
                time+=1;
          
                if(time>10)
                {
                    time=1;
                    if(loop!=11)
                    {
                        if(loop!=10)
                        {
                            loop+=1;
                        }  
                    }
                }
                if(loop!=11)
                 {
                   etimes[x][y]=loop * time;
                   answer=etimes[x][y];
                 }
                //display in proper place
                if(time==10)
                {
                  container+=" \t   " + loop + " x " + time + " = " + answer;  
                  container+="\n";
              
                }
                else
                {
                     container+=" \t   " + loop + " x " + time + " = " + answer;  
                }
            }    //second loop
        }    //first loop
      
        JOptionPane.showMessageDialog(null,  container );  
    }
}

Exercise no. 23

package lord1;

import javax.swing.JOptionPane;

public class arraydelete {
     
    public static void main(String[]args)
    {
        String[][] arr = new String[5][2];
        String choice=" ";
        String container="";
        String element="";
String sumpay="";
     
        do{
        choice=JOptionPane.showInputDialog(null,"V--->View element  \nD--->Delete element  \nI--->Insert element \nE--->Exit");
        choice=choice.toUpperCase();
     
        //view element
        if(choice.equals("V")==true)
        {
            sumpay="";
            for(int column=0;column<5;column++)
            {
                for(int row=0;row<2;row++)
                {
                    sumpay+=  " "+ arr[column][row];
                 
                }
            }
            JOptionPane.showMessageDialog(null, "Array element " + sumpay);
         
         
        }
        //delete element
        if(choice.equals("D")==true)
        {
           
            int empty=0;
            int notempty=0;
             element=JOptionPane.showInputDialog(null,"Enter element");
             for(int column=0;column<5;column++)
                {
                    for(int row=0;row<2;row++)
                    {
                        if(arr[column][row]!=null)
                        {
                     
                            if(arr[column][row].equals(element)==true)
                             {
                               arr[column][row]=null;
                               notempty=1;
                            
                             }
                        }
                     
                        else
                        {
                            empty=1;
                        }
                }
            }
          
          
             if(empty==0 && notempty==1)
             {
                 JOptionPane.showMessageDialog(null, "value is deleted");
                 notempty=0;
             }
             if(empty==1 && notempty==0)
             {
                 JOptionPane.showMessageDialog(null, "Element is not on the list to delete");
               
               
                 empty=0;
               
             }
     
        }
     
//insert element
if(choice.equals("I")==true)
        {
              for(int column=0;column<5;column++)
                {
                   for(int row=0;row<2;row++)
                     {
                      container=JOptionPane.showInputDialog(null,"Maximum value is 10" + "\nColumn [" + column + "]" + "Row [" + row + "]" +" Insert element");
                   
                      if(arr[column][row]!=null)
                      {
                   
                                if(arr[column][row].equals(container)==true)
                                     {
                                        JOptionPane.showMessageDialog(null, "Already exists");
                                     }
                               else
                                    {
                                   JOptionPane.showMessageDialog(null, "occupied");
                                  
                                     }
                      }
                      else
                      {
                          arr[column][row]=container;
                      }
                   
                 
                }//first for
            }//first for
        }
        }
        while(choice.equals("E")==false);
     
        JOptionPane.showMessageDialog(null, "System terminated");
    }
}

Exercise no. 22

package lord1;

import javax.swing.JOptionPane;


public class searchelement {
 
public static void main(String[]args)

   int display=0; 
   String x="",xx="";
   String y="",yy="";
   double container=0;
   
   x=JOptionPane.showInputDialog(null,"Enter Size of Array:\nEnter column\n");
   y=JOptionPane.showInputDialog (null," Rows");
   int c=Integer.parseInt(x);
   int r=Integer.parseInt(y);
   Integer arr [][]=new Integer [c][r];

for(int f=0;f<c;f++)
{
for(int g=0;g<r;g++)
 {
   String user=JOptionPane.showInputDialog(null,"Enter element");
   int user1=Integer.parseInt(user);
   arr[f][g]=user1;         
 }
}
   xx=JOptionPane.showInputDialog(null,"Search Value");
   int cc=Integer.parseInt(xx);
   int ff=0,gg=0;
for( ff=0;ff<c;ff++)
{
for( gg=0;gg<r;gg++)
    {
      if(arr[ff][gg]==cc) 
       {
       
         container=arr[ff][gg];
         JOptionPane.showMessageDialog(null,"The Values is :  " + container + "  Location "+ "["+ ff + " ]" + " " + "["+ gg + " ]"  );
      

         break;
    
       }
    
        
   }
}
if(container==0)
{
   JOptionPane.showMessageDialog(null, "Not found in the list ");
}




}
}

Exercise no. 21

package lord1;


import javax.swing.JOptionPane;


public class lwarray {

public static void main(String[]args)
{
double    array [][] = new double [5][2];
int    colum=5;
int rows=2;
double    high=0;
double    low=0;
int i,j = 0,z=0,loop1=0;
  Integer f=0,location;

for ( i = 0; i <5; i++)
{
for ( j = 0; j <2; j++)
{

      do{
          loop1=0;
          z=0;
     
       
          String user=JOptionPane.showInputDialog(null,"Location"+ "["+ i + " ]" + " " + "["+ j + " ]" +  "Enter number");
       
     
       
      for(int x=0;x< user.length();x++)
          {
              char c = user.charAt(x);
           
              int ascii = (int) c;
       
         
            if((ascii>=48 && ascii<=57))
          {
       
               z=1;
          }
          else
          {
              loop1=1;
          }
       
      
       
      
          }
   
       
         if(z==1 && loop1==0 )
         {
     f =Integer.parseInt(user);
   
      array[i][j] = f;
         }
         else
         {
             JOptionPane.showMessageDialog(null,"Please try Again");
         }
      }
      while(loop1>0 );
}
         
}


int in=0,jn=0,in1=0,jn1=0;

for ( i = 0; i <5; i++)
{
for ( j = 0; j <2; j++)
{
  if(i==0 && j==0)
    {
    high=array[i][j];
    low=array[i][j];
    }   
      if( array[i][j] >= high)
                  {
                    high =  array[i][j] ;
                    in1=i;
                    jn1=j;
                 
                  }
   
                 if(array[i][j] <= low)
                 {
                    low =  array[i][j];
                    in=i;
                    jn=j;
                 }



}


}

JOptionPane.showMessageDialog(null,"Location"+ "["+ in1 + " ]" + " " + "["+ jn1 + " ]" + "High is: " + high + "\n");
JOptionPane.showMessageDialog(null,"Location"+ "["+ in + " ]" + " " + "["+ jn + " ]" + "Low is:" + low);

}
}

Exercise no. 20

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"); 
  
     
     

}