Huwebes, Disyembre 1, 2011

How to run on your Computer??

 Note: Make sure you have a Java bin.

Using netbeans Application:
1) Open netbeans IDE and create Java Application

2)Just Type the Code and press F6 to run.


 Using command promp window:
Just type the following
1. cd\
2. cd Program Files
3. cd java 
4.dir  (Look for your JDK Version)
5.Type the JDK version looks like this cd jdk1.6.0_22  (It depends on your JDK version)
6. cd bin
7. edit filename.java
You'd be directed to edit window.

How to run
1. Alt F-S
2. Alt F-X
3. javac filename.java
4. java filename
How to edit
1. edit filename.java

Martes, Nobyembre 29, 2011

Create a java program using BufferedReader that can compute the total quizes assumming that the inputed number specifies the user Input.

import java.io.*;
public class Main
{
    public static void main(String[] args) throws IOException
    {
BufferReader in = new Bufferedreader(new InputStreamReader(System.in));
      System.out.print("how many quizzes do you want to compute?");
int x = Integer.parseInt(in.readLine());
       int y = 0;
       Integer[] grades = new Integer[x];
       int z=1;
       int total=0;
      
       for (y=0;y<=x-1;y++)
       {
           System.out.print(""Quiz" +z +" " +":"")
            grades[y]= Integer.parseInt(in.readLine());
            total = total + grades[y];
            z++;
       }
       double ave = total/x;
      System.out.print("average is"+" " +ave);
    }
}

Create a simple Log-in program using BufferedReader specify the Username and Password will determine that you are log-on to the System

import java.io.*;

public class login{
String user,pass;
public static void main(String[] args)throws IOException{
BufferReader in = new Bufferedreader(new InputStreamReader(System.in));
System.out.print("Usename: ");
user=in.reaLine();
System.out.print("Password: ");
pass=in.reaLine();
if(user.equals("Java") && pass.equals("Jedi"))
{
System.out.print("log in OK");
}
else
{
System.out.print("ERROR!");
}
 }
}

A mail order house sales 5 product whose retail price as follows:PRODUCT1: $2.98, PRODUCT2: $4.50, PRODUCT3: $9.98,PRODUCT4: $4.49, & PRODUCT5: $6.87, Write an application that reads a series of pair of numbers as Follows: A) Product number B) Quantity Sold ..... The program should use a switch statement, determine the retail price for each product. it should calculate and display the total retail value of all product sold.

import java.io.*;
public class sample4 {

 
    public static void main(String[] args)throws IOException {
         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
         double product1 = 2.98,product2=4.50,product3=9.98,product4=4.49,product5=6.87;
         int hold,value;


         double total;
         System.out.print("Choices of Product! \n[1]Product1 \n[2]Product2 \n[3]Product3 \n[4]Product4 \n[5]Product5 \nChoose Product : ");
         hold=Integer.parseInt(in.readLine());
         switch(hold){
             case 1:
                 System.out.println("Quantity you want?: ");
                value =   Integer.parseInt(in.readLine());
                total=product1*value;
                 System.out.println("Product number 1:");
                 System.out.println("Quantity sold: "+value);
                 System.out.print("Amount to be paid: "+total+"$");
                 break;
             case 2:
                 System.out.println("Quantity you want?: ");
                value =   Integer.parseInt(in.readLine());
                 total=product2*value;
                 System.out.println("Product number 2:");
                 System.out.println("Quantity sold: "+value);
                 System.out.print("Amount to be paid: "+total+"$");
                 break;
             case 3:
                 System.out.println("Quantity you want?: ");
                value =   Integer.parseInt(in.readLine());
                 total=product3*value;
                 System.out.println("Product number 3:");
                 System.out.println("Quantity sold: "+value);
                 System.out.print("Amount to be paid: "+total+"$");
                 break;

              case 4:
                 System.out.println("Quantity you want?: ");
                value =   Integer.parseInt(in.readLine());
                 total=product4*value;
                 System.out.println("Product number 4:");
                 System.out.println("Quantity sold: "+value);
                 System.out.print("Amount to be paid: "+total+"$");
                 break;

            case 5:
                 System.out.println("Quantity you want?: ");
                value =   Integer.parseInt(in.readLine());
                 total=product5*value;
                 System.out.println("Product number 5:");
                 System.out.println("Quantity sold: "+value);
                 System.out.print("Amount to be paid: "+total+"$");
                 break;            }
    }

}

Write a java program that calculate the product of the odd integers from 1 to 20

import java.io.*;
public class sample2 {


    public static void main(String[] args)throws IOException {
       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

       int total=1;
       for(int x=3;x<=20;x+=2){
           total=total*x;
           
       }
        System.out.print("Product of odd integers is: "+total);
    }

}

Write an application that finds the smallest of several integers. Assumes that the first value specifies the number of values inputed from the user.

 import java.io.*;
public class sample1 {
    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

      int smallest = 0, value = 0, val;
String input;
        System.out.print("How many Integers you want to Input:?");
        val = Integer.parseInt(in.readLine());

for ( int x = 1; x <= val; x++ ) {
    System.out.print("Enter Integer no"+x+" : ");
    value = Integer.parseInt(in.readLine());

    if ( x == 1 )
smallest = value;
else if ( value < smallest )
smallest = value;
}
        System.out.println("Smallest Integer is: "+smallest);
}
}

Write a Java application that calculate a payroll of an employee.Assumes that following must be indicated : Rate at Php108.33, Deduction: SSS=5.72% Pgibig=7.5% Philhealth=8.2% If No of hours work inputed is greaterthan 40 Overtime pay must be 15times of Rate per hours would be computed and if its less than 40 the program will be INVALID

import java.io.*;
public class payroll {
  
    public static void main(String[] args) throws IOException{
  BufferedReader num= new BufferedReader(new InputStreamReader(System.in));

     System.out.print("Enter Name: ");
    String name = num.readLine();
     System.out.print("No. of hours worked: ");
     int hw= Integer.parseInt(num.readLine());
     if(hw==40){
    double rate = 108.33;
    double net = rate*40;
     double sss = net*.0572;
     double ph= net*.082;
     double pi = net*.075;
     double tax= net*.12;
     double tded = sss+ph+pi+tax;
     double netpay = net-tded;
         System.out.println("Employee name: "+name);
         System.out.println("No of hours work: "+hw);
         System.out.println("Net Income: "+net);
         System.out.println("SSS: "+sss);
         System.out.println("ph: "+ph);
         System.out.println("pi: "+pi);
         System.out.println("tax: "+tax);
            System.out.println("Total Deduction: "+tded);
            System.out.println("Net Pay: "+netpay);

     }
 else if(hw > 40) {
        double othours = hw - 40;
        double otfee = (othours*1.5)*108.33;
        double rate = 108.33;
        double anet = rate*40;
        double net= anet+otfee;
        double sss = net*.0572;
     double ph= net*.082;
     double pi = net*.075;
     double tax= net*.12;
     double tded = sss+ph+pi+tax;
     double netpay =net-tded;
      System.out.println("Employee name: "+name);
         System.out.println("No of hours work: "+hw);
         System.out.println("Net Income: "+net);
         System.out.println("Overtime hours: "+othours);
         System.out.println("Overtime Fee's: "+otfee);
         System.out.println("Total Deduction: "+tded);
         System.out.println("Net Pay: "+netpay);

     }
 else if(hw < 40){
         System.out.println("Employee name: "+name);
         System.out.println("No of Hours Work: "+hw);
         System.out.println("Invalid hours ");
         
     }
    }