I am learning java and want to make a small inventory management and which operates a menu in which there are 4 options:
- View item
- Sell Item
- Place Order
- Exit
I specifically want to do it with the help of while loop. I made the methods for the menu actions but when i call it in the while loop, it is not giving the desired result except when i press 1 to view product.
public class Item {
private double cost,OrderPoint,AmountOnHand,PercentMarkup,OrderQuantity;
private String NameOfItem, Supplier;
Item(String NameOfItem,double cost,double PercentMarkup,String Supplier,double OrderQuantity,double OrderPoint,double AmountOnHand){
this.NameOfItem=NameOfItem;
this.cost=cost;
this.PercentMarkup=PercentMarkup;
this.Supplier=Supplier;
this.OrderQuantity=OrderQuantity;
this.OrderPoint=OrderPoint;
this.AmountOnHand=AmountOnHand;
}
public String getNameOfItem()
{
return NameOfItem;
}
public String setNameOfItem()
{
return NameOfItem;
}
public double getCost()
{
return cost;
}
public double setCost()
{
return cost;
}
public String getSupplier()
{
return Supplier;
}
public String setSupplier()
{
return Supplier;
}
public double getOrderPoint()
{
return OrderPoint;
}
public double setOrderPoint()
{
return OrderPoint;
}
public double getAmountOnHand()
{
return AmountOnHand;
}
public double setAmountOnHand()
{
return AmountOnHand;
}
public double getPercentMarkup()
{
return PercentMarkup;
}
public double setPercentMarkup()
{
return PercentMarkup;
}
public double getOrderQuantity()
{
return OrderQuantity;
}
public double setOrderQuantity()
{
return OrderQuantity;
}
public double PlaceOrder(){
if(AmountOnHand<5)
AmountOnHand+=20;
return AmountOnHand;
}
public double SellItem() {
if(AmountOnHand>0)
AmountOnHand-=1;
return AmountOnHand;
}
public String toString()
{
String str="Name Of Item:" + this.getNameOfItem()+"\n";
str=str+"Supplier:" +this.getSupplier()+"\n";
str=str+"cost=" +this.cost+ "\n";
str=str+"OrderPoint= " + this.OrderPoint+ "\n";
str=str+"Amount On Hand= " +this.getAmountOnHand()+"\n";
str=str+"PercentMarkup:"+this.getPercentMarkup()+"\n";
str=str+"Order Quantity:" +this.getOrderQuantity()+"\n" ;
return str;
}
}
MAIN method:
public class ItemTest{
public static void main(String [] args) {
Item product = new Item("Wrench",15,15%10+15,"Craftsmen Tool",20,5,4);
System.out.println("Enter a Number");
Scanner myScanner = new Scanner(System.in);
int x=0;
int choice = menu();
while(choice !=4) {
System.out.println("Enter a number");
int aNumber= myScanner.nextInt();
if (aNumber==1) {
System.out.println("You entered"+product.toString());
choice=menu();
}
else if (aNumber==2) {
System.out.println("You entered 2"+product.SellItem());
choice=menu();
}
else if (aNumber==3) {
System.out.println("You entered 3"+product.PlaceOrder());
choice=menu();
}
else
{
System.out.println("Thanks for Visiting");
}
}
}
private static int menu() {
Scanner aScanner = new Scanner(System.in);
int response=aScanner.nextInt();
return response;
}
}
Any help is appreciated. Thanks