Fiza Oop 1
Fiza Oop 1
Karachi Campus
Submitted By:
Submitted To:
2 Write a JAVA program, which receives the input of two integer numbers, operation
(+,-,*,/,%, power, square-root and factorial) and compute arithmetic operations.
Generate a menu for operations and ask user after every operation if they want to
do another. (Hint use switch case)
3 Make a program in JAVA in which take no. of items, price of items and name of
items as input from the user and give the discount according to the following
conditions:
• If from Bahria University give discount of 30%.
• Else if the total amount is greater then 50,000 and less than 100,000 give
discount of 20%.
• Else if the total amount is greater then 100,000 give discount of 30%.
4 Write a JAVA program which will implement the following formulae using
methods.
Submitted On:
20/2/2024
(Date: DD/MM/YY)
16/02/2024 Object Oriented Programming
[Introduction To Java Programming Language]
LAB # 01
Task # 01:
Write a program that prints any pattern, similar to the following.
Solution:
package fiza.lab.pkg1;
System.out.println(" ( (");
System.out.println(" ) )");
System.out.println(" ................");
System.out.println("| |-");
System.out.println("|~~~~~~~~~~~~~~~| ]");
System.out.println(" \\-------------/ ]");
System.out.println(" \\-----------/ -");
System.out.println(" '---------'");
}
}
Output:
FIZA KHAN 1
16/02/2024 Object Oriented Programming
[Introduction To Java Programming Language]
Task # 02:
Write a JAVA program, which receives the input of two integer numbers,
operation (+,-,*,/,%, power, square-root and factorial) and compute arithmetic
operations. Generate a menu for operations and ask user after every operation
if they want to do another. (Hint use switch case)
Solution:
package fiza.lab.pkg1;
import java.util.Scanner;
public class FizaLab1 {
System.out.println(" '---------'");
Scanner input=new Scanner(System.in);
double num1,num2,res;
char ans1;
do{
System.out.println("_____MENU_____");
System.out.println("1) Addition \n2) Subtraction \n3)
Multiplication \n4) Division \n5) Modulus \n6) Power \n7) Square root
\n8) Factorial");
System.out.println("Which operation do you want to
perform?");
int ans=input.nextInt();
switch(ans){
case 1:
System.out.println("Enter 1st number:");
num1=input.nextDouble();
System.out.println("Enter 2nd number:");
num2=input.nextDouble();
res=num1+num2;
System.out.println("The sum of two numbers is
"+res);
break;
case 2:
System.out.println("Enter 1st number:");
num1 = input.nextDouble();
System.out.println("Enter 2nd number:");
num2 = input.nextDouble();
res = num1 - num2;
FIZA KHAN 2
16/02/2024 Object Oriented Programming
[Introduction To Java Programming Language]
FIZA KHAN 3
16/02/2024 Object Oriented Programming
[Introduction To Java Programming Language]
}
System.out.println("Do you want to continue? Y: Yes N:
NO");
ans1=Character.toUpperCase(input.next().charAt(0));
}
while(ans1=='Y');
System.out.println("Program ended!");
}
}
Output:
FIZA KHAN 4
16/02/2024 Object Oriented Programming
[Introduction To Java Programming Language]
Task # 03:
Make a program in JAVA in which take no. of items, price of items and name
of items as input from the user and give the discount according to the
following conditions:
• If from Bahria University give discount of 30%.
• Else if the total amount is greater then 50,000 and less than 100,000
give discount of 20%.
• Else if the total amount is greater then 100,000 give discount of 30%.
Solution:
package fiza.lab.pkg1;
import java.util.Scanner;
public class FizaLab1 {
FIZA KHAN 5
16/02/2024 Object Oriented Programming
[Introduction To Java Programming Language]
System.out.println("____________________BILL_____________________");
System.out.println("No. of items \tName of items \tPrice of
items");
for(int i=0;i<n;i++){
System.out.println(i+1+"\t\t"+name[i]+"\t\t"+price[i]);
}
System.out.println("Total Amount: "+total);
System.out.println("Discount: "+dis);
System.out.println("Payable Amount: "+payAm);
}
}
Output:
FIZA KHAN 6
16/02/2024 Object Oriented Programming
[Introduction To Java Programming Language]
Task # 04:
Write a JAVA program which will implement the following formulae using
methods.
• Automobile Tire Pressure: P = 0.37m(T + 460)/V P = pressure in psi.
V = volume in cubic feet
m = mass of air in pounds
T = temperature in Fahrenheit
• Pulley formulas
• calculate the speed of one pulley if there are 2 pulleys connected
with a belt:
RPM2 = diameter1/diameter2 * RPM1
• The body mass index (BMI), is a heuristic proxy for human body fat
based on an individual's weight and height. BMI does not actually
measure the percentage of body fat. We will be building a BMI
calculator method. Body mass index (BMI) is computed using the the
formula,
Where mass is the subject's weight in pounds (lb) and height is the height in
inches (in). The value 703 is a factor to convert BMI to a value that matches the
original BMI calculations done in metric units (i.e. kilograms-meters).
Solution:
package fiza.lab.pkg1;
import java.util.Scanner;
public class FizaLab1 {
static Scanner input=new Scanner(System.in);
public static void main(String[] args) {
char rep;
FIZA KHAN 7
16/02/2024 Object Oriented Programming
[Introduction To Java Programming Language]
do{
System.out.println("Which calculation do you want to
perform?");
System.out.println("1) Automobile Tire Pressure \n2)
Pulley formulas \n3) BMI Calculator");
int ans=input.nextInt();
switch(ans){
case 1:
ATM();
break;
case 2:
Pulley();
break;
case 3:
BMI();
break;
default:
System.out.println("Invalid choice");
break;
}
System.out.println("Do you want to continue? Y/N");
rep=input.next().charAt(0);
}
while(rep=='Y' || rep=='y');
}
public static void ATM(){
System.out.println("Enter the vaue of volume in cubic feet:");
double V=input.nextDouble();
System.out.println("Enter the value of mass of air in
pounds:");
double m=input.nextDouble();
System.out.println("Enter the value of temperature in
farhenheit:");
double T=input.nextDouble();
double P=0.37*m*(T + 460)/V;
System.out.println("The Automobile Tire Pressure is: "+P+"
psi");
}
public static void Pulley(){
System.out.println("Which calculation do you want to
perform?");
System.out.println("S: Speed of one pulley \nW: Weight that
can be lifted with a multiple pulley system");
char ans=Character.toUpperCase(input.next().charAt(0));
switch(ans){
case 'S':
FIZA KHAN 8
16/02/2024 Object Oriented Programming
[Introduction To Java Programming Language]
FIZA KHAN 9
16/02/2024 Object Oriented Programming
[Introduction To Java Programming Language]
Output:
FIZA KHAN 10