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

}

Degree Converter

1.Class Name: DegreeConverter.

import java.util.*;

class DegreeConverter {
  public static void main(String[] args) {
    float temperature;
    double c,f;
   
    Scanner in = new Scanner(System.in);     

    System.out.println("Enter temperatue in Fahrenheit");
    f = in.nextDouble();

   c = ( f-32)/1.8;

    System.out.println("Temperature in Celsius = " + c);
  }
}