package finalscomprog;
import java.util.Scanner;
public class Finalscomprog {
public static void main(String[] args) {
//final presentation..
//Login
//Assigned Program - Jewelry Shop Billing and Payment
//Requirements of Program
//*Array
//*Conditional Statement
//*Loop
// Sign up, Get the variable for ruser and rpassword from the user
Scanner io= new Scanner (System.in);
System.out.println("Sign up");
System.out.print("Enter your username: ");
String ruser=io.nextLine();
System.out.print("Enter your password: ");
String rpassword=io.nextLine();
Scanner scanner = new Scanner(System.in);
System.out.println("User Registered");
//Login, the ruser and rpassword variable must be the same to luser and lpass
System.out.println("Enter your login details:");
System.out.print("Enter username: ");
String spare= io.nextLine();
System.out.print("Enter password: ");
String spare2= io.nextLine();
// variables
String[] products = {"Sapphire Necklace", "Forever Bracelet", "Diamond Earrings", "Emerald Ring"}; //Jewelries
int[] prices = {320, 250, 475, 560}; // prices
boolean[] availability = {true, true, true, true}; //availability of stock
int[] cart = new int[4];// the picked items will be added to cart or the quantity of each product
int total = 0; // The total value everything added on the cart
boolean shopping = true; // used for checkout
// code to check if sign up and login are the same
if (ruser.equals(spare) && rpassword.equals(spare2)) {
System.out.println("Login successful!");
} else {
System.out.println("Login failed. Invalid username or password.");
return;
}
// loop
while (shopping) {
System.out.println("Welcome to ALAHAS IN BPSU! Please Choose a product:");
for (int i = 0; i < products.length; i++) {
if (availability[i]) {
System.out.println((i + 1) + ". " + products[i] + " (Php" + prices[i] + ")");
}
}
System.out.print("Enter product number (or 0 to check out): ");
int choice = scanner.nextInt();
if (choice == 0) {
shopping = false;
continue;
}
//continuation if user chose a product
choice--;
if (availability[choice]) {
System.out.print("Enter quantity: ");
int quantity = scanner.nextInt();
cart[choice] += quantity;
total += prices[choice] * quantity; // overall total quantity
System.out.println("Item added to cart!");
}
}
//Receipt or Final PrintOut
System.out.println("--- Receipt ---");
System.out.println("-ALAHAS IN BPSU-");
System.out.println("Owned & Operated by :LA ");
for (int i = 0; i < products.length; i++) {
if (cart[i] > 0) {
System.out.println(products[i] + ": " + cart[i] + " x Php" + prices[i] + " = Php" + cart[i] * prices[i]); //Final solution product: name +quantity + price = total
}
}
System.out.println("Total: Php" + " = Php"+total);
System.out.println("BPSU-CICT MAIN CAMPUS, Balanga City, Bataan 2100");
System.out.println("This Receipt shall be valid for FIVE (5) years from the date of permit to use");
}
}
the thing is my teacher asked why did i put [4] here on my arrayint