WebProgramming Lab Excercises From 1 To 6
WebProgramming Lab Excercises From 1 To 6
given below
Calculate the bill amount for the current month based on the number of
import java.util.Scanner;
public class Q1 {
System.out.println("Enter units:");
billAmount = 100;
} System.out.println("The bill amount for " + units + " units is: Rs. " + billAmount);
double billAmount;
} else {
billAmount = (50 * 1.50) + (50 * 2.00) + (50 * 3.50) + ((units - 150) * 5.00);
}return billAmount;
}}
from the user, deduct it from the total balance, and display the
message.
Deposit: For depositing the funds, gets the deposit amount from the
user to add, add it to the total balance, and display the message.
Check the balance: For checking the balance, display the user’s total
balance.
the screen.
import java.util.Scanner;
this.balance = initialBalance;
System.out.println("Insufficient funds.");
} else {
balance -= amount;
displayBalance();
balance += amount;
displayBalance();
}
ATM atm = new ATM(1000.0); // Initial balance set to $1000 for testing
while (true) {
System.out.println("\nATM Menu:");
System.out.println("1. Withdraw");
System.out.println("2. Deposit");
System.out.println("4. Exit");
switch (choice) {
case 1:
atm.withdraw(withdrawAmount);
break;
case 2:
atm.deposit(depositAmount);
break;
case 3:
atm.displayBalance();
break;
case 4:
scanner.close();
System.exit(0);
default:
write a Java program to create marks sheet with all grades and print the
overall grade as shown below and the Grading details are as follows:
Grade A: 90>Marks>=80
Grade B: 70>Marks>=60
Grade C: 60>Marks>=35
Fail: 35>Marks
Result :. FAIL
import java.util.Scanner;
marks[i] = scanner.nextInt();
grades[i] = getGrade(marks[i]);
System.out.println("\nMark Sheet:");
System.out.println("Subject\tMarks\tGrade");
scanner.close();
return "A+";
return "A";
return "B+";
return "C";
} else {
return "Fail";
}}
int sum = 0;
sum += mark;
}}
Complete the stub code provided in your editor to print whether or not is
weird.
Input Format
Constraints
1<=n<=100
Output Format
Sample Input 0
Sample Output 0
Weird
Sample Input 1
24
Sample Output 1
Not Weird
Explanation
import java.util.Scanner;
int n = scanner.nextInt();
if (n % 2 != 0) {
// n is odd
System.out.println("Weird");
} else {
// n is even
System.out.println("Not Weird");
System.out.println("Weird");
System.out.println("Not Weird");
}}
scanner.close();
}}
Given an integer, N , print its first 10 multiples. Each multiple N*i (where
1<=i<=10) shouldbe printed on a new line in the form: N x i = result.
Input Format
A single integer,N .
Constraints
2<=N<=20
Output Format
Print 10 lines of output; each line i (where 1<=i<=10) contains the result
Sample Input
Sample Output
2x1=2
2x2=4
2x3=6
2x4=8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
import java.util.Scanner;
// Input an integer N
int N = scanner.nextInt();
// Print the first 10 multiples of N
}scanner.close();
}}
import java.util.Scanner;
// Input an integer
if (isPalindrome(number)) {
} else {
}scanner.close();
int reversedNumber = 0;
while (number != 0) {
number /= 10;
}}
Input:
/).
Output:
Example:
Input:
84
Output:
32
import java.util.Scanner;
switch (operation) {
case '+':
break;
case '-':
case '*':
break;
case '/':
if (num2 != 0) {
} else {
break;
default:
}scanner.close();
}}
Given the marks of a student in three subjects, determine if the student has
passed or failed. The student passes if they score at least 40 in each subject and
Input:
Output:
Example:
Input:
45 55 60
Output:
Pass
import java.util.Scanner;
if (mark1 >= 40 && mark2 >= 40 && mark3 >= 40 && average >= 50) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}scanner.close();
}}
import java.util.Scanner;
// Input an integer
int product = 1;
while (number != 0) {
product *= digit;
number /= 10;
scanner.close();
}}
sum += nextNum;
num1 = num2;
num2 = nextNum;