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

}

Friday, August 16, 2013

Exercise No. 19

 import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class Exercise19{
  
    public static void main(String[]args)
    {
        double h=0;
        double v=0;
        double c=0;
        double t;
     
     
        int boss=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the Volume of cylinder"));
        int boss1=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the Radius of cylinder"));
     
        double j = Math.pow(boss1, 2);
  
        h=boss/3.16*j;
       
        c=2*3.16 * j*(j+h);
       
        DecimalFormat fomat = new DecimalFormat("###.##");
       
        JOptionPane.showMessageDialog(null,"Height :  " + fomat.format(h) + "\nCost :  " + c);
     
     
  
     
     
     
     
    }

}

Exercise no. 18

import javax.swing.JOptionPane;


public class Exercise18 {
  
    public static void main(String []args)
    {
     
        int score=0;
        int score1=0;
     
  
        for(int x=1;x<=9;x++)
           
        {
            score=Integer.parseInt(JOptionPane.showInputDialog(null, "Team  A " + "\n" + "Enter Runs Score " + " inning [" + x + "]"));
            score=score+score;
        }
     
        for(int y=1;y<=9;y++)
           
        {
            score1=Integer.parseInt(JOptionPane.showInputDialog(null, "Team  B " + "\n" +" Enter Runs Score "+ " inning [" + y + "]"));
            score1=score1+score1;
        }
     
        JOptionPane.showMessageDialog(null, "Total Score of Team  A : " + score + "\n" + "Total Score of Team  B :" + score1);
     
    }
  

}

Exercise17

   import javax.swing.JOptionPane;


public class Exercise17 {
  
    public static void main(String[]args)
    {
      
        String [] month = new String []{"Januray","February","March","April","May"
                ,"June","July","August","September","October","November","December"};
      
      
      
        for(String year : month)
        {
            JOptionPane.showMessageDialog(null,"Month of " + year );
        }      
    }
}

Exercise no. 14

import javax.swing.JOptionPane;
public class Exercise14 {
  
    public static void main(String [] args)
    {
  
    String squares;
  
    squares=JOptionPane.showInputDialog(null,"Enter the number");
  
    int s=Integer.parseInt(squares);
  
    int a=0,x=0;
    for ( ;x<=s;x++)
    {  
        Math.pow(x,2);
      
    }
    JOptionPane.showMessageDialog(null,"The sum of Square  is : " + Math.pow(x,2));
}
}

Exercise no. 13

 import javax.swing.JOptionPane;


public class Exercise13 {
 
    public static void main(String[]args)
    {
        int s=0,f=0;
        int d=1;

String userstring = JOptionPane.showInputDialog(null,"Enter number");

int userint = Integer.parseInt(userstring);


do{
  
 if(d%2==1)

 {
     s++;
 }

  if(s<=userint)
    
               {
        f+=s;
     
               }
  d=d+1;
}
while(s!=userint);

JOptionPane.showMessageDialog(null,"The sum of first is " + userstring + " and positive odd integer is : " + f);

    }

    }

Tuesday, August 6, 2013

Exercise No. 10

import java.util.Scanner;


public class Prime {

  
    public static void main(String[] args) {
      
      

    Scanner s = new Scanner(System.in);
  
    int x, y =2;
    String value;
    System.out.print("Enter A Number: ");
    x = s.nextInt();
  
    while (x != 0){
       
        if (y<x){
        if(x%y==0){
           
            value= "Is Not A Prime";
            System.out.print(value);
            break;}
       
        else{
           
             y++;
             continue;}
             }
             else{
             value = "Is A Prime";
             System.out.print(value);
             break;}
           
     }

     }

}
       
           
        
       
      
       
      

Saturday, August 3, 2013

Exercise no. 4

import java.util.*;
public class MileAge {

    public static void main(String[] args) {
        Scanner x= new Scanner(System.in);
      
        double milesdriven,gallonsused,milespergallon;
      
        System.out.println("Enter Miles Driven: ");
        milesdriven=x.nextDouble();
       
        System.out.println("Enter Gallons Used: ");
        gallonsused=x.nextDouble();
       
        milespergallon=milesdriven/gallonsused;
        System.out.println("The Miles Per Gallon Is: "+milespergallon);
              
      
    }

}

Exercise no. 3

import java.util.*;
public class Pay {
  
    public static void main(String[] args) {  
        Scanner x= new Scanner(System.in);
      
     
        double RPH;
    double HW;
    double Absences;
    double Late;
    double Gross;
    double TD;
    double NI;


        final double SSS=175,PhilHealth=300;
     
        System.out.println("Enter RatePerHour: ");
        RPH=x.nextDouble();
      
        System.out.println("Enter HoursWorked: ");
        HW=x.nextDouble();
      
        System.out.println("Enter absences: ");
        Absences=x.nextDouble();
        Absences=Absences*5.75;
      
        System.out.println("Enter Late: ");
        Late=x.nextDouble();
        Late=Late*3.25;
        Gross=RPH*HW;
      
        System.out.println("The Gross is: "+Gross);
        TD=Absences+Late+SSS+PhilHealth;
      
        System.out.println("The Total Deduction is: "+TD);
        NI=Gross-TD;
      
        System.out.println("The Total Net Income is: "+NI);
     
     
     
    }

}


   

Friday, August 2, 2013

Main Menu

What is a Professional?

Exercise no. 1

Exercise no. 2

Exercise no. 3

Exercise no. 4

Exercise no. 5

Exercise no. 6

Exercise no. 7

Exercise no. 8

Exercise no. 9

Exercise No. 10

Exercise no. 11

Exercise no. 12

Exercise no. 13

Exercise no. 14

Exercise no. 16

Exercise no. 17

Exercise no. 18

Exercise no. 19

Exercise no.20

Exercise no. 21

Exercise no. 22

Exercise no. 23

Exercise no. 24

Exercise no. 25

Exercise no. 26

Exercise no.27

Exercise no. 28










Exercise no. 38

Exercise no. 39

Exercise no. 40


Exercise no. 42














Exercise 16

import java.io.*;
public class Reverse {

   
    public static void main(String[] args)throws Exception
    {
        BufferedReader fb=new BufferedReader(new InputStreamReader(System.in));
        System.out.print("enter string");
        String name=fb.readLine();
      
        String reverse=new StringBuffer(name).reverse().toString();
      
        System.out.print("the reverse string is:"+reverse);

    }

}

Exercise 12

Class Name CharacterorString

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

import javax.swing.JOptionPane;

public class CharacterorString{
public static void main(String[] Theory)
{
    String SentenceContents=JOptionPane.showInputDialog("Enter a string:" );


    int VowelCount = 0,ConsonantCount = 0,WordCount = 0,SpaceCount = 0,SpecialCharCount = 0 ;

    for (int Bat = 0; Bat < SentenceContents.length(); Bat++)
    {
        char Vowels = SentenceContents.charAt(Bat );
        if ( (Vowels == 'A') || (Vowels == 'a' )
        || (Vowels == 'E') || (Vowels == 'e' )
        || (Vowels == 'I') || (Vowels == 'i' )
        || (Vowels == 'O') || (Vowels == 'o' )
        || (Vowels == 'U') || (Vowels == 'u' ))
        VowelCount++;

        char Consonants = SentenceContents.charAt(Bat);
        if ( (Consonants == 'B') || (Consonants == 'b')
        || (Consonants == 'C') || (Consonants == 'c')
        || (Consonants == 'D') || (Consonants == 'd')
        || (Consonants == 'F') || (Consonants == 'f')
        || (Consonants == 'G') || (Consonants == 'g')
        || (Consonants == 'H') || (Consonants == 'h')
        || (Consonants == 'J') || (Consonants == 'j')
        || (Consonants == 'K') || (Consonants == 'k')
        || (Consonants == 'L') || (Consonants == 'l')
        || (Consonants == 'M') || (Consonants == 'm')
        || (Consonants == 'N') || (Consonants == 'n')
        || (Consonants == 'P') || (Consonants == 'p')
        || (Consonants == 'Q') || (Consonants == 'q')
        || (Consonants == 'R') || (Consonants == 'r')
        || (Consonants == 'S') || (Consonants == 's')
        || (Consonants == 'T') || (Consonants == 't')
        || (Consonants == 'V') || (Consonants == 'v')
        || (Consonants == 'W') || (Consonants == 'w')
        || (Consonants == 'X') || (Consonants == 'x')
        || (Consonants == 'Y') || (Consonants == 'y')
        || (Consonants == 'Z') || (Consonants == 'z') )

        ConsonantCount++;

        char Spaces = SentenceContents.charAt(Bat);
        if ( (Spaces == ' ') )

        SpaceCount++;

        char SpecialCharacters = SentenceContents.charAt(Bat);
        if ( (SpecialCharacters == '!') || (SpecialCharacters == '@' )
        || (SpecialCharacters == '#') || (SpecialCharacters == '$' )
        || (SpecialCharacters == '%') || (SpecialCharacters == '^' )
        || (SpecialCharacters == '&') || (SpecialCharacters == '*' )
        || (SpecialCharacters == '(') || (SpecialCharacters == ')' )
        || (SpecialCharacters == '-') || (SpecialCharacters == '_' )
        || (SpecialCharacters == '+') || (SpecialCharacters == '=' )
        || (SpecialCharacters == ',') || (SpecialCharacters == '<' )
        || (SpecialCharacters == '.') || (SpecialCharacters == '>' )
        || (SpecialCharacters == '?') || (SpecialCharacters == '/' )
        || (SpecialCharacters == '"') || (SpecialCharacters == ';' )
        || (SpecialCharacters == ':') || (SpecialCharacters == '{' )
        || (SpecialCharacters == '[') || (SpecialCharacters == '}' )
        || (SpecialCharacters == ']') || (SpecialCharacters == '~' )
        || (SpecialCharacters == '`') || ((SpecialCharacters == '1' )
        || (SpecialCharacters == '2') || (SpecialCharacters == '3' )
        || (SpecialCharacters == '4') || (SpecialCharacters == '5' )
        || (SpecialCharacters == '6') || (SpecialCharacters == '7' )
        || (SpecialCharacters == '8') || (SpecialCharacters == '9' )
        || (SpecialCharacters == '|') ))

        SpecialCharCount++;
        String done="";
        char Terminate = SentenceContents.charAt(Bat);
        if (Terminate == 'd')
        JOptionPane.showMessageDialog(null,"the System is terminating");
        if ( SentenceContents != null)
   
    {
    }
    }
    JOptionPane.showMessageDialog(null,
                             "There are " + VowelCount + " vowels in this sentence\n"+
                             "There are " + ConsonantCount + " consonants in this sentence\n"+
                             "There are " + SpaceCount + " spaces in this sentence\n" +
                             "There are " + SpecialCharCount + " special characters in this sentence" );


    }

    }

Exercise 11

Class Name MonthBalance

import javax.swing.JOptionPane;
public class MonthBalance {

   
    public static void main(String[] args) {
        String choice="element";
        String Menu="\nd-Deposit \nw-Withdrawal \ne-Exit";
        
           String Choice="element";
        double balance = 0,d=0;
        double yearlyRate=0.025,w=0;
      
  

  
   do{
       choice=JOptionPane.showInputDialog(Menu+"\n Enter Choice:");
       choice=choice.toLowerCase();
      
       switch(choice.charAt(0) ){
      
       case 'd':
         
     JOptionPane.showMessageDialog(null,"Beginning of Month Balance:" + balance);
    balance=Double.parseDouble(JOptionPane.showInputDialog("enter Deposit"));
     JOptionPane.showMessageDialog(null,"Beginning of Month Balance:" + balance);
   
     break;
    
       case 'w':
         
       JOptionPane.showMessageDialog(null,"Beginning of Month Balance:"+balance);
       w=Double.parseDouble(JOptionPane.showInputDialog("Enter withdrawal amount:"));
       balance = balance+(yearlyRate / 12) * balance;
       JOptionPane.showMessageDialog(null,"Balance after transaction:"+ (balance=balance-w));
     
       break;
      
       case 'e': System.exit(0);
      
       break;
      
       default:JOptionPane.showMessageDialog(null,"Access Denied!");
       }
       }while(choice.charAt(0)!=('e'));
       }
  

    }

NameValidation

import java.util.Scanner;
public class NameValidation {
   
    public static void main(String[] args) {
      
        Scanner s= new Scanner(System.in);
        String word;
        int lastletter;
      
        do{
            System.out.print("Enter a word: ");
            word = s.next();
            lastletter = word.length()-1;
            if (word.equals("exit")){
            System.out.println("Program is now terminating…");
            break;
            }
            else if (word.charAt(lastletter)==word.charAt(0))
            System.out.println("The first character is EQUAL to its last character: "+word);
            else
            System.out.println("The first character is NOT EQUAL to its last character: "+word);

            }
            while (word != null);

            }

            }

TableOfSquares.

public class TableOfSquares {

    public static void main(String[] args) {
       
        //for loop
       
        System.out.println("----- Using for loop -----");
        for(int a=1; a<=20;a++)
        {
            System.out.println();
            System.out.print("Number: " + a + "\tSquare: " + (a*a) );
        };
        System.out.println(" " + "\n" + "\n");
       
       
        //WHILE LOOP
        int x=1;
        System.out.println("----- Using while loop -----");
        while(x<=20)
        {
            System.out.println();
            System.out.print("Number: " + x + "\tSquare: " + (x*x) );
            x++;
        };
        System.out.println(" " + "\n" + "\n");
       
       
       
        //DO..WHILE LOOP
        int a=1;
        System.out.println("----- Using do..while loop -----");
        do{System.out.println();
        System.out.print("Number: " + a + "\tSquare: " + (a*a) );
        a++;}

        while (a<=20);
       
       
       
       

    }

}

Sumof50

public class Sumof50 {

    public static void main(String[] args) {
      
        int sum = 0;
      
        for (int i=1; i<=50; i++)
        {      
            sum = i+sum;
          
        };
      
      
        System.out.println("Sum numbers from 1-50: " + sum);

    }

}

EvenNum.

public class EvenNum {

    public static void main(String[] args)
    {
       
       
        //FOR LOOP
        System.out.println("------------ using for loop ------------");
        for (int a=2; a<=50; a++)
        {
            System.out.print(a+" ");       
            a=a+1;
        };
       
       
        //WHILE LOOP
        System.out.println(" ");
        System.out.println("------------ using while loop ------------");
        int a = 2;
        while(a<=50)
        {
            System.out.print(a+" ");
            a=a+2;
        };
       
       
        //DO..WHILE LOOP
        System.out.println(" ");
        System.out.println("------------ using do...while loop ------------");
       
        int x = 2;
        do
        {
            System.out.print(x+" ");
            x=x+2;
        }
        while(x<=50);
       

    }

}

Quadratic

import java.util.*;
public class Quadratic {
   
    public static void main(String[] args) {
       
        Scanner console = new Scanner (System.in);

        double a , b , c , d , r , rr, sq ;

        System.out.println("Please enter the value of a:");
        a = console.nextDouble();

        System.out.println("Please enter the value of b:");
        b = console.nextDouble();

        System.out.println("Please enter the value of c:");
        c = console.nextDouble();

        d = ((b * 2) - 4) * (a * c);
        r = -b / (2 * a);
        rr=(-b+d) / (2*a);
        System.out.println("The Quadratic answer is: " + d);

        if ( d < 0){
        System.out.println("No root available");}

        else if ( d == 0){
        System.out.println("Roots are equal");
        System.out.println("The answer for the roots is: " + r);}

        else if (d > 0){

        System.out.println("The Displayed answer is:" + rr );}

        else
        System.out.println("Invalid");
        System.exit(0);


        }

        }
   

Class CurrencyConverter

import java.util.*;
public class CurrencyConverter {

   
   
    public static void main(String[] args) {
        double USD=43.75, GBP=78.98, EUR=56.45, JPY=0.867;
        double USDmoney=0,GBPmoney=0,EURmoney=0,JPYmoney=0;
        int Pmoney;
        Scanner in = new Scanner(System.in); 
       
        System.out.println("Enter currency:");
        Pmoney = in.nextInt();
       
       
        USDmoney = Pmoney* USD;
        GBPmoney = Pmoney * GBP;
        EURmoney = Pmoney * EUR;
        JPYmoney = Pmoney* JPY;
       
       System.out.println("Peso to USD:" + USDmoney + "\n Peso to GBP:" + GBP + "\nPeso to EUR:" +
       EURmoney + "\n Peso to JPY:" + JPYmoney);
    }

}