|
||
|
|||
|
Hello everyone, I'm currently making a program that is going to be designed to keep track of inventory for a near by church pantry. I'm using ArrayList to keep track of the ingredients and the type of unit they are stored in. For example: " One gallon-the unit of milk-the ingredient" And I'm making a user interface for the person behind the counter so she can use it easily, so I've made a method to contain that. Here's what I have so far in main:
Java Code
import java.util.*;
public class Driver {
Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
}
public void menu()
{
ArrayList ingredients = new ArrayList();
int menuChoice;
System.out.println("Please select an option");
System.out.println("1)Add inventory");
System.out.println("2)Stock inventory");
System.out.println("3)Use ingredients");
System.out.println("4)Display ingredients");
System.out.println("5)Exit program");
menuChoice = keyboard.nextInt();
if(menuChoice < 1 || menuChoice > 5)
System.out.println("Invalid please try again");
menuChoice = keyboard.nextInt();
if(menuChoice==1)
//S.O.P "What type of ingredient would you like to add"
//S.O.P "What type of unit is "ingredient" stored in"
//S.O.P "How many "units" of "ingredient" do you have"
else if(menuChoice==2)
//S.O.P "What type of ingredient would you like to add?"
//S.O.P "How many "units" of "ingredient" would you like to add"?
else if (menuChoice==3)
//S.O.P "What type of ingredient are you wanting to use?"
//S.O.P "How many "units" of "ingredient" are you wanting to use?
else if (menuChoice==4)
System.out.println(ingredients);
else
System.out.println("Thank you for using the Ingredient Manager");
|
|
|||
|
Okay after much thought and deliberation over this thing here's what I have accomplished:
Java Code
import java.util.*;
public class Driver {
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
ArrayList <Inventory>ingredients = new ArrayList<Inventory>();
String name;
String measurement;
int units;
int menuChoice=menu();
int i;
int addOn;
while(menuChoice!=5)
{
if(menuChoice==1)
{
System.out.println("What type of ingredient would you like to add?");
name=keyboard.nextLine();
System.out.println("What is "+name+" measured in?");
measurement=keyboard.nextLine();
System.out.println("");
System.out.println("How many "+measurement+" of "+name+" do you have?");
units=keyboard.nextInt();
keyboard.nextLine();
System.out.println("");
Inventory foodItem = new Inventory(name, measurement, units);
ingredients.add(foodItem);
}
else if(menuChoice==2)
{
for(i=0; i<ingredients.size(); i++)
{
System.out.println(i +") "+ingredients.get(i).toString());
}
System.out.println("What would you like to add to?");
int x = keyboard.nextInt();
addOn=ingredients.get(x).getUnits();
System.out.println("How many "+ingredients.get(x).getMeasurment()+" would you like to stock?");
addOn+=keyboard.nextInt();
ingredients.get(x).setUnits(addOn);
}
else if (menuChoice==3)
{
for(i=0; i<ingredients.size(); i++)
{
System.out.println(i +") "+ingredients.get(i).toString());
}
System.out.println("Which item would you like to use?");
int x = keyboard.nextInt();
addOn=ingredients.get(x).getUnits();
System.out.println("How many "+ingredients.get(x).getMeasurment()+" would you like to use?");
addOn-=keyboard.nextInt();
ingredients.get(x).setUnits(addOn);
}
else if (menuChoice==4)
{
for(i=0; i<ingredients.size(); i++)
System.out.println(ingredients.get(i).toString());
}
menuChoice=menu();
}
}
public static int menu()
{
Scanner keyboard = new Scanner(System.in);
int menuChoice;
System.out.println("Please select an option");
System.out.println("1)Add inventory");
System.out.println("2)Stock inventory");
System.out.println("3)Use ingredients");
System.out.println("4)Display ingredients");
System.out.println("5)Exit program");
menuChoice = keyboard.nextInt();
while(menuChoice < 1 || menuChoice > 5)
{
System.out.println("Invalid please try again");
menuChoice = keyboard.nextInt();
}
return menuChoice;
}
}
Java Code
public class Inventory
{
int units;
String name;
String measurment;
public Inventory(String nameIn,String measurmentIn, int unitsIn)
{
name=nameIn;
measurment=measurmentIn;
units=unitsIn;
}
public int getUnits() {
return units;
}
public void setUnits(int units) {
this.units = units;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMeasurment() {
return measurment;
}
public void setMeasurment(String measurment) {
this.measurment = measurment;
}
public String toString()
{
String foodInfo="you have "+units+" "+measurment+" of "+name;
return foodInfo;
}
}
Also once again, any comments, suggestions to improve, and any catch in an error would be very much appreciated <3. Thanks again |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help making program | ixjaybeexi | Collections and Generics | 5 | 07-12-2009 03:36 AM |
| Arraylist or Arraylist Object? | igniteflow | Collections and Generics | 2 | 11-09-2009 07:08 AM |
| [SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int?? | igniteflow | Collections and Generics | 2 | 16-08-2009 06:11 PM |
| How to use an ArrayList - java.util.ArrayList | JavaPF | Java Code Snippets and Tutorials | 1 | 17-05-2009 06:12 PM |
| [ASK]making a map | donjuan | AWT / Java Swing | 3 | 15-05-2009 08:32 AM |
|
100 most searched terms
Search Cloud
|
| 2d arraylist java actionlistener actionlistener in java actionlistener java addactionlistener addactionlistener in java addactionlistener java applications of oops could not create java virtual machine xp double format java double to int double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java java 2d arraylist java actionlistener java addactionlistener java convert list to map java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming help java sendkeys java two dimensional arraylist java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics two dimensional arraylist java writing ipod apps |