Lab Oop
Lab Oop
SP22-BSE-104
DR WAQAS JADOON
QUESTION NO1:
System.out.printf("The area of the circle with radius %.2f is: %.2f\n", radius, area);
double pi = Math.PI;
return area;
OUTPUT:
QUESTION NO2:
int a = 5, b = 1, c = 10;
System.out.println("The largest number among " + a + ", " + b + ", and " + c + " is: " + largest);
}
QUESTION NO3: /*
*/
package com.mycompany.cgpacalculator;
import java.util.Scanner;
/**
*/
System.out.print("Quiz: ");
System.out.print("Assignment: ");
System.out.print("Mid-Term: ");
System.out.print("Final: ");
double cgpa;
cgpa = 4.0;
cgpa = 3.0;
cgpa = 2.0;
} else {
}
QUESTION NO4:
/*
*/
package com.mycompany.mathquiz;
import java.util.Scanner;
/**
*/
int number2 = (int) (Math.random() * (number1 + 1)); // Generating random number2 (<= number1)
if (userAnswer == correctAnswer) {
System.out.println("Correct!");
} else {
switch (operation) {
case 0:
userAnswer = scanner.nextInt();
if (userAnswer == correctAnswer) {
System.out.println("Correct!");
} else {
System.out.println("Incorrect. The correct answer is: " + correctAnswer);
break;
case 1:
userAnswer = scanner.nextInt();
if (userAnswer == correctAnswer) {
System.out.println("Correct!");
} else {
break;
default:
System.out.println("Invalid operation.");
scanner.close();
}
EXERCISE:
import java.util.Scanner;
while (true) {
// Display question
// Check answer
} else {
System.out.println("Oops! That's incorrect. The correct answer is: " + (number1 - number2));
if (!playAgain.equals("yes")) {
break; // Exit the loop if the user doesn't want to play again
scanner.close();
2:
import java.util.Scanner;
public class ArithmeticGame {
while (true) {
char operation;
int result;
case 0:
operation = '+';
break;
case 1:
operation = '-';
break;
case 2:
operation = '*';
break;
case 3:
operation = '%';
break;
default:
break;
// Display question
System.out.print("What is " + number1 + " " + operation + " " + number2 + "? ");
// Check answer
if (answer == result) {
} else {
if (!playAgain.equals("yes")) {
break; // Exit the loop if the user doesn't want to play again
}
scanner.close();
Q1
Q2
Q3