Showing posts with label Java Programs. Show all posts
Showing posts with label Java Programs. Show all posts

Tuesday, 20 September 2016

Switch Statement Example in Java Swing Package

import javax.swing.JOptionPane;
    class Switch{
        public static void main(String[]args) throws Exception{
            String input = JOptionPane.showInputDialog("Enter");
            int percentage = Integer.parseInt(input);
        switch(percentage){
            case 90:
                JOptionPane.showMessageDialog(null, "A+ Grade");
                    break;
            case 80:
                JOptionPane.showMessageDialog(null, "A Grade");
                    break;
            case 70:
                JOptionPane.showMessageDialog(null, "B Grade");
                    break;
            case 60:
                JOptionPane.showMessageDialog(null, "C Grade");
                    break;
            case 50:
                JOptionPane.showMessageDialog(null, "D Grade");
                    break;
            case 40:
                JOptionPane.showMessageDialog(null, "IMPROVED");
                    break;
            default:
                JOptionPane.showMessageDialog(null, "Fail");
               
        }
        }
    }

Marksheet In Else-If Statement Java Program Swing Package

import javax.swing.JOptionPane;
    class IfElseMarksheet{
        public static void main(String[]args) throws Exception{
            String a = JOptionPane.showInputDialog("Enter Java Marks");
            int java = Integer.parseInt(a);
            String b = JOptionPane.showInputDialog("Enter PHP Marks");
            int php = Integer.parseInt(b);
            String c = JOptionPane.showInputDialog("Enter VB Marks");
            int vb = Integer.parseInt(c);
            String d = JOptionPane.showInputDialog("Enter C++ Marks");
            int cpp = Integer.parseInt(d);
            String e = JOptionPane.showInputDialog("Enter Ruby Marks");
            int ruby = Integer.parseInt(e);
           
            int total = 500;
            int obtained = java + php + cpp + vb + ruby;
            int percentage = obtained * 100 / total;
           
            if(java >39){
                if(php > 39)
                if(vb >  39)
                if(cpp > 39)
                if(ruby > 39)
                if(percentage < 100)
                if(percentage >= 80)
               
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Pass" + "\n You Got A+ Grade");
}
       
           else if(java >39){
                if(php > 39)
                if(vb >  39)
                if(cpp > 39)
                if(ruby > 39)
                if(percentage <  80)
                if(percentage >= 70)
               
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
             
                              "\n You Are Pass" + "\n You Got A Grade");
}
           
           else if(java >39){
                if(php > 39)
                if(vb >  39)
                if(cpp > 39)
                if(ruby > 39)
                if(percentage <  70)
                if(percentage >= 60)              
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Pass" + "\n You Got B Grade");
}
           
           else if(java >39){
                if(php > 39)
                if(vb >  39)
                if(cpp > 39)
                if(ruby > 39)
                if(percentage <  60)
                if(percentage >= 50)              
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Pass" + "\n You Got C Grade");
}
           
           else if(java >39){
                if(php > 39)
                if(vb >  39)
                if(cpp > 39)
                if(ruby > 39)
                if(percentage <  50)
                if(percentage >= 40)              
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Pass" + "\n You Got D Grade");
}

            else{
                JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Fail");
}

        }
    }

Wednesday, 7 September 2016

Operator Selector Calculator Java Program

Operator Based Calculator Using Swing Package



import javax.swing.JOptionPane;
    class OperatorCalc{
        public static void main(String[]args){
            String operator = JOptionPane.showInputDialog("Enter any Operator" );
            String op = operator;
           
            String v1 = JOptionPane.showInputDialog("Enter First Value" );
            int value1 = Integer.parseInt(v1);
           
            String v2 = JOptionPane.showInputDialog("Enter Second Value" );
            int value2 = Integer.parseInt(v2);

   
    if (!(op == "+" || op == "-" || op == "*" || op == "/" || op == "%" ))
        JOptionPane.showMessageDialog(null, " Enter a valid Operator");
           
           
    if( op == "+" )
        JOptionPane.showMessageDialog(null, " Addition is " + (value1 + value2) );
           
    if( op == "-" )
        JOptionPane.showMessageDialog(null, " Subtraction " + (value1 - value2) );
           
    if( op == "*" )
        JOptionPane.showMessageDialog(null, " Multiplication is " + (value1 * value2) );
           
    if( op == "/" )
        JOptionPane.showMessageDialog(null, " Division is " + (value1 / value2) );
           
    if( op == "%" )
        JOptionPane.showMessageDialog(null, " Reminder is " + (value1 % value2) );
           
        }
    }

Menu Based Calculator Java Program

GUI Based Menu Calculator Using Swing Package



import javax.swing.JOptionPane;
    class MenuCalc{
        public static void main(String[]args) throws Exception{
            String select = JOptionPane.showInputDialog( "Enter Number 1-5" +
                                                        "\n 1 == Addition " +
                                                        "\n 2 == Subtraction " +
                                                        "\n 3 == Multiplication " +
                                                        "\n 4 == Division " +
                                                       "\n 5 == Reminder ");
            int Menu = Integer.parseInt(select);

            String v1 = JOptionPane.showInputDialog( "Enter First Value ");
            int value1 = Integer.parseInt(v1);
           
            String v2 = JOptionPane.showInputDialog( "Enter Second Value ");
            int value2 = Integer.parseInt(v2);
           
            if(Menu == 1)
            JOptionPane.showMessageDialog(null, value1 + value2);
       
            if(Menu == 2)
            JOptionPane.showMessageDialog(null, value1 - value2);

            if(Menu == 3)
            JOptionPane.showMessageDialog(null, value1 * value2);
       
            if(Menu == 4)
            JOptionPane.showMessageDialog(null, value1 / value2);

            if(Menu == 5)
            JOptionPane.showMessageDialog(null, value1 % value2);
       
            if(!( Menu == 1 || Menu == 2 || Menu == 3 || Menu == 4 || Menu == 5))
            JOptionPane.showMessageDialog(null, " Enter Valid Menu ");
       
        }
    }

Billing System Java Program

Java Program Billing System According to Units Using `util` Package


import java.util.Scanner;
    class HESCOBill{
        public static void main(String[]args) throws Exception{
            Scanner s = new Scanner(System.in);
            System.out.print(" Enter Units ");
                String bill = s.nextLine();
                int units = Integer.parseInt(bill);
            if( units >= 1 && units <=100 )
                System.out.print("Your bill is " + units * 2 );
            if( units > 100 && units <=200 )
                System.out.print("Your bill is " + units * 4 );
            if( units > 200 && units <= 300 )
                System.out.print("Your bill is " + units * 6 );
            if( units > 300 && units <= 400 )
                System.out.print("Your bill is " + units * 8 );
            if( units > 400 )
                System.out.print("Your bill is " + units * 10 );
        }
    }

Thursday, 1 September 2016

Java Program (Age Comparison)

THREE AGE COMPARISON IN SWING PACKAGE


import javax.swing.JOptionPane;
    class Three_Age{
        public static void main(String[]args) throws Exception{
            String text = JOptionPane.showInputDialog("Enter First Age");
            int Age1 = Integer.parseInt(text);

            String text2 = JOptionPane.showInputDialog("Enter First Age");
            int Age2 = Integer.parseInt(text2);

            String text3 = JOptionPane.showInputDialog("Enter First Age");
            int Age3 = Integer.parseInt(text3);
    
        if( Age1 > Age2 && Age1 > Age3 )
            JOptionPane.showMessageDialog( null, Age1 + " is Greater" );
        if( Age2 > Age1 && Age2 > Age3 )
            JOptionPane.showMessageDialog( null, Age2 + " is Greater" );
        if( Age3 > Age1 && Age3 > Age2 )
            JOptionPane.showMessageDialog(null, Age3 + " is Greater" );
        if ( Age1 < Age2 && Age1 < Age3 )
            JOptionPane.showMessageDialog( null, Age1 + " is Smaller" );
        if( Age2 < Age1 && Age2 < Age3 )
            JOptionPane.showMessageDialog( null, Age2 + " is Smaller" );
        if( Age3 < Age1 && Age3 < Age2 )
            JOptionPane.showMessageDialog(null, Age3 + " is Smaller" );
        }
    }

Java Program (Complete Marksheet Using Swing)

COMPLETE MARKSHEET USING SWING PACKAGE


import javax.swing.JOptionPane;
    class swingMarksheet{
        public static void main(String[]args) throws Exception{
            String a = JOptionPane.showInputDialog("Enter Java Marks");
            int java = Integer.parseInt(a);
            String b = JOptionPane.showInputDialog("Enter PHP Marks");
            int php = Integer.parseInt(b);
            String c = JOptionPane.showInputDialog("Enter VB Marks");
            int vb = Integer.parseInt(c);
            String d = JOptionPane.showInputDialog("Enter C++ Marks");
            int cpp = Integer.parseInt(d);
            String e = JOptionPane.showInputDialog("Enter Ruby Marks");
            int ruby = Integer.parseInt(e);
           
            int total = 500;
            int obtained = java + php + cpp + vb + ruby;
            int percentage = obtained * 100 / total;
           
            if(java >39 && php >39 && vb >39 && cpp >39 && ruby >39 && (percentage <100 && percentage >=80))
               
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Pass" + "\n You Got A+ Grade");

            if(java >39 && php >39 && vb >39 && cpp >39 && ruby >39 && (percentage <80 && percentage >=70))
               
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Pass" + "\n You Got A Grade");

           
           if(java >39 && php >39 && vb >39 && cpp >39 && ruby >39 && (percentage <70 && percentage >=60))
               
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Pass" + "\n You Got B Grade");

           
           if(java >39 && php >39 && vb >39 && cpp >39 && ruby >39 && (percentage <60 && percentage >=50))
               
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Pass" + "\n You Got C Grade");

           
           if(java >39 && php >39 && vb >39 && cpp >39 && ruby >39 && (percentage <50 && percentage >=40))
               
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Pass" + "\n You Got D Grade");


            if(java <40 || php <40 || vb <40 || cpp <40 || ruby <40 || percentage < 40)
JOptionPane.showMessageDialog(null, "Total Marks Are :" + total +
                 "\n Obtained Marks Are : " + obtained +
                 "\n Percentage is : " + percentage +"%" +
                 "\n You Are Fail");
                                                 
        }
    }

Java Program (Find Out Greater and Smaller Age)

FIND OUT SMALLER AND LARGER AGE FROM TAKEN INPUT (SWING PACKAGE)


import javax.swing.JOptionPane;
    class FiveAge{
        public static void main(String[]args) throws Exception{
            String text = JOptionPane.showInputDialog("Enter First Age");
            int Age1 = Integer.parseInt(text);

            String text2 = JOptionPane.showInputDialog("Enter Second Age");
            int Age2 = Integer.parseInt(text2);

            String text3 = JOptionPane.showInputDialog("Enter Third Age");
            int Age3 = Integer.parseInt(text3);
   
            String text4 = JOptionPane.showInputDialog("Enter Fourth Age");
            int Age4 = Integer.parseInt(text4);
   
            String text5 = JOptionPane.showInputDialog("Enter Fifth Age");
            int Age5 = Integer.parseInt(text5);
   
            if( Age1 > Age2 && Age1 > Age3 && Age1 > Age4 && Age1 > Age5 )
            JOptionPane.showMessageDialog( null, Age1 + " is Greater" );
       
            if( Age2 > Age1 && Age2 > Age3 && Age2 > Age4 && Age2 > Age5 )
            JOptionPane.showMessageDialog( null, Age2 + " is Greater" );
       
            if( Age3 > Age1 && Age3 > Age2 && Age3 > Age4 && Age3 > Age5 )
            JOptionPane.showMessageDialog(null, Age3 + " is Greater" );
       
            if ( Age4 > Age1 && Age4 > Age2 && Age4 > Age3 && Age4 > Age5 )
            JOptionPane.showMessageDialog( null, Age4 + " is Greater" );
       
            if( Age5 > Age1 && Age5 > Age2 && Age5 > Age3 && Age5 > Age4 )
            JOptionPane.showMessageDialog( null, Age5 + " is Greater" );
   
            if( Age1 < Age2 && Age1 < Age3 && Age1 < Age4 && Age1 < Age5 )
            JOptionPane.showMessageDialog(null, Age1 + " is Smaller" );
       
            if( Age2 < Age1 && Age2 < Age3 && Age2 < Age4 && Age2 < Age5 )
            JOptionPane.showMessageDialog(null, Age2 + " is Smaller" );
       
            if( Age3 < Age1 && Age3 < Age2 && Age3 < Age4 && Age3 < Age5 )
            JOptionPane.showMessageDialog( null, Age3 + " is Smaller" );
       
            if( Age4 < Age1 && Age4 < Age2 && Age4 < Age3 && Age4 < Age5 )
            JOptionPane.showMessageDialog( null, Age4 + " is Smaller" );
       
            if( Age5 < Age1 && Age5 < Age2 && Age5 < Age3 && Age5 < Age4 )
            JOptionPane.showMessageDialog(null, Age5 + " is Smaller" );      
        }
    }

Saturday, 27 August 2016

Java Program

GUI (Swing) Based Even/Odd Number Recognition Java Program


import javax.swing.JOptionPane;
    class SwingEvenOdd{
        public static void main(String[]args) throws Exception{
            String season = JOptionPane.showInputDialog("Enter Number");
            int asd = Integer.parseInt(season);
        

  if(asd % 2 == 1)
                JOptionPane.showMessageDialog(null, "Number " + asd + " is odd");
  if(asd % 2 == 0)
                JOptionPane.showMessageDialog(null, "Number " + asd + " is even");                      
            
        }
    }

Java Program

GUI (Swing) Based Season Identifier Java Program


import javax.swing.JOptionPane;
    class SeasonIdentifier{
        public static void main(String[]args) throws Exception{
               String season = JOptionPane.showInputDialog("Enter season number");
            int asd = Integer.parseInt(season);
            

            if(asd == 1 || asd == 11 || asd == 12)
                JOptionPane.showMessageDialog(null, "The Number: " + asd + "\n Wellcome to WINTER season");
            if(asd == 2 || asd == 3 || asd == 4)
                JOptionPane.showMessageDialog(null, "The Number: " + asd + "\n Wellcome to SPRING season");
            if(asd == 5 || asd == 6 || asd == 7)
                JOptionPane.showMessageDialog(null, "The Number: " + asd + "\n Wellcome to SUMMER season");
            if(asd == 8 || asd == 9 || asd == 10)
                JOptionPane.showMessageDialog(null, "The Number: " + asd + "\n Wellcome to AUTUMN season");
            if(asd < 1 || asd > 12)
                JOptionPane.showMessageDialog(null, "Invalid Month Number");

        }
    }

Java Program

GUI Based Payroll System Java Program


import javax.swing.JOptionPane;
    class salary{
        public static void main(String[]args) throws Exception{
            
            String pay = JOptionPane.showInputDialog("Enter Basic Pay");
            int basicpay = Integer.parseInt(pay);
            
                    JOptionPane.showMessageDialog(null, "Basic Salary: " +  pay);
            
            int houserent = basicpay * 25 / 100;
            int conveyance = basicpay * 15 / 100;
            int medical = basicpay * 35 / 100;
            int governance = basicpay * 5 / 100;
            int total_salary = basicpay + houserent + conveyance + medical + governance;
            
            int tax = basicpay * 14 / 100;
            int zakat = basicpay * 25 / 100;
            int gross_pay = tax + zakat;
            
            int net_salary = total_salary - gross_pay;
                        
        JOptionPane.showMessageDialog(null, "ALLOUNCES " + 
                    "\n House rent 35% : " + houserent +
                    "\n Conveyance is 15% : " + conveyance +
                    "\n Medical Allounce 35% : " + medical + 
                    "\n Governance Allounce 5% : " + governance +
                    "\n Total Salary is : " + total_salary );
        
        JOptionPane.showMessageDialog(null, "DEDUCTIONS " + 
                    "\n Government Tax : " + tax + "\n Annual Zakat :"                                       + zakat + "\n Total Deductions " + gross_pay);

        JOptionPane.showMessageDialog(null, "Net Salary " + net_salary );
        }
    }

/*given * 100 divide total == percentage
    
    */

Java Program

GUI Based Currency Converter Java Program


import javax.swing.JOptionPane;
    class converter{
        public static void main(String[]args) throws Exception{
            String amount = JOptionPane.showInputDialog("Enter rupees");
            int asd = Integer.parseInt(amount);
        
        float us_dollor = asd / 104f;
        float aus_dollor = asd / 78f;
        float riyal = asd / 28f;
        float deenar = asd / 358f;
            JOptionPane.showMessageDialog(null, "Pakistani Rupees" + asd + 
                        "\n In US Dollors: " + us_dollor + 
                        "\n Australian Dollors : " + aus_dollor +
                        "\n Saudi Riyal : " + riyal +
                        "\n Deenar : " + deenar );
        }
    }

Saturday, 20 August 2016

Java Program

Marksheet Using GUI Based Input (SWING)


import javax.swing.JOptionPane;
    class SwingMarksheet{
        public static void main(String[]args) throws Exception{
            String a = JOptionPane.showInputDialog("Enter Java Marks");
            int java = Integer.parseInt(a);
            String s = JOptionPane.showInputDialog("Enter PHP Marks");
            int php = Integer.parseInt(s);
            String d = JOptionPane.showInputDialog("Enter VB Marks");
            int vb = Integer.parseInt(d);
            String f = JOptionPane.showInputDialog("Enter C++ Marks");
            int cpp = Integer.parseInt(f);
            String g = JOptionPane.showInputDialog("Enter Assembly Marks");
            int assembly = Integer.parseInt(g);
           
            int total = 500;
            int obtained = java + php + vb + cpp + assembly;
            int percentage = obtained*100/total;
        JOptionPane.showMessageDialog(null, " \n Obtained Marks Are : " + obtained
                                      + "\n Total Marks Are : " + total
                                      + " \n Percentage is : " + percentage + "%" );
           
        }
    }

Java Program

Operator Example Using GUI (Swing) Input And CLI (io) Input Both


import javax.swing.JOptionPane;
    class SwingAddition{
        public static void main(String[]args) throws Exception{
            String a = JOptionPane.showInputDialog("Enter Num1");
                int x = Integer.parseInt(a);
            String s = JOptionPane.showInputDialog("Enter Num2");
                int y = Integer.parseInt(s);
                int add = x + y;
                int mul = x * y;
                int div = x / y;
                int sub = x - y;
                int rem = x % y;
           
            JOptionPane.showMessageDialog(null, "Sum is : " + add);
            System.out.print(" \n Sum is: " + add);
            JOptionPane.showMessageDialog(null, "Multiplication is : " + mul);
            System.out.print(" \n Multiplication is: " + mul);
            JOptionPane.showMessageDialog(null, "Division is : " + div);
            System.out.print(" \n Division is: " + div);
            JOptionPane.showMessageDialog(null, "Subtraction is : " + sub);
            System.out.print(" \n Subtraction is: " + sub);
            JOptionPane.showMessageDialog(null, "Reminder is : " + rem);
            System.out.print("  \n Reminder is: " + rem);
        }
    }

Java Program

Operator Example by Taking Input From User


import java.io.DataInputStream;
    class Operator{
        public static void main(String[]args) throws Exception{
            DataInputStream ob = new DataInputStream(System.in);
                System.out.print("Enter First Number ");
                    String a = ob.readLine();
                    int r = Integer.parseInt(a);
                System.out.print("Enter Second Number ");
                    String b = ob.readLine();
                    int s = Integer.parseInt(b);
                    int sum = r + s;
                    int min = r - s;
                    int mul = r * s;
                    int div = r / s;
                    int rem = r % s;
                System.out.print(" Sum is " + sum + " \n subtract is " + min + 
                                 " \n multiplication is " + mul + " \n division is " + div + 
                                 " \n reminder is " + rem);
        }
    }
                

Java Program

Java Marksheet Using DataInputStream Class


import java.io.DataInputStream;
    class Marksheet{
        public static void main(String[]args) throws Exception{
            DataInputStream ob = new DataInputStream(System.in);
                System.out.print("Enter Java Marks ");
                    String one = ob.readLine();
                    int java = Integer.parseInt(one);
                System.out.print("Enter PHP Marks ");
                    String second = ob.readLine();
                    int php = Integer.parseInt(second);
                System.out.print("Enter VB.Net Marks ");
                    String third = ob.readLine();
                    int vb = Integer.parseInt(third);
                System.out.print("Enter C++ Marks ");
                    String fourth = ob.readLine();
                    int cpp = Integer.parseInt(fourth);
                System.out.print("Enter Assemby Marks ");
                    String fifth = ob.readLine();
                    int assembly = Integer.parseInt(fifth);
                    int total = 500;
                    int obtained =  java + php + vb + cpp + assembly;
                    int percentage = obtained * 100 / total;
                System.out.print(" Total Marks Are : " + total + "\n Your Obtained Marks Are: " + obtained +
                                "\n Your Percentage is: " + percentage + "%");
        }
    }

Java Program

Addition of Numbers Using io.DataInputStream


import java.io.DataInputStream;
    class Addition{
        public static void main(String[]args) throws Exception{
            DataInputStream ob = new DataInputStream(System.in);
        /*        we created the object of DIS class 
        
        */
            System.out.print("Enter First Number");
                String s = ob.readLine();
                int a = Integer.parseInt(s);
            /** we cnvert the string value into integer and save into a variable **/
            System.out.print("Enter second Number");
                String d = ob.readLine();
                int b = Integer.parseInt(d);
                int sum = a+b;
            System.out.println("Addition: " + sum);
        }
    }




/* line 6 and 7 can be written as
int b = Integer.parseInt(ob.readLine());
Assignments
        Perform All Airthematic operators
    Marksheet:
    Subject1 Marks
    Subject2 Marks
    Subject2 Marks
    Subject2 Marks
    Subject2 Marks as inputs
    gives output as 
    Total Marks
    Obtain Marks
    Percentage
    */