//editor used - IntelliJ IDEA
package ToyStore;
import javax.swing.*;
import java.awt.event.*;
import java.util.Scanner;
//here you can edit the available toys in the store according to the specific price and gender
class ToyStore {
final String[] BrdToys =new String[]{"Chess"," Ludo"," Chinese Checkers"," Monopoly"," Pictionary" }; //String
final int[] BrdToysPrice= new int[]{ 15,12,20,25,30}; //price in euros
final String[] SoftToys = new String[]{"Stuffed Animals","Plush Pillows","Teddy Bear","Octopus","Unicorn"};
final int[] STPrice=new int[] {20,26,25,20,26};
final String[] AfigureF = new String[]{"Barbie","Black Widow","Wonder Woman","Valkyrie","Catwoman"};
final int[] AfigFPrice= new int[]{20,25,20,26,30,25};
final String [] AfigureB=new String[]{"Iron Man","Spider Man","Hulk ","Thor"," AquaMan"};
final int[] AfigBPrice= new int[]{20,25,20,26,30,25};
final String[] CarToys= new String[]{"Monster Truck","HotWheels","RC Cars\t","Trucks","RoboCar"};
final int[] CarToyP= new int[]{20,35,20,26,30,25};
public void DisplayAllToys()
{
System.out.println("<---Board Games---> " );
for (int i = 0; i <5 ; i++) {
System.out.print(BrdToys[i]);
}
System.out.println("");
System.out.println("<---Soft Toys---> " );
for (int i = 0; i <5 ; i++) {
System.out.print(SoftToys[i]+" ");
}
System.out.println("");
System.out.println("<---Action Figures---> " );
for (int i = 0; i <5 ; i++) {
System.out.print(AfigureB[i]+" \t"+AfigureF[i]+" ");
}
System.out.println("");
System.out.println("<---Toy Cars---> " );
for (int i = 0; i <5 ; i++) {
System.out.print(CarToys[i]+" ");
}
}
}
class Customers extends ToyStore{
static String gender;
static int age;
static double priceInput;
public void input()
{
Scanner sc = new Scanner(System.in);
System.out.println("WELCOME TO GUCCI TOY STORE!");
System.out.println("Enter your child's age: ");
age = sc.nextInt();
if(age<=13 && age>=3) //assuming that maximum and minimum age for a child are 13y and 6y respectively
{
boolean x = true;
while(x)
{
System.out.println("Enter your child's gender (Male/Female) :");
gender = sc.next();
if (gender.equalsIgnoreCase("male") || gender.equalsIgnoreCase("female"))
{
x = false;
boolean y = true;
while(y)
{
System.out.println("Enter your maximum budget (>10 Euros)"); //assuming the toy with the lowest price is 10 Euros
priceInput = sc.nextDouble();
if (priceInput < 10.0 || priceInput > 69.99) {
System.out.println("Entered budget must at least be 10 Euros or at max be 60 Euros!");
}else
y = false;
}
}
else
System.out.println("Wrong input!");
}
}
else
System.out.println("Please enter a valid age (b/w 6 and 13 years old)");
//return age,priceInput;
}
void Choice()
{
System.out.println(" Press 1 to Display all Toys. Press 2 for Filling Details");
ToyStore ts=new ToyStore();
Customers cs=new Customers();
Scanner sc= new Scanner(System.in);
while(true) {
int ch=sc.nextInt();
if (ch == 1) {
ts.DisplayAllToys();
System.out.println(" \nPress 2 for Filling Details");
}
else if(ch ==2 )
{
cs.input();
break;
}
else
{
System.out.println("Enter Valid Choice");
}
}
}
public static void main(String[] args)
{
ToyPicker tp=new ToyPicker();
Customers cs = new Customers();
cs.Choice();
tp.assistant();
}
}
class Checkout extends JFrame implements ActionListener {
static int[] Price = new int[5];
static String[] FinOrder = new String[5];
JLabel l;
JCheckBox cb1, cb2, cb3, cb4, cb5;
JButton b;
Checkout(String[] order, int[] price)
//Checkout is to pop a window with all the category Toys and Let the user choose it and order.
{
for (int i = 0; i < 5; i++) {
Price[i] = price[i];
FinOrder[i] = order[i];
}
int i = 0;
l = new JLabel("Toy Selection System");
l.setBounds(100, 50, 1080, 50);
while (i == 0) {
cb1 = new JCheckBox(" " + order[i] + " \t@" + price[i]+ '€');
cb1.setBounds(100, 100, 150, 20);
cb2 = new JCheckBox(" " + order[i + 1] + " \t@" + price[i + 1] + '€');
cb2.setBounds(100, 150, 150, 20);
cb3 = new JCheckBox(" " + order[i + 2] + " \t@" + price[i + 2] + '€');
cb3.setBounds(100, 200, 200, 20);
cb4 = new JCheckBox(" " + order[i + 3] + " \t@" + price[i + 3] + '€');
cb4.setBounds(100, 250, 150, 20);
cb5 = new JCheckBox(" " + order[i + 4] + " \t@" + price[i+4] + '€');
cb5.setBounds(100, 300, 150, 20);
b = new JButton("Order");
b.setBounds(100, 400, 80, 30);
b.addActionListener(this);
add(l);add(cb1);add(cb2);add(cb3);add(cb4);add(cb5);add(b);
setSize(500, 700);
setLayout(null);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
i++;
}
}
public void actionPerformed(ActionEvent e) {
float amount = 0;
String msg = " ";
if (cb1.isSelected()) {
amount += Checkout.Price[0];
msg = Checkout.FinOrder[0] + " : " + Checkout.Price[0] + "€\n";
}
if (cb2.isSelected()) {
amount += Checkout.Price[1];
msg += Checkout.FinOrder[1] + " : " + Checkout.Price[1] + "€\n";
}
if (cb3.isSelected()) {
amount += Checkout.Price[2];
msg += Checkout.FinOrder[2] + " : " + Checkout.Price[2] + "€\n";
}
if (cb4.isSelected()) {
amount += Checkout.Price[3];
msg += Checkout.FinOrder[3] + " : " + Checkout.Price[3] + "€\n";
}
if (cb5.isSelected()) {
amount += Checkout.Price[4];
msg += Checkout.FinOrder[4] + " : " + Checkout.Price[4] + "€\n";
}
msg += "-----------------\n";
JOptionPane.showMessageDialog(this, msg + "Total: " + amount+"€");
if(amount<=Customers.priceInput)
{
JOptionPane.showMessageDialog(this, msg + "Transaction Successful: " + amount+"€");
}
else{
JOptionPane.showMessageDialog(this, msg + "Transaction Unsuccessful: " + amount+"€");
}
}
}
Output