First Exam

First Exam - Print odd numbers. - Calculate the area of triangle. - Enter the employee names , salaries and print the average of their salaries.
 avatar
unknown
plain_text
2 years ago
5.3 kB
1
Indexable
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
 */
package javaapplication9;

import javax.swing.JOptionPane;

/**
 *
 * @author attasam
 */
public class JavaApplication9 {

    /**
     * @param args the command line arguments
     */
     public static void main(String[] args) {
        // TODO code application logic here
        
        int num;
        
        boolean continuo=true;
        
        
        
        
        
        while(continuo){
            String info="-------------------Welcome------------------- "
                    +" \n 1- Print odd numbers"
                    +" \n 2- Calculate the area of traingle"
                    +" \n 3- Enter the employee names , salaries and print the average of their salaries";
            num=Integer.parseInt(JOptionPane.showInputDialog(null,info));
            
                  switch(num){
            case 1:{
                int num1,num2;
                String nums="";
        do{
             num1=Integer.parseInt(JOptionPane.showInputDialog(null," Enter the First Number"));
             if(num1 <=0){
                  JOptionPane.showMessageDialog(null,"It must be above  0" );
             }
        }while(num1 <=0);
       
        do{
              num2=Integer.parseInt(JOptionPane.showInputDialog(null," Enter the Second Number"));
              if(num2<num1 && num2>0)
              {
                  JOptionPane.showMessageDialog(null,"The number "+num2+ "  must be bigger than first number "+num1 );
              }
              else if(  num2<= 0){
                   JOptionPane.showMessageDialog(null,"It must be above  0" );
              }
        }while( num2 <num1);
         
          
          
         
        for(int x=num1; x<=num2; x++ ){
            
            if(x%2!=0){
                nums+= x+" ";
            }
        }
        JOptionPane.showMessageDialog(null,"the odd numbers between "+num1 + " and "+num2 +" is : " + nums);
        int n=JOptionPane.showConfirmDialog(null, "Do you want to continue with the program ","Title",JOptionPane.YES_NO_OPTION);
        if(n!=0){
           continuo=!continuo;
        }
       
        
           break; }
            
            case 2:{
               int num1,num2;
                String nums="";
        do{
             num1=Integer.parseInt(JOptionPane.showInputDialog(null," Enter the base of traingle"));
             if(num1<=0){
                 JOptionPane.showMessageDialog(null,"It must be above  0" );
             }
        }while(num1 <=0);
       
        do{
              num2=Integer.parseInt(JOptionPane.showInputDialog(null," Enter the height of traingle"));
               if(num2<=0){
                 JOptionPane.showMessageDialog(null,"It must be above  0" );
             }
        }while( num2  <=0);
       double sum;
              sum  =0.5 * num1*num2;
              JOptionPane.showMessageDialog(null,"the area of traingle is : "+sum);
              int n=JOptionPane.showConfirmDialog(null, "Do you want to continue with the program ","Title",JOptionPane.YES_NO_OPTION);
        if(n!=0){
           continuo=!continuo;
        }
           break; }
            case 3:{
                int numsOfEmp;
                 do{
                     numsOfEmp=Integer.parseInt(JOptionPane.showInputDialog(null," Enter the numbers of emplyees"));
                
                 if(numsOfEmp<=0){
                 JOptionPane.showMessageDialog(null,"It must be above  0" );
             }
                }while(numsOfEmp <=0 );
                double sum=0.0,avg=0.0;
                String names[]=new String[numsOfEmp];
                double sal[]=new double[numsOfEmp];
                
                for(int i=0; i<names.length; i++){
                      names[i]=JOptionPane.showInputDialog(null," Enter the name "+ (i+1));
                    do{
                       
                    sal[i]=Integer.parseInt(JOptionPane.showInputDialog(null," Enter the salary for " + names[i]));
                    if(sal[i]<=0){
                        JOptionPane.showMessageDialog(null,"The salary for "+names[i]+"  must be above  0" );
                    }
                    }while(sal[i]<=0);
                   
                     sum +=sal[i];
                }
                avg=sum/numsOfEmp;
                JOptionPane.showMessageDialog(null,"The Total of salaries : "+sum+ "\nThe avarage is        : "+ avg);
                                                                        
                int n=JOptionPane.showConfirmDialog(null, "Do you want to continue with the program ","Title",JOptionPane.YES_NO_OPTION);
        if(n!=0){
           continuo=!continuo;
        }
            break;}
            default:{
                 JOptionPane.showMessageDialog(null,"Invaild number try again please");
            }
        }
            
        }
  JOptionPane.showMessageDialog(null,"Thank you see you later ");
        
    }
    
}

Editor is loading...