What's new

Please help me about this i don't know how to do this

ZattyZ

Leecher
Joined
Apr 1, 2022
Posts
6
Reaction
0
Points
2
please help me about this i don't know how to do this

Screen Shot 2022-04-01 at 9.38.38 AM.png Screen Shot 2022-04-01 at 9.39.08 AM.png Screen Shot 2022-04-01 at 9.39.29 AM.png
 

Attachments

I think nakapag gawa na ako nyan sa java dati,

Naka loop na if else lang tapos, nilagyan ko nalang ng A,B,C,D yung mga name ng items para madali lang e if else. Then yung answer na variable is naka auto UPPERCASE para kahit ano e enter ni user pasok parin dun sa condition
 
I think nakapag gawa na ako nyan sa java dati,

Naka loop na if else lang tapos, nilagyan ko nalang ng A,B,C,D yung mga name ng items para madali lang e if else. Then yung answer na variable is naka auto UPPERCASE para kahit ano e enter ni user pasok parin dun sa condition
can you help me po literal po kasi na hindi ko alam paano umpisahan.
 
Ano po coverage nito? Arrays and loops lng ba?

  1. Define a multidimensional 3X5 string array (prod, stock, price) and initialize with values based on stated example (products list)
  2. Run a loop to read all the contents of the array
  3. Define a loop to read user data and terminate upon user response (y/N)
  4. get user input
  5. Define an inner loop to search product from the array
  6. if the product is found, get price, compute total, deduct stocks (modify index 1)
  7. show Totals
  8. else, show product not found!
  9. ask the user if he/he want to try again
  10. if yes, continue,
  11. else, break
The idea presented above requires effort..Good luck!
 
Last edited:
Ano po coverage nito? Arrays and loops lng ba?

  1. Define a multidimensional 3X5 string array (prod, stock, price) and initialize with values based on stated example (products list)
  2. Run a loop to read all the contents of the array
  3. Define a loop to read user data and terminate upon user response (y/N)
  4. get user input
  5. Define an inner loop to search product from the array
  6. if the product is found, get price, compute total, deduct stocks (modify index 1)
  7. show Totals
  8. else, show product not found!
  9. ask the user if he/he want to try again
  10. if yes, continue,
  11. else, break
The idea presented above requires effort..Good luck!
import java.util.Scanner;

public class Shop {
static Stock store[] = {
new Stock(new String[]{"bags","bag"}, 25.45, 10),
new Stock(new String[]{"shoe","shoes"}, 67.64, 20),
new Stock(new String[]{"shirt","shirts"}, 43.23, 10),
new Stock(new String[]{"jeans"}, 24.12, 10),
new Stock(new String[]{"glove","gloves"}, 12.34, 5)
};

public static void main(String[] args) {

double total = visitStore();
System.out.println(total);



}
static double visitStore(){
Scanner in = new Scanner(System.in);
double subTotal = buy();
do{
subTotal+= buy();
System.out.println("Subtotal : $ " + subTotal);
System.out.println("Would you like to buy again? (y/n)");

}while(in.next().toLowerCase()=="y");
in.close();
return subTotal;
}

static double buy(){
Scanner input = new Scanner(System.in);
double total = 0;
String thing;
int itemCount;

showStocks();

System.out.println("What you want to buy");
thing = input.nextLine();


boolean found = false;
for (Stock stock : store) {
if(stock.find(thing)){
found = true;
if(stock.stock!=0){
boolean itemNotInRange = true;
do{
System.out.println("How many ?");

itemCount = input.nextInt();

if(stock.stock>=itemCount){
itemNotInRange = false;
total = stock.cost * itemCount;
stock.stock -= itemCount;
}else{
System.out.println("Not Enough Stock, try again");
}
}while(itemNotInRange);
}else{
System.out.println("Item out of Stock!");
}
break;
}
}
if(!found)
System.out.println("Item not found!");
input.close();
return total;
}

static void showStocks(){
System.out.println("Stocks:\t\tCost:");

for (Stock stock : store) {
stock.display();
}
}

}
class Stock {
String name[];
double cost;
int stock;
Stock(String[] name,double cost,int stock){
this.name = name;
this.cost = cost;
this.stock = stock;
}
boolean find(String name){
for(String n : this.name)
if(n.equals(name))
return true;
return false;
}


void display(){
System.out.println(this.name[0] + " - " + this.stock + "\t\t|| $" + this.cost);
}
}
 
import java.util.Scanner;

public class Shop {
static Stock store[] = {
new Stock(new String[]{"bags","bag"}, 25.45, 10),
new Stock(new String[]{"shoe","shoes"}, 67.64, 20),
new Stock(new String[]{"shirt","shirts"}, 43.23, 10),
new Stock(new String[]{"jeans"}, 24.12, 10),
new Stock(new String[]{"glove","gloves"}, 12.34, 5)
};

public static void main(String[] args) {

double total = visitStore();
System.out.println(total);



}
static double visitStore(){
Scanner in = new Scanner(System.in);
double subTotal = buy();
do{
subTotal+= buy();
System.out.println("Subtotal : $ " + subTotal);
System.out.println("Would you like to buy again? (y/n)");

}while(in.next().toLowerCase()=="y");
in.close();
return subTotal;
}

static double buy(){
Scanner input = new Scanner(System.in);
double total = 0;
String thing;
int itemCount;

showStocks();

System.out.println("What you want to buy");
thing = input.nextLine();


boolean found = false;
for (Stock stock : store) {
if(stock.find(thing)){
found = true;
if(stock.stock!=0){
boolean itemNotInRange = true;
do{
System.out.println("How many ?");

itemCount = input.nextInt();

if(stock.stock>=itemCount){
itemNotInRange = false;
total = stock.cost * itemCount;
stock.stock -= itemCount;
}else{
System.out.println("Not Enough Stock, try again");
}
}while(itemNotInRange);
}else{
System.out.println("Item out of Stock!");
}
break;
}
}
if(!found)
System.out.println("Item not found!");
input.close();
return total;
}

static void showStocks(){
System.out.println("Stocks:\t\tCost:");

for (Stock stock : store) {
stock.display();
}
}

}
class Stock {
String name[];
double cost;
int stock;
Stock(String[] name,double cost,int stock){
this.name = name;
this.cost = cost;
this.stock = stock;
}
boolean find(String name){
for(String n : this.name)
if(n.equals(name))
return true;
return false;
}


void display(){
System.out.println(this.name[0] + " - " + this.stock + "\t\t|| $" + this.cost);
}
}

my error po hindi ko ma ayos.x pa help po /\

I think nakapag gawa na ako nyan sa java dati,

Naka loop na if else lang tapos, nilagyan ko nalang ng A,B,C,D yung mga name ng items para madali lang e if else. Then yung answer na variable is naka auto UPPERCASE para kahit ano e enter ni user pasok parin dun sa condition
pwede po patulong sa error hindi ko po maayos

import java.util.Scanner;

public class Shop {
static Stock store[] = {
new Stock(new String[]{"bags","bag"}, 25.45, 10),
new Stock(new String[]{"shoe","shoes"}, 67.64, 20),
new Stock(new String[]{"shirt","shirts"}, 43.23, 10),
new Stock(new String[]{"jeans"}, 24.12, 10),
new Stock(new String[]{"glove","gloves"}, 12.34, 5)
};

public static void main(String[] args) {

double total = visitStore();
System.out.println(total);



}
static double visitStore(){
Scanner in = new Scanner(System.in);
double subTotal = buy();
do{
subTotal+= buy();
System.out.println("Subtotal : $ " + subTotal);
System.out.println("Would you like to buy again? (y/n)");

}while(in.next().toLowerCase()=="y");
in.close();
return subTotal;
}

static double buy(){
Scanner input = new Scanner(System.in);
double total = 0;
String thing;
int itemCount;

showStocks();

System.out.println("What you want to buy");
thing = input.nextLine();


boolean found = false;
for (Stock stock : store) {
if(stock.find(thing)){
found = true;
if(stock.stock!=0){
boolean itemNotInRange = true;
do{
System.out.println("How many ?");

itemCount = input.nextInt();

if(stock.stock>=itemCount){
itemNotInRange = false;
total = stock.cost * itemCount;
stock.stock -= itemCount;
}else{
System.out.println("Not Enough Stock, try again");
}
}while(itemNotInRange);
}else{
System.out.println("Item out of Stock!");
}
break;
}
}
if(!found)
System.out.println("Item not found!");
input.close();
return total;
}

static void showStocks(){
System.out.println("Stocks:\t\tCost:");

for (Stock stock : store) {
stock.display();
}
}

}
class Stock {
String name[];
double cost;
int stock;
Stock(String[] name,double cost,int stock){
this.name = name;
this.cost = cost;
this.stock = stock;
}
boolean find(String name){
for(String n : this.name)
if(n.equals(name))
return true;
return false;
}


void display(){
System.out.println(this.name[0] + " - " + this.stock + "\t\t|| $" + this.cost);
}
}
 
Sundan mo lang yung idea na binigay ko. Di ka mawawala doon. sa una palang mali pagkaka construct mo ng multidimensional array..
 
Sundan mo lang yung idea na binigay ko. Di ka mawawala doon. sa una palang mali pagkaka construct mo ng multidimensional array..
pwede po pa check saan ako may mali po hindi kasi nababwasan yong stock please help po

static int shirtstock=10;
static int jeanstock=10;
static int glovestock=5;
static double total = 0, subtotal = 0;
public static void main(String[] args) {

Scanner console = new Scanner(System.in);
int quantity;
int stock[] = {bagstock=10, shoestock=20, shirtstock=10, jeanstock=10, glovestock=5};
String itemList[] = {"Bags", "Shoes", "Shirt", "Jeans", "Gloves"};
double cost[] = {25.45, 67.64, 43.23, 24.12, 12.34};
System.out.println("Stock:\t\t||Cost:");
for(int i = 0; i<5; i++){
System.out.println(String.valueOf(itemList) + "\t" + String.valueOf(stock)
+ "\t||" + String.valueOf(cost));}
while(true){
System.out.println("What would you like to buy? ");
String item = console.next().toLowerCase();
while(true){
System.out.println("How many?");
quantity = console.nextInt();

if(item.contains("bag")&(stock[0]-->=quantity)){
int bagstock = stock[0]- quantity;
int base = bagstock - quantity;
System.out.println(stock[0]--);
if (bagstock >= base){
subtotal = quantity * cost[0];
total = total + subtotal;
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal);
bagstock = bagstock - quantity;
}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;}
}else if(item.contains("shoe") & stock[0]>=quantity){
int shoe = stock[0] - quantity;
int base = shoe - quantity;
System.out.println(stock[0]--);
if (shoe >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
shoestock = shoestock - quantity;

}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else if(item.contains("shirt")& stock[0]>=quantity){
int shirt = stock[0] - quantity;
int base = shirt - quantity;
System.out.println(stock[0]--);
if (shirt >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
shirtstock = shirtstock - quantity;
}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else if(item.contains("jean")& stock[0]>=quantity){
int jean = stock[0] - quantity;
int base = jean - quantity;
System.out.println(stock[0]--);
if (jean >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
jeanstock = jeanstock - quantity;
}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else if(item.contains("glove")& stock[0]>=quantity){
int glove = stock[0] - quantity;
int base = glove - quantity;
System.out.println(stock[0]--);
if (glove >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;

}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else{
System.out.println("Not enough stock. Try again.");
continue;
} break;
}
System.out.println("Would you like to order again? (Y/N)");
String answer = console.next().toLowerCase();
if(answer.contains("y")){
continue;
}else{
double total = subtotal + subtotal;
System.out.println("The total is: " + total);
System.out.print("Input Payment: \n \u20B1");
double pay=console.nextDouble();
System.out.printf("Your change is: \u20B1" + "%3.2f%n",(pay-total));
System.out.println("Would you like to make another transaction? (Y/N)");
String sagot = console.next().toLowerCase();
if (sagot.contains("y")){
int input = stock- quantity;
Arrays.asList(stock, input);
for(int i = 0; i<5; i++){
System.out.println(String.valueOf(itemList) + "\t" + String.valueOf(stock)
+ "\t||" + String.valueOf(cost));
}
continue;

}
else{
System.out.println("Thank you come again!");
System.exit(0);
}
}
}
}
}


pwede po pa check saan ako may mali po hindi kasi nababwasan yong stock please help po

import java.util.Arrays;
import java.util.Scanner;
public class MidtermActivity {
static int i;
static int bagstock=10;
static int shoestock = 20;
static int shirtstock=10;
static int jeanstock=10;
static int glovestock=5;
static double total = 0, subtotal = 0;
public static void main(String[] args) {

Scanner console = new Scanner(System.in);
int quantity;
int stock[] = {bagstock=10, shoestock=20, shirtstock=10, jeanstock=10, glovestock=5};
String itemList[] = {"Bags", "Shoes", "Shirt", "Jeans", "Gloves"};
double cost[] = {25.45, 67.64, 43.23, 24.12, 12.34};
System.out.println("Stock:\t\t||Cost:");
for(int i = 0; i<5; i++){
System.out.println(String.valueOf(itemList) + "\t" + String.valueOf(stock)
+ "\t||" + String.valueOf(cost));}
while(true){
System.out.println("What would you like to buy? ");
String item = console.next().toLowerCase();
while(true){
System.out.println("How many?");
quantity = console.nextInt();

if(item.contains("bag")&(stock[0]-->=quantity)){
int bagstock = stock[0]- quantity;
int base = bagstock - quantity;
System.out.println(stock[0]--);
if (bagstock >= base){
subtotal = quantity * cost[0];
total = total + subtotal;
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal);
bagstock = bagstock - quantity;
}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;}
}else if(item.contains("shoe") & stock[0]>=quantity){
int shoe = stock[0] - quantity;
int base = shoe - quantity;
System.out.println(stock[0]--);
if (shoe >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
shoestock = shoestock - quantity;

}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else if(item.contains("shirt")& stock[0]>=quantity){
int shirt = stock[0] - quantity;
int base = shirt - quantity;
System.out.println(stock[0]--);
if (shirt >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
shirtstock = shirtstock - quantity;
}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else if(item.contains("jean")& stock[0]>=quantity){
int jean = stock[0] - quantity;
int base = jean - quantity;
System.out.println(stock[0]--);
if (jean >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
jeanstock = jeanstock - quantity;
}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else if(item.contains("glove")& stock[0]>=quantity){
int glove = stock[0] - quantity;
int base = glove - quantity;
System.out.println(stock[0]--);
if (glove >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;

}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else{
System.out.println("Not enough stock. Try again.");
continue;
} break;
}
System.out.println("Would you like to order again? (Y/N)");
String answer = console.next().toLowerCase();
if(answer.contains("y")){
continue;
}else{
double total = subtotal + subtotal;
System.out.println("The total is: " + total);
System.out.print("Input Payment: \n \u20B1");
double pay=console.nextDouble();
System.out.printf("Your change is: \u20B1" + "%3.2f%n",(pay-total));
System.out.println("Would you like to make another transaction? (Y/N)");
String sagot = console.next().toLowerCase();
if (sagot.contains("y")){
int input = stock- quantity;
Arrays.asList(stock, input);
for(int i = 0; i<5; i++){
System.out.println(String.valueOf(itemList) + "\t" + String.valueOf(stock)
+ "\t||" + String.valueOf(cost));
}
continue;

}
else{
System.out.println("Thank you come again!");
System.exit(0);
}
}
}
}
}
 
Last edited:
import java.util.Arrays;
import java.util.Scanner;
public class MidtermActivity {
static int i;
static int bagstock=10;
static int shoestock = 20;
static int shirtstock=10;
static int jeanstock=10;
static int glovestock=5;
static double total = 0, subtotal = 0;
public static void main(String[] args) {

Scanner console = new Scanner(System.in);
int quantity;
int stock[] = {bagstock=10, shoestock=20, shirtstock=10, jeanstock=10, glovestock=5};
String itemList[] = {"Bags", "Shoes", "Shirt", "Jeans", "Gloves"};
double cost[] = {25.45, 67.64, 43.23, 24.12, 12.34};
System.out.println("Stock:\t\t||Cost:");
for(int i = 0; i<5; i++){
System.out.println(String.valueOf(itemList) + "\t" + String.valueOf(stock)
+ "\t||" + String.valueOf(cost));}
while(true){
System.out.println("What would you like to buy? ");
String item = console.next().toLowerCase();
while(true){
System.out.println("How many?");
quantity = console.nextInt();

if(item.contains("bag")&(stock[0]-->=quantity)){
int bagstock = stock[0]- quantity;
int base = bagstock - quantity;
System.out.println(stock[0]--);
if (bagstock >= base){
subtotal = quantity * cost[0];
total = total + subtotal;
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal);
bagstock = bagstock - quantity;
}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;}
}else if(item.contains("shoe") & stock[0]>=quantity){
int shoe = stock[0] - quantity;
int base = shoe - quantity;
System.out.println(stock[0]--);
if (shoe >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
shoestock = shoestock - quantity;

}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else if(item.contains("shirt")& stock[0]>=quantity){
int shirt = stock[0] - quantity;
int base = shirt - quantity;
System.out.println(stock[0]--);
if (shirt >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
shirtstock = shirtstock - quantity;
}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else if(item.contains("jean")& stock[0]>=quantity){
int jean = stock[0] - quantity;
int base = jean - quantity;
System.out.println(stock[0]--);
if (jean >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
jeanstock = jeanstock - quantity;
}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else if(item.contains("glove")& stock[0]>=quantity){
int glove = stock[0] - quantity;
int base = glove - quantity;
System.out.println(stock[0]--);
if (glove >= base){
subtotal = quantity * cost[0];
System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;

}else if (base <= 0){
System.out.println("Item Out of Stock. Select another item.");
continue;
}
}else{
System.out.println("Not enough stock. Try again.");
continue;
} break;
}
System.out.println("Would you like to order again? (Y/N)");
String answer = console.next().toLowerCase();
if(answer.contains("y")){
continue;
}else{
double total = subtotal + subtotal;
System.out.println("The total is: " + total);
System.out.print("Input Payment: \n \u20B1");
double pay=console.nextDouble();
System.out.printf("Your change is: \u20B1" + "%3.2f%n",(pay-total));
System.out.println("Would you like to make another transaction? (Y/N)");
String sagot = console.next().toLowerCase();
if (sagot.contains("y")){
int input = stock- quantity;
Arrays.asList(stock, input);
for(int i = 0; i<5; i++){
System.out.println(String.valueOf(itemList) + "\t" + String.valueOf(stock)
+ "\t||" + String.valueOf(cost));
}
continue;

}
else{
System.out.println("Thank you come again!");
System.exit(0);
}
}
}
}
}


your posted code was not convenient to read. Post your code properly.. Ganito gawin mo sa source code

View attachment 1883570

your posted code was not convenient to read. Post your code properly.. Ganito gawin mo sa source code

View attachment 1883570
Code:
import java.util.Arrays;
import java.util.Scanner;
public class MidtermActivity {
    static int i;
static int bagstock=10;
static int shoestock = 20;
static int shirtstock=10;
static int jeanstock=10;
static int glovestock=5;
static double total = 0, subtotal = 0;
public static void main(String[] args) {

Scanner console = new Scanner(System.in);
int quantity;
int stock[] = {bagstock=10, shoestock=20, shirtstock=10,  jeanstock=10, glovestock=5};
 String itemList[] = {"Bags", "Shoes", "Shirt", "Jeans", "Gloves"};
 double cost[] = {25.45, 67.64, 43.23, 24.12, 12.34};
 System.out.println("Stock:\t\t||Cost:");
 for(int i = 0; i<5; i++){
  System.out.println(String.valueOf(itemList[i]) + "\t" +  String.valueOf(stock[i])
                    + "\t||" + String.valueOf(cost[i]));}
 while(true){
     System.out.println("What would you like to buy? ");
     String item = console.next().toLowerCase();
 while(true){
     System.out.println("How many?");
     quantity = console.nextInt();

  if(item.contains("bag")&(stock[0]-->=quantity)){
      int bagstock = stock[0]- quantity;
       int base = bagstock - quantity;
      System.out.println(stock[0]--);
 if (bagstock >= base){
      subtotal = quantity * cost[0];
      total = total + subtotal;
       System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal);
       bagstock = bagstock - quantity;
   }else if (base <= 0){
       System.out.println("Item Out of Stock. Select another item.");
       continue;}
   }else if(item.contains("shoe") & stock[0]>=quantity){
      int shoe = stock[0] - quantity;
     int base = shoe - quantity;
      System.out.println(stock[0]--);
 if (shoe >= base){
      subtotal = quantity * cost[0];
       System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
      shoestock = shoestock - quantity;

   }else if (base <= 0){
      System.out.println("Item Out of Stock. Select another item.");
   continue;
                    }
   }else if(item.contains("shirt")& stock[0]>=quantity){
       int shirt = stock[0] - quantity;
       int  base = shirt - quantity;
      System.out.println(stock[0]--);
  if (shirt >= base){
        subtotal = quantity * cost[0];
      System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
      shirtstock = shirtstock - quantity;
  }else if (base <= 0){
      System.out.println("Item Out of Stock. Select another item.");
    continue;
                    }
 }else if(item.contains("jean")& stock[0]>=quantity){
       int  jean = stock[0] - quantity;
       int  base = jean - quantity;
      System.out.println(stock[0]--);
       if (jean >= base){
      subtotal = quantity * cost[0];
      System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;
      jeanstock = jeanstock - quantity;
  }else if (base <= 0){
      System.out.println("Item Out of Stock. Select another item.");
  continue;
      }
  }else if(item.contains("glove")& stock[0]>=quantity){
     int  glove = stock[0] - quantity;
     int  base = glove - quantity;
      System.out.println(stock[0]--);
     if (glove >= base){
         subtotal = quantity * cost[0];
          System.out.printf("Subtotal: \u20B1" + "%3.2f%n",subtotal=quantity*cost[0]);subtotal++;

  }else if (base <= 0){
        System.out.println("Item Out of Stock. Select another item.");
    continue;
                    }
  }else{
   System.out.println("Not enough stock. Try again.");
    continue;
   } break;
    }
            System.out.println("Would you like to order again? (Y/N)");
            String answer = console.next().toLowerCase();
            if(answer.contains("y")){
                continue;
            }else{
                double total = subtotal + subtotal;
                System.out.println("The total is: " + total);
                System.out.print("Input Payment: \n \u20B1");
                double pay=console.nextDouble();
                System.out.printf("Your change is: \u20B1" + "%3.2f%n",(pay-total));
                System.out.println("Would you like to make another transaction? (Y/N)");
                String sagot = console.next().toLowerCase();
                if (sagot.contains("y")){
                    int  input = stock[i]- quantity;
                    Arrays.asList(stock[i], input);
                    for(int i = 0; i<5; i++){
                        System.out.println(String.valueOf(itemList[i]) + "\t" +  String.valueOf(stock[i])
                                + "\t||" + String.valueOf(cost[i]));
                    }
                    continue;

                }
                else{
                    System.out.println("Thank you come again!");
                    System.exit(0);
                }
            }
        }
    }
}
 
Last edited:
1. Set your array properly so that it can be retrieved easily.
Code:
static String Products[][]={
        {"Bags", "10", "25.45"},
        {"Shoes", "20", "67.64"},
        {"Skirt","10", "43.23"},
    };
2. Retrieve product list
Code:
       //get product size
        int prods = Products.length; //System.out.print(prods);
       
        //Show product list
       
        System.out.printf("%-15s || %-8s", "Stocks", "Cost"); //Header
        System.out.print("\n");
        for(int i=0; i<prods; i++){
            System.out.printf("%-15s || %-8s\n", Products[i][0] + " - " + Products[i][1] , Products[i][2]);
        }
        System.out.print("\n");

3. Perform transaction
a. Setup while loop to get transaction
b. Another while loop to buy the items and compute subtotal and total
4. Display total
 
Last edited:

Similar threads

Back
Top