Java Programs
Java Programs
// Check and print the number of 100-peso bills public class Calculator {
if (change >= 100) { public static void main(String[] args) {
int count = change / 100; Scanner scanner = new Scanner(System.in);
System.out.println(count + " 100-peso bill");
change %= 100; // Input two numbers
} System.out.print("Enter the first number: ");
double num1 = scanner.nextDouble();
// Check and print the number of 50-peso bills
if (change >= 50) { System.out.print("Enter the second number: ");
int count = change / 50; double num2 = scanner.nextDouble();
System.out.println(count + " 50-peso bill");
change %= 50; // Display menu for operation selection
} System.out.println("Select an operation:");
System.out.println("1. Addition (+)");
// Check and print the number of 20-peso coins System.out.println("2. Subtraction (-)");
if (change >= 20) { System.out.println("3. Multiplication (*)");
int count = change / 20; System.out.println("4. Division (/)");
System.out.println(count + " 20-peso coin");
change %= 20; System.out.print("Enter your choice (1-4): ");
} int choice = scanner.nextInt();
// Check and print the number of 10-peso coins // Perform the selected operation
if (change >= 10) { switch (choice) {
int count = change / 10; case 1:
System.out.println(count + " 10-peso coin"); System.out.println("Result: " + (num1 + num2));
change %= 10; break;
} case 2:
System.out.println("Result: " + (num1 - num2));
// Check and print the number of 5-peso coins break;
if (change >= 5) { case 3:
int count = change / 5; System.out.println("Result: " + (num1 * num2));
System.out.println(count + " 5-peso coin"); break;
change %= 5; case 4:
} if (num2 != 0) {
System.out.println("Result: " + (num1 / num2));
// Check and print the number of 1-peso coins } else {
if (change >= 1) { System.out.println("Error: Division by zero is not
int count = change / 1; allowed.");
System.out.println(count + " 1-peso coin"); }
} break;
} default:
} System.out.println("Invalid choice. Please select a
number between 1 and 4.");
}
}
}
import java.util.Scanner;
double discount = 0;
// Calculate discount based on the purchase amount
if (purchaseAmount > 200) { int num1 = scanner.nextInt();
discount = 0.20; // 20% discount
} else if (purchaseAmount > 100) { System.out.print("Enter number two: ");
discount = 0.10; // 10% discount
} int num2 = scanner.nextInt();
// Calculate the total amount to be paid after applying the System.out.print("Enter number three: ");
discount int num3 = scanner.nextInt();
double discountAmount = purchaseAmount * discount;
double totalAmount = purchaseAmount - discountAmount; //================================//
9 10
if (username.equals(Username) &&
password.equals(Password)) { System.out.println("Your gloss salary is
System.out.println("Login successful! Welcome to "+grossSalary);
Facebook.");
} else { System.out.print("Enter number of absences: ");
System.out.println("Login failed! Incorrect username or double numOfAbsences = scanner.nextDouble();
password.");
} System.out.print("Enter deduction per absences: ");
} double deductionPerAbsences =
} scanner.nextDouble();
11
import java.util.Scanner;