Sie sind auf Seite 1von 11

OOAD LAB 01

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;

public class multiply {


public static void main(String[] args) {
int count=1;
Scanner input = new Scanner(System.in);
System.out.println("Enter the number : ");
int number = input.nextInt();
System.out.println("Multiples of number is ");
for (int i = 0; i <20; i++) {
for (int j =0; j <10; j++) {
System.out.print(number*count+" ");
count++;
}
System.out.println();
}

}
}

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

System.out.println("press 1.Convert farhneit to celcius 2.Convert celcius to farheniet ");


choice= input.nextInt();
if(choice==1) {
System.out.println("Enter temprature in farhneit ");
temp= input.nextInt();
System.out.println("Farneit to celcius "+5.0 / 9.0*(temp-32.0));
}
else if(choice==2) {
System.out.println("Enter temprature in celcius ");
temp= input.nextInt();
System.out.println("celcius to farhneit "+ 9.0 / 5.0*temp + 32.0);
}
else {
System.out.println("INVALID INPUT ");
main(args);
}
}
}

Screenshot:

Problem#03:
Code:
package muliple;
import java.util.Scanner;

public class Digit {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int total=0;
char ch;

do {
System.out.println("Enter a number : ");
ch = input. next(). charAt(0);

total= total * 10 + ch- '0';

System.out.println("Number is : "+ total);


}
while(ch!='\r');
}
OOAD LAB 01

Screenshot:

Problem4:
Code:
package muliple;
import java.util.Scanner;

public class Calculator {


public static void main(String[] args) {

double number1, number2, answer;


char oper, choice;
Scanner input = new Scanner(System.in);
System.out.print("Enter first number : ");
number1 = input.nextInt();
System.out.print("Enter operation to perform ");
oper = input.next().charAt(0);
System.out.print("Enter second number : ");
number2= input.nextInt();
switch (oper)
{
case '+':
answer= number1 + number2;
System.out.print("Addition is : " + answer);
break;
case '-':
answer = number1 - number2;
System.out.print("Subtraction is : " + answer);
break;
case '*':
answer = number1 * number2;
System.out.print("Multiplication is : " + answer);
break;
case '/':
answer = number1 / number2;
System.out.print("Division is : " + answer);
break;
default:
OOAD LAB 01

System.out.print("Invalid input again enter ");


main(args);
answer=0;
}

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:

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;

public class Factorial {


public static void main(String[] args) {
int number;

System.out.println("Enter the number you want factorial ");


Scanner input = new Scanner(System.in);
number = input.nextInt();
do {
int i;
long fact=1;
for (i = number; i>0; i--)
fact= fact*i;
System.out.print( "Factorial is " + fact);
System.out.println();
System.out.println("Enter 0 to exit or any number to calculate factorial");
number = input.nextInt();
} while (number != 0);

}
}

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++;

System.out.println("Total number of possible arrangement "+total);

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;

public class Calculator {


public static void main(String[] args) {

double a,b,c,d, answer;


char oper, choice;
Scanner input = new Scanner(System.in);
System.out.print("Enter first number of first fraction : ");
a= input.nextDouble();

System.out.print("Enter second number first fraction : ");


b= input.nextDouble();

System.out.print("Enter operation to perform ");


oper = input.next().charAt(0);
System.out.print("Enter first number second fraction : ");
c= input.nextDouble();
System.out.print("Enter second number second fraction : ");
d= input.nextDouble();

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

Das könnte Ihnen auch gefallen