final String userName = “Student”;
final String password = “12345”;
boolean authenticated = false;
int attempts = 0;
// Login system
while (!authenticated && attempts < 3) {
String inputUserName = JOptionPane.showInputDialog(
if (inputUserName == null || inputUserName.
JOptionPane.showMessageDialog(
System.exit(0);
}
String inputPassword = JOptionPane.showInputDialog(
if (inputPassword == null || inputPassword.
JOptionPane.showMessageDialog(
System.exit(0);
}
if (inputUserName.equals(
authenticated = true;
JOptionPane.showMessageDialog(
} else {
attempts++;
if (attempts < 3) {
JOptionPane.showMessageDialog(
} else {
JOptionPane.showMessageDialog(
System.exit(0);
}
}
}
JOptionPane.showMessageDialog(
// Collect user details
String fullName = “”;
String ageStr = “”;
int age = 0;
String email = “”;
// Full Name
while (true) {
fullName = JOptionPane.showInputDialog(
if (fullName == null || fullName.equalsIgnoreCase(“
JOptionPane.showMessageDialog(
System.exit(0);
} else if (fullName.trim().isEmpty() || !fullName.matches(“[a-zA-Z ]+”)) {
JOptionPane.showMessageDialog(
} else {
break;
}
}
// Age
while (true) {
ageStr = JOptionPane.showInputDialog(
if (ageStr == null || ageStr.equalsIgnoreCase(“exit”
JOptionPane.showMessageDialog(
System.exit(0);
}
try {
age = Integer.parseInt(ageStr);
if (age < 12) {
JOptionPane.showMessageDialog(
} else {
break;
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(
}
}
// Email
while (true) {
email = JOptionPane.showInputDialog(
if (email == null || email.equalsIgnoreCase(“exit”)
JOptionPane.showMessageDialog(
System.exit(0);
} else if (email.trim().isEmpty() || !email.matches(“^[\\w.-]+@[\\
JOptionPane.showMessageDialog(
} else {
break;
}
}
// Movie selection and booking loop
boolean running = true;
while (running) {
Object[] movies = {
“Avengers: Endgame”,
“Interstellar”,
“Inception”,
“Barbie”,
“Exit”
};
int selectedMovie = JOptionPane.showOptionDialog(
null,
“Select a movie to book tickets:”,
“Movie Selection”,
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_
null,
movies,
movies[0]
);
if (selectedMovie == JOptionPane.CLOSED_OPTION || movies[selectedMovie].equals(“
running = false;
JOptionPane.showMessageDialog(
break;
}
String ticketCountStr;
int ticketCount = 0;
while (true) {
ticketCountStr = JOptionPane.showInputDialog(
if (ticketCountStr == null || ticketCountStr.
JOptionPane.showMessageDialog(
break;
}
try {
ticketCount = Integer.parseInt(
if (ticketCount <= 0) {
JOptionPane.showMessageDialog(
} else {
break;
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(
}
}
if (ticketCount <= 0) continue;
int response = JOptionPane.showConfirmDialog(
null,
“You’re booking ” + ticketCount + ” ticket(s) for:\n” + movies[selectedMovie] +
“\n\nDo you want to confirm?”,
“Confirm Booking”,
JOptionPane.YES_NO_OPTION
);
if (response == JOptionPane.YES_OPTION) {
final int pricePerTicket = 250;
int totalAmount = ticketCount * pricePerTicket;
String paymentStr = JOptionPane.showInputDialog(
null,
“Total amount: PHP ” + totalAmount + “\nEnter payment amount:”
);
if (paymentStr == null || paymentStr.equalsIgnoreCase(“
JOptionPane.showMessageDialog(
continue;
}
try {
double payment = Double.parseDouble(paymentStr)
double difference = payment – totalAmount;
String paymentMessage;
if (difference > 0) {
paymentMessage = “Change: PHP ” + String.format(“%.2f”, difference);
} else if (difference < 0) {
paymentMessage = “Insufficient payment. You’re short by: PHP “ + String.format(“%.2f”, -difference);
JOptionPane.showMessageDialog(
continue;
} else {
paymentMessage = “Exact amount received.”;
}
JOptionPane.showMessageDialog(
null,
“Booking Confirmed!\n\n” +
“Customer: ” + fullName + “\n” +
“Age: ” + age + “\n” +
“Email: “ + email + “\n” +
“Movie: ” + movies[selectedMovie] + “\n” +
“Tickets: ” + ticketCount + “\n” +
“Price per ticket: PHP ” + pricePerTicket + “\n” +
“Total: PHP ” + totalAmount + “\n” +
“Payment: PHP ” + String.format(“%.2f”, payment) + “\n” +
paymentMessage + “\n\nThank you for booking!”
);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(
}
} else {
JOptionPane.showMessageDialog(
}
}
}
}
LIBRARY CODE
String namePattern = “^[A-Za-z\\s]{2,50}$”;
String bookPattern = “^[\\w\\s\\p{Punct}]{1,100}$”;
while (true) {
int startChoice = JOptionPane.showConfirmDialog(
if (startChoice != JOptionPane.YES_OPTION) {
int exitConfirm = JOptionPane.showConfirmDialog(
if (exitConfirm == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(
System.exit(0);
} else {
continue;
}
}
String name = “”;
String bookTitle = “”;
while (true) {
name = JOptionPane.showInputDialog(“
if (name == null) {
int cancelConfirm = JOptionPane.showConfirmDialog(
if (cancelConfirm == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(
System.exit(0);
} else {
continue;
}
}
if (Pattern.matches(namePattern, name.trim())) {
break;
} else {
JOptionPane.showMessageDialog(
}
}
while (true) {
bookTitle = JOptionPane.showInputDialog(“
if (bookTitle == null) {
int cancelConfirm = JOptionPane.showConfirmDialog(
if (cancelConfirm == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(
System.exit(0);
} else {
continue;
}
}
if (Pattern.matches(bookPattern, bookTitle.trim())) {
break;
} else {
JOptionPane.showMessageDialog(
}
}
String message = ” Reservation Complete!\n\nName: ” + name + “\nBook: ” + bookTitle;
JOptionPane.showMessageDialog(
int again = JOptionPane.showConfirmDialog(
if (again != JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(
break;
}
}
System.exit(0);
}
}
ENGINEERING TOOLS ORDER
String customerName = “”;
String contactNumber = “”;
String contactAddress = “”;
int total = 0; // To keep track of total amount
// Get name
while (true) {
customerName = JOptionPane.showInputDialog(“
if (customerName == null || customerName.trim().isEmpty()) {
JOptionPane.showMessageDialog(
} else if (!customerName.matches(“[a-zA-
JOptionPane.showMessageDialog(
} else {
break;
}
}
// Get contact number
while (true) {
contactNumber = JOptionPane.showInputDialog(“
if (contactNumber == null || contactNumber.trim().isEmpty()
JOptionPane.showMessageDialog(
} else if (!contactNumber.matches(“\\d+”
JOptionPane.showMessageDialog(
} else {
break;
}
}
// Get address
while (true) {
contactAddress = JOptionPane.showInputDialog(“
if (contactAddress == null || contactAddress.trim().isEmpty(
JOptionPane.showMessageDialog(
} else {
int confirm = JOptionPane.showConfirmDialog(
“You entered:\n” + contactAddress + “\n\nIs this correct?”,
“Confirm Address”,
JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
break;
}
}
}
// Start ordering
boolean ordering = true;
while (ordering) {
String[] items = {“T-Square”, “ScientificCal”, “MechanicalCal”, “Compass”, “Protractor”, “Exit”};
int choice = JOptionPane.showOptionDialog(
“Select an item to order:”,
“Items”,
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_
null,
items,
items[0]);
if (choice == -1 || items[choice].equals(“Exit”)) {
ordering = false;
break;
}
String item = items[choice];
String quantityInput = JOptionPane.showInputDialog(“
if (quantityInput != null) {
int quantity = 0;
boolean valid = true;
try {
quantity = Integer.parseInt(
if (quantity <= 0) {
valid = false;
JOptionPane.showMessageDialog(
}
} catch (Exception e) {
valid = false;
JOptionPane.showMessageDialog(
}
if (valid) {
int price = 0;
if (item.equals(“T-Square”)) {
price = 2000;
} else if (item.equals(“ScientificCal”)) {
price = 1800;
} else if (item.equals(“MechanicalCal”)) {
price = 4000;
} else if (item.equals(“Compass”)) {
price = 1000;
} else if (item.equals(“Protractor”)) {
price = 25;
}
int subtotal = quantity * price;
total += subtotal;
JOptionPane.showMessageDialog(
String[] payments = {“Cash”, “Gcash”, “PayMaya”, “Credit Card”};
String paymentMethod = (String) JOptionPane.showInputDialog(
“Choose payment method:”,
“Payment”,
JOptionPane.PLAIN_MESSAGE,
null,
payments,
payments[0]);
if (paymentMethod != null) {
JOptionPane.showMessageDialog(
“Order confirmed!\n” +
item + ” x ” + quantity + “\n” +
“Payment: ” + paymentMethod);
} else {
JOptionPane.showMessageDialog(
}
}
} else {
JOptionPane.showMessageDialog(
}
}
JOptionPane.showMessageDialog(
String customerName= “”;
String contactNumber = “”;
String contactAddress = “”;
while (true) {
customerName = JOptionPane.showInputDialog(
if (customerName == null || customerName.trim().isEmpty()) {
JOptionPane.showMessageDialog(
} else if (!customerName.matches(“[a-zA-
JOptionPane.showMessageDialog(
} else {
break;
}
}
while (true) {
contactNumber = JOptionPane.showInputDialog(
if (contactNumber == null || contactNumber.trim().isEmpty()
JOptionPane.showMessageDialog(
} else if (!contactNumber.matches(“\\d+”
JOptionPane.showMessageDialog(
} else {
break;
}
}
while (true) {
contactAddress = JOptionPane.showInputDialog(
if (contactAddress == null || contactAddress.trim().isEmpty(
JOptionPane.showMessageDialog(
} else {
int confirmAddress = JOptionPane.showConfirmDialog(
null,
“You entered:\n” + contactAddress + “\n\nAre you sure you want to send the order to this address?”,
“Confirm Address”,
JOptionPane.YES_NO_OPTION
);
if (confirmAddress == JOptionPane.YES_OPTION) {
break;
}
}
}
boolean running = true;
while (running) {
Object[] products = {“T-Square”, “ScientificCal”, “MechanicalCal”, “Compass”, “Protractor”, “Exit”};
int selectedProduct = JOptionPane.showOptionDialog(
null,
“Please choose an item to order:”,
“Item Selection”,
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_
null,
products,
products[0]
);
if (selectedProduct ==JOptionPane.CLOSED_OPTION || products[selectedProduct].
running = false;
JOptionPane.showMessageDialog(
}else{
String quantityString = JOptionPane.showInputDialog(
if (quantityString !=null){
int quantity =0;
boolean validInput = true;
try{
quantity = Integer.parseInt(
if(quantity <=0){
validInput =false;
JOptionPane.showMessageDialog(
}
}catch(NumberFormatException e){
validInput= false;
JOptionPane.showMessageDialog(
}
if (validInput){
int response= JOptionPane.showConfirmDialog(
null,
“You ordered” + quantity + ” ” + products[selectedProduct] + “(s).Do you want to confirm the order?”,
“Order Confirmation”,
JOptionPane.YES_NO_OPTION
);
if (response == JOptionPane.YES_OPTION){
Object [] payment = {“Cash”, “Gcash”, “PayMaya”, “Credit Card”};
Object selectedPayment = JOptionPane.showInputDialog(
null,
“Select payment method: “,
“Payment”,
JOptionPane.PLAIN_MESSAGE,
null,
payment,
payment[0]
);
if (selectedPayment != null){
JOptionPane.
null,
“Order confirmed!\n” +
“Customer: ” + customerName + “\n” +
“Contact: ” + contactNumber + “\n” +
“Address: ” + contactAddress + “\n” +
“Items: ” + products[selectedProduct] + “\n” +
“Quantity: ” + quantity + “\n”+
“Payment Method: ” + selectedPayment + “\n\n” +
“Thank you for ordering!”
);
}else {
JOptionPane.
}
}else{
JOptionPane.
}
}
}else {
JOptionPane.
}
}
}
JOptionPane.showMessageDialog(
String customerName= “”;
String contactNumber = “”;
String contactAddress = “”;
while(true){
customerName = JOptionPane.showInputDialog(
if (customerName == null || customerName.trim().isEmpty())
JOptionPane.showMessageDialog(
}else if (!customerName.matches(“[a-zA-
JOptionPane.showMessageDialog(
}else{
break;
}
}
while(true){
contactNumber = JOptionPane.showInputDialog(
if (contactNumber == null || contactNumber.trim().isEmpty()
JOptionPane.showMessageDialog(
}else if (!contactNumber.matches(“\\d+”
JOptionPane.showMessageDialog(
}else{
break;
}
}
while(true){
contactAddress = JOptionPane.showInputDialog(
if (contactAddress == null || contactAddress.trim().isEmpty(
JOptionPane.showMessageDialog(
}else {
int confirmAddress = JOptionPane.showConfirmDialog(
null,
“You entered: \n” +contactAddress + “\n\nAre you sure you want to send this order to this address?”,
“Confirm Address”,
JOptionPane.YES_NO_OPTION
);
if (confirmAddress == JOptionPane.YES_OPTION){
break;
}
}
}
boolean running = true;
while (running) {
Object[] products = {“T-Square”, “ScientificCal”, “MechanicalCal”, “Compass”, “Protractor”};
int selectedProduct = JOptionPane.showOptionDialog(
null,
“Please choose an item to order:”,
“Item Selection”,
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_
null,
products,
products[0]
);
if (selectedProduct ==JOptionPane.CLOSED_OPTION || products[selectedProduct].
running = false;
JOptionPane.showMessageDialog(
}else{
String quantityString = JOptionPane.showInputDialog(
if (quantityString !=null){
int quantity =0;
boolean validInput = true;
try{
quantity = Integer.parseInt(
if(quantity <=0){
validInput =false;
JOptionPane.showMessageDialog(
}
}catch(NumberFormatException e){
validInput= false;
JOptionPane.showMessageDialog(
}
if (validInput){
int response= JOptionPane.showConfirmDialog(
null,
“You ordered” + quantity + ” ” + products[selectedProduct] + “(s).Do you want to confirm the order?”,
“Order Confirmation”,
JOptionPane.YES_NO_OPTION
);
if (response == JOptionPane.YES_OPTION){
Object [] payment = {“Cash”, “Gcash”, “PayMaya”, “Credit Card”};
Object selectedPayment = JOptionPane.showInputDialog(
null,
“Select payment method: “,
“Payment”,
JOptionPane.PLAIN_MESSAGE,
null,
payment,
payment[0]
);
if (selectedPayment != null){
JOptionPane.
null,
“Order confirmed!\n” +
“Customer: ” + customerName + “\n” +
“Contact: ” + contactNumber + “\n” +
“Address: ” + contactAddress + “\n” +
“Items: ” + products[selectedProduct] + “\n” +
“Quantity: ” + quantity + “\n”+
“Payment Method: ” + selectedPayment + “\n\n” +
“Thank you for ordering!”
);
}else {
JOptionPane.
}
}else{
JOptionPane.
}
}
}else{
JOptionPane.
}
}
}
JOptionPane.
boolean keepOrdering = true;
while (keepOrdering) {
Object[] menu = {“Classic Burger”, “Cheese Burger”, “Double Burger”, “Chicken Burger”, “Fries”, “Soda”};
int choice = JOptionPane.showOptionDialog(
“Choose your Order: “,
“MENU”,
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_
null,
menu,
menu[0]
);
if (choice != JOptionPane.CLOSED_OPTION) {
String quantitymenu = JOptionPane.showInputDialog(
int quantity = Integer.parseInt(quantitymenu)
if (quantity > 0) {
int response = JOptionPane.showConfirmDialog(
“You ordered ” + quantity + ” ” + menu[choice] + “(s). Do you want to confirm the order?”,
“Order Confirmation”,
JOptionPane.YES_NO_OPTION
);
if (response == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(
} else {
JOptionPane.showMessageDialog(
}
} else {
JOptionPane.showMessageDialog(
}
} else {
JOptionPane.showMessageDialog(
}
int exitResponse = JOptionPane.showConfirmDialog(
“Do you want to add another order?”,
“Add Another Order”,
JOptionPane.YES_NO_OPTION
);
if (exitResponse == JOptionPane.NO_OPTION) {
keepOrdering = false;
JOptionPane.showMessageDialog(
}
}
}
}
/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license */ package com.mycompany.mavenproject26; import java.util.Scanner; /** * * @author STUDENT */ public class Mavenproject26 { public static void main(String[] args) { System.out.println("Gunda & Alayan, Enter 5 Elements "); Scanner alayangunda = new Scanner (System.in); int n = 5; int [] o = new int [n]; for (int i=0; i<n; i++){ System.out.print("\nElements " + (i+1) + ":"); o [i] = alayangunda.nextInt(); } int lowerthan50 = 0; int greaterthan50 = 0; int equalto50 = 0; for(int y=0; y< o.length; y++){ if (o[y]>50){ greaterthan50++; }else if (o[y]<50){ lowerthan50++; }else{ equalto50++; } } System.out.println("\nThe numbers lower than 50: " + lowerthan50); System.out.println("\nThe numbers greater than 50: " + greaterthan50); System.out.println("\nThe numbers equal to 50: " + equalto50); }
Online Java Compiler. Code, Compile, Run and Debug java program online. Write your code in this editor and press "Run" button to execute it. *******************************************************************************/ import java.util.Scanner; public class ArrayActivity1 { public static void main(String[] args) { Scanner Names= new Scanner (System.in); System.out.println("Enter the Name Of Students: "); int size = Names.nextInt(); String [] userArray = new String [size]; System.out.println("Enter" + size + "Students Name:"); for (int i = 0; i<size; i++){ System.out.println ("Students " + (i + 1) + ":" ); userArray[i] = Names.nextLine(); } System.out.println("\nThe Students in BSCE are: "); for (int i = 0; i<userArray.length; i++){ System.out.println ("Students " + i + ":" + userArray[i]);