Write a java program to generate electricity bill the tariff plans are
given below
No of units Price Per Unit in rupees
1-50 1.50 (one rupee fifty paisa)
51-100 2.00 (two rupees)
101-150 3.50 (three rupees fifty paisa)
151>= 5.00 (five rupees)
Calculate the bill amount for the current month based on the number of
units spent, the minimum bill amount should be 100 rupees.
import java.util.Scanner;
public class Q1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter units:");
int units = sc.nextInt();
double billAmount = calculatebill(units);
if (billAmount < 100) {
billAmount = 100;
} System.out.println("The bill amount for " + units + " units is: Rs. " + billAmount);
} public static double calculatebill(int units) {
double billAmount;
if (units <= 50) {
billAmount = units * 1.50;
} else if (units <= 100) {
billAmount = (50 * 1.50) + ((units - 50) * 2.00);
} else if (units <= 150) {
billAmount = (50 * 1.50) + (50 * 2.00) + ((units - 100) * 3.50);
} else {
billAmount = (50 * 1.50) + (50 * 2.00) + (50 * 3.50) + ((units - 150) * 5.00);
}return billAmount;
}}
Develop an ATM application in java to perform the following operations
Withdraw: For withdrawing the funds, gets the withdrawal amount
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.
Exit: Exit from the application by displaying Thank You message on
the screen.
import java.util.Scanner;
public class ATM {
private double balance;
public ATM(double initialBalance) {
this.balance = initialBalance;
public void withdraw(double amount) {
if (amount > balance) {
System.out.println("Insufficient funds.");
} else {
balance -= amount;
System.out.println("Successfully withdrawn: $" + amount);
displayBalance();
public void deposit(double amount) {
balance += amount;
System.out.println("Successfully deposited: $" + amount);
displayBalance();
}
public void displayBalance() {
System.out.println("Current balance: $" + balance);
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
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("3. Check Balance");
System.out.println("4. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Enter amount to withdraw: ");
double withdrawAmount = scanner.nextDouble();
atm.withdraw(withdrawAmount);
break;
case 2:
System.out.print("Enter amount to deposit: ");
double depositAmount = scanner.nextDouble();
atm.deposit(depositAmount);
break;
case 3:
atm.displayBalance();
break;
case 4:
System.out.println("Thank You for using the ATM. Goodbye!");
scanner.close();
System.exit(0);
default:
System.out.println("Invalid option. Please try again.");
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+: Marks>=90
Grade A: 90>Marks>=80
Grade B+: 80>Marks>=70
Grade B: 70>Marks>=60
Grade C: 60>Marks>=35
Fail: 35>Marks
Subject Max Marks Obtained marks. Grade
Maths 100 91. A+
DBMS 100 84. A
C language 100 74. B+
Java 100 64. B
Html 100 54. C
Php 100 34. FAIL
Result :. FAIL
import java.util.Scanner;
public class MarkSheet {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Get the number of subjects
System.out.print("Enter the number of subjects: ");
int numSubjects = scanner.nextInt();
// Initialize arrays to store marks and grades
int[] marks = new int[numSubjects];
String[] grades = new String[numSubjects];
// Input marks for each subject
for (int i = 0; i < numSubjects; i++) {
System.out.print("Enter marks for subject " + (i + 1) + ": ");
marks[i] = scanner.nextInt();
grades[i] = getGrade(marks[i]);
// Print the mark sheet
System.out.println("\nMark Sheet:");
System.out.println("Subject\tMarks\tGrade");
for (int i = 0; i < numSubjects; i++) {
System.out.println((i + 1) + "\t" + marks[i] + "\t" + grades[i]);
// Calculate and print the overall grade
double average = calculateAverage(marks);
String overallGrade = getGrade(average);
System.out.println("\nOverall Grade: " + overallGrade);
scanner.close();
// Method to calculate the grade based on marks
public static String getGrade(double marks) {
if (marks >= 90) {
return "A+";
} else if (marks >= 80) {
return "A";
} else if (marks >= 70) {
return "B+";
} else if (marks >= 60) {
return "B";
} else if (marks >= 35) {
return "C";
} else {
return "Fail";
}}
// Method to calculate the average of marks
public static double calculateAverage(int[] marks) {
int sum = 0;
for (int mark : marks) {
sum += mark;
}return (double) sum / marks.length;
}}
Given an integer, , perform the following conditional actions:
If is odd, print Weird
If is even and in the inclusive range of 2 to 5 , print Not Weird
If is even and in the inclusive range of 6 to 20, print Weird
If is even and greater than 20, print Not Weird
Complete the stub code provided in your editor to print whether or not is
weird.
Input Format
A single line containing a positive integer, .
Constraints
1<=n<=100
Output Format
Print Weird if the number is weird; otherwise, print Not Weird.
Sample Input 0
Sample Output 0
Weird
Sample Input 1
24
Sample Output 1
Not Weird
Explanation
Sample Case 0: n=3
n is odd and odd numbers are weird, so we print Weird.
Sample Case 1: n=24
n>20 and n is even, so it isn’t weird. Thus, we print Not Weird.
import java.util.Scanner;
public class ConditionalActions {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input a positive integer n
System.out.print("Enter a positive integer: ");
int n = scanner.nextInt();
// Determine if n is "Weird" or "Not Weird"
if (n % 2 != 0) {
// n is odd
System.out.println("Weird");
} else {
// n is even
if (n >= 2 && n <= 5) {
System.out.println("Not Weird");
} else if (n >= 6 && n <= 20) {
System.out.println("Weird");
} else if (n > 20) {
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
of N*i in the form:N x i = 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;
public class MultiplicationTable {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input an integer N
System.out.print("Enter an integer N: ");
int N = scanner.nextInt();
// Print the first 10 multiples of N
for (int i = 1; i <= 10; i++) {
System.out.println(N + " x " + i + " = " + (N * i));
}scanner.close();
}}
check weather the given number is palindrome or not.
import java.util.Scanner;
public class PalindromeCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input an integer
System.out.print("Enter an integer: ");
int number = scanner.nextInt();
// Check if the number is a palindrome
if (isPalindrome(number)) {
System.out.println(number + " is a palindrome.");
} else {
System.out.println(number + " is not a palindrome.");
}scanner.close();
// Method to check if a number is a palindrome
public static boolean isPalindrome(int number) {
int originalNumber = number;
int reversedNumber = 0;
while (number != 0) {
int digit = number % 10;
reversedNumber = reversedNumber * 10 + digit;
number /= 10;
return originalNumber == reversedNumber;
}}
Write a simple calculator program that performs addition, subtraction,
multiplication, or division based on user input.
Input:
The first line consists of two integers.
The second line consists of a character representing the operation (+, -, *,
/).
Output:
Print the result of the operation.
Example:
Input:
84
Output:
32
import java.util.Scanner;
public class SimpleCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input two integers
System.out.print("Enter two integers: ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
// Input the operation character
System.out.print("Enter an operation (+, -, *, /): ");
char operation = scanner.next().charAt(0);
// Perform the operation and print the result
switch (operation) {
case '+':
System.out.println("Result: " + (num1 + num2));
break;
case '-':
System.out.println("Result: " + (num1 - num2));
break;
case '*':
System.out.println("Result: " + (num1 * num2));
break;
case '/':
if (num2 != 0) {
System.out.println("Result: " + (num1 / num2));
} else {
System.out.println("Error: Division by zero");
break;
default:
System.out.println("Error: Invalid operation");
}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
the average score is 50 or more.
Input:
Three space-separated integers representing the marks in three subjects.
Output:
Print pass if the student passes, otherwise print fail
Example:
Input:
45 55 60
Output:
Pass
import java.util.Scanner;
public class StudentResult {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input three space-separated integers representing the marks in three subjects
System.out.print("Enter marks in three subjects: ");
int mark1 = scanner.nextInt();
int mark2 = scanner.nextInt();
int mark3 = scanner.nextInt();
// Calculate the average score
int sum = mark1 + mark2 + mark3;
double average = sum / 3.0;
// Check if the student has passed or failed
if (mark1 >= 40 && mark2 >= 40 && mark3 >= 40 && average >= 50) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}scanner.close();
}}
Write a program to print product of individual digits of a given number.
import java.util.Scanner;
public class DigitProduct {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input an integer
System.out.print("Enter an integer: ");
int number = scanner.nextInt();
// Initialize the product variable
int product = 1;
// Calculate the product of individual digits
while (number != 0) {
int digit = number % 10;
product *= digit;
number /= 10;
}// Print the product
System.out.println("Product of individual digits: " + product);
scanner.close();
}}
print sum of first 5 elements of Fibonacci series.
public class FibonacciSum {
public static void main(String[] args) {
// Variables to store the first two Fibonacci numbers
int num1 = 0, num2 = 1;
// Variable to store the sum of the first 5 Fibonacci numbers
int sum = num1 + num2;
// Print the first two Fibonacci numbers
System.out.println("Fibonacci series: ");
System.out.print(num1 + " " + num2 + " ");
// Loop to calculate the next 3 Fibonacci numbers and their sum
for (int i = 3; i <= 5; i++) {
int nextNum = num1 + num2;
sum += nextNum;
System.out.print(nextNum + " ");
num1 = num2;
num2 = nextNum;
// Print the sum of the first 5 Fibonacci numbers
System.out.println("\nSum of the first 5 Fibonacci numbers: " + sum);