You are on page 1of 5

Lab Practical

import java.util.Scanner;
public class Ex01
{
public static void main(String[] args)

Scanner sc = new Scanner(System.in);


System.out.print("Enter your age: ");

int age = sc.nextInt();

if (age > 18) System.out.println("You are eligible to vote.");

import java.util.Scanner;
class IfExample01
{

public static void main(String[] args)


{

Scanner sc = new Scanner(System.in);

System.out.print("Enter your name: ");


String name = sc.nextLine();

System.out.print("Enter your age: ");

int age = sc.nextInt();

if(age>18)
{

System.out.println("Hello, " + name +", you are eligible to vote!");


}
}

import java.util.Scanner;
class IfExample02

MIT 12043, S. Sabraz Nawaz Page 1


Lab Practical

public static void main(String[] args)


{
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name: ");

String name = sc.nextLine();

System.out.print("Enter your age: ");

int age = sc.nextInt();

if(age>18)
{

System.out.println("Hello, " + name +", you are eligible to vote!");

}
}
}

import java.util.Scanner;
public class IfExample03

{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

System.out.print("Enter your name: ");

String name = sc.nextLine();

System.out.print("Enter your age: ");


int age = sc.nextInt();

if(age>18)
{
System.out.println("Hello, " + name +", you are eligible to vote!");

}
else

{
System.out.println("Hello, " + name +", you are not eligible to vote!");

MIT 12043, S. Sabraz Nawaz Page 2


Lab Practical

import java.util.Scanner;
class IfSalaryExercise
{

public static void main(String[] args)


{

double basicSalary = 0.0, dearnessAllowance = 0.0, houseRentAllowance = 0.0,

totalSalary = 0.0, incomeTax = 0.0, netSalary = 0.0;

Scanner sc = new Scanner(System.in);


System.out.print("Enter Basic Salary: ");

basicSalary = sc.nextDouble();

if(basicSalary > 30000)


{
dearnessAllowance = basicSalary * .4;

else
{
dearnessAllowance = basicSalary * .5;
}

if(basicSalary > 25000)

houseRentAllowance = basicSalary * .2;


}
else

{
houseRentAllowance = 3000.0;
}

totalSalary = basicSalary + dearnessAllowance + houseRentAllowance;

if(totalSalary > 50000)

MIT 12043, S. Sabraz Nawaz Page 3


Lab Practical

incomeTax = totalSalary * .12;


}

netSalary = totalSalary - incomeTax;

System.out.println("===============================================");

System.out.println("Dearness Allowance is: "+ dearnessAllowance);


System.out.println("House Rent Allowance is: "+ houseRentAllowance);

System.out.println("Total Salary is: "+ totalSalary);


System.out.println("Income Tax is: "+ incomeTax);
System.out.println("Net Salary is: "+ netSalary);
}

import java.util.Scanner;

public class LoanQualifier


{

public static void main(String[] args)


{

double salary;
double yearsOnJob;
Scanner sc = new Scanner(System.in);

System.out.print("Enter your annual salary: ");


salary = sc.nextDouble();

System.out.println(); //To create a blank line

System.out.print("Enter the number of years at your current job: ");


yearsOnJob = sc.nextDouble();

System.out.println(); //To create a blank line

if (salary >= 30000)


{

if (yearsOnJob >= 2)
{

System.out.print("You qualify for the loan!!!");

MIT 12043, S. Sabraz Nawaz Page 4


Lab Practical

}
else
{
System.out.print("Sorry, at least two years in current job is needed!");

}
else

System.out.print("Sorry, you must earn at least Rs.30,000 per year to


qualify.");
}

MIT 12043, S. Sabraz Nawaz Page 5

You might also like