Beruflich Dokumente
Kultur Dokumente
OOAD LAB
ROLL NO : F178171
MUHAMMAD HAMZA
Section C
Instructor SIR MUGHEES
ISMAIL
Semester FALL 2019
OOAD LAB 01
Problem 1:
Code:
package muliple;
import java.util.Scanner;
}
}
Screenshot:
PROBLEM 2:
CODE:
package muliple;
import java.util.Scanner;
public class Temprature {
public static void main(String[] args) {
int choice;
double temp;
Scanner input = new Scanner(System.in);
OOAD LAB 01
Screenshot:
Problem#03:
Code:
package muliple;
import java.util.Scanner;
do {
System.out.println("Enter a number : ");
ch = input. next(). charAt(0);
Screenshot:
Problem4:
Code:
package muliple;
import java.util.Scanner;
return;
}
else
return;
}
}
Screenshot:
Problem 5:
Code:
package muliple;
import java.util.Scanner;
public class pyramid {
public static void main(String[] args) {
int i;
for (i = 1; i < 20; i++) {
for (int j = 2; j <= i*2; j++) {
System.out.print("X");
}
System.out.println();
}
}
OOAD LAB 01
Screenshot:
Problem6:
Code:
package muliple;
import java.util.Scanner;
}
}
Screenshot:
OOAD LAB 01
Problem 07:
Code:
package muliple;
import java.util.Scanner;
public class Interest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int years;
double initial_amount,interst_rate;
System.out.println("Enter initial amount : ");
initial_amount = input.nextDouble();
System.out.println("Enter Number of years : ");
years = input.nextInt();
System.out.println("Enter interest rate(percent per year)");
interst_rate = input.nextDouble();
for(int i=0; i<years; i++)
initial_amount += initial_amount*interst_rate/100;
System.out.println( "At the end of year you have amount of "+initial_amount);
}
Screenshot:
Problem#09:
Code:
package muliple;
import java.util.Scanner;
public class Guest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int guest,chairs;
int i=0;
int total=1;
System.out.println("Enter Number of guest ");
guest= input.nextInt();
System.out.println("Enter Number of chairs ");
chairs= input.nextInt();
OOAD LAB 01
while(i<chairs) {
total*=(guest-i);
i++;
Screenshot:
Program#10:
Code:
package muliple;
import java.util.Scanner;
public class Interest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int i;
double initial_amount,interst_rate,final_amount;
System.out.println("Enter initial amount :");
initial_amount=input.nextDouble();
System.out.println("Enter final amount : ");
final_amount=input.nextDouble();
System.out.println("Enter intrest rate (percent per year):");
interst_rate=input.nextDouble();
for(i=0;final_amount>=initial_amount;i++) {
final_amount -= final_amount*interst_rate/100;
}
System.out.println("Total year "+i);
}
}
OOAD LAB 01
Screenshot:
Problem#12:
Code:
package muliple;
import java.util.Scanner;
switch (oper)
{
case '+':
answer= (a*d+b*c)/(b*d);
System.out.print("Addition is : " + answer);
break;
case '-':
answer = (a*d-b*c)/(b*d);
System.out.print("Subtraction is : " + answer);
break;
case '*':
answer = (a*c)/(b*d);
System.out.print("Multiplication is : " + answer);
break;
case '/':
answer = (a*d)/(b*c);
System.out.print("Division is : " + answer);
OOAD LAB 01
break;
default:
System.out.print("Invalid input again enter ");
main(args);
answer=0;
}
System.out.println();
System.out.print ("Enter ‘y’ for again calculation or ‘n’ for no ");
choice= input.next().charAt(0);
System.out.println();
if(choice=='y') {
main(args);
}
else if(choice=='n') {
return;
}
else
return;
}
}
Screenshot:
OOAD LAB 01