Pages

Total Pageviews

Thursday, June 6, 2019

Lab 4 Exercise Questions at Java Programming

import java.util.Scanner;

class Lab5Ex1
{
   public static void main(String[] args)
   {
      Scanner keyboard = new Scanner(System.in);
     
      System.out.print("Please enter grade between 1-100 : ");
      int grade = keyboard.nextInt();
     
      if(grade >= 90)
      {
         System.out.println("Grade is A");
      }
      else if(grade >= 80)
      {
         System.out.println("Grade is B");
      }
      else if(grade >= 70)
      {
         System.out.println("Grade is C");
      }
      else if(grade >= 60)
      {
         System.out.println("Grade is D");
      }
      else {
         System.out.println("Grade is F");
      }     
   }
}



import java.util.Scanner;

class Lab5Ex1_Switch
{
   public static void main(String[] args)
   {
      Scanner keyboard = new Scanner(System.in);
     
      System.out.print("Please enter grade between 1-100 : ");
      int grade = keyboard.nextInt();
     
     
      switch(grade/10)
      {
         case 10:
         case 9:
               System.out.println("Grade is A");
               break;
         case 8:
               System.out.println("Grade is B");
               break;
         case 7:
               System.out.println("Grade is C");
               break;
         case 6:
               System.out.println("Grade is D");
               break;
         default:
               System.out.println("Grade is F");
               break;

      }     
   }
}


import java.util.Scanner;

class Lab5Ex2
{
   public static void main(String[] args)
   {
      Scanner keyboard = new Scanner(System.in);
     
      System.out.print("Please enter year to check whether leap or not : ");
      int year = keyboard.nextInt();
      boolean isLeap = false;
      if(year % 4 == 0)
      {
         isLeap = true;     
      }
     
      if(isLeap && year % 100 == 0 && year % 400 != 0)
      {
         isLeap = false;
      }
     
      if(isLeap)
      {
         System.out.println("Year " + year + " is leap year.");
      }
      else
      {
         System.out.println("Year " + year + " is not a leap year.");
      }
   }
}

import java.util.Scanner;
import java.text.DecimalFormat;

class Lab5Ex3
{
   static final double HourlyWage = 7.25;
   static final double WeeklyWorkingHoursLimit = 40;
 
   public static void main(String[] args)
   {
      Scanner keyboard = new Scanner(System.in);
     
      System.out.print("Please enter number of hours worked : ");
      double hoursWorked = keyboard.nextDouble();   
     
      System.out.print("Please enter total sales : ");
      double totalSales = keyboard.nextDouble();   
     
      double totalSalary = 0;
     
      if(hoursWorked < WeeklyWorkingHoursLimit)
      {
         totalSalary += hoursWorked * HourlyWage;
      }
      else
      {
         totalSalary += WeeklyWorkingHoursLimit * HourlyWage;
         totalSalary += (hoursWorked - WeeklyWorkingHoursLimit) * HourlyWage * 1.5;
      }
     
      if(totalSales >= 1 && totalSales < 100)
      {
         totalSalary += totalSales * 0.05;
      }
      else if(totalSales >= 100 && totalSales < 300)
      {
         totalSalary += totalSales * 0.10;
      }
      else if(totalSales >= 300)
      {
         totalSalary += totalSales * 0.15;
      }
     
      DecimalFormat salesFormat = new DecimalFormat("0.00");
     
      System.out.println("Total salary calculated is $" + salesFormat.format(totalSalary));
     
   }
}



http://erdoganakbiyik.blogspot.com/
https://www.youtube.com/channel/UCDsUnmBfVdEPkcC8FlzPKcg

No comments:

Post a Comment