Assignment: Online ordering System
Now it has been suggested that I use ArrayList, but unfortunately that's not an option as I haven't gotten to it yet
import java.util.Scanner;
import java.util.*;
public class OnlineOrderingSystem {
public static void main(String[] args) {
String product[] = { "PD1", "PD2","PD3","PD4","PD5","PD6","PD7","PD8","PD9","PD10"};
double price[] = {5.99,10.99,32.99,3.99,54.99,64.99,29.99,19.99,23.99,84.99};
int stock[] = {32,28,10,104,95,14,2,0,14,3};
Scanner kb = new Scanner(System.in);
int i,p,number;
String storage[] = new String[10];
boolean found = false;
String answer;
System.out.println("Welcome to the Online Ordering System!\nTake a look at our product!");
for(String s : product)
System.out.print(s + " ");
for(i = 0; i<storage.length;i++){
System.out.println("\n\nWhich product would you like to order?");
storage[i] = kb.next();
for(p = 0; p < product.length - 1; p++) {
if(product[p].toLowerCase().equals(storage[i]))
found = true;
break;
}
if(found)
System.out.println("We carry it!");
System.out.print("How many do you want?");
number = kb.nextInt();
for(number : )
}
}
}
Now I know what this code says: if storage[index] = product[index] then found = true. This doesn't help. After realizing that if I type anything other then PD1, I'll always get a false. Why isn't product incrementing >< What I want to do is get the arrays to compare to each other. I just can't seem to get that to happen.
Here's what I tried:
System.out.println("\n\nWhich product would you like to order?");
storage[i] = kb.next();
for(storage[i] : product){
if(storage[i] == product){
found = true;
break;
}
}
if(found)
System.out.println("We carry it!");
else
System.out.println("We do not carry that item, sorry!");
System.exit(0); //temporary exit point NOT PERMANENT
}
This doesn't work because the storage array became a problem (please understand it's late and I've been at this for hours so hopefully after a nights rest things will come to me).
The code I was trying to mimic came from my text which was;
for(int x : nums) {
if(x == val){
found = truel
break;
}
}
if (found)
System.out.println("Value found!");
OK these are my goals. To get the program to verify that the product is carried, in stock and how many the customer wants. As I type this I'm not even sure why I wrote this code like this, I think it's best if I create sub-classes. What I really want to know though at this moment is why I can't compare the storage array and the product array.

New Topic/Question
Reply



MultiQuote








|