package ctowerinventory; /* * @(#)CtowerInventory.java * * CtowerInventory application * * @author Craig Tower * @version 1.00 2008/2/22 */ /** * Non-GUI Based Java Application that Inventories * a Product and its * Name,ID,Price,and Number of Units * CTower */ // Program uses class Scanner import java.util.Scanner; public class CtowerInventory { private static Object myProduct; public static void main( String args[] ) //Main method {// While Start and Second Class Introduction { // Introduction System.out.println ("Inventory Program\nPart 1" + ""); } // CtowerProduct myProduct = new CtowerProduct("",0,"",0,0); //Constructor Declaration and Initialization //Boolean variable to terminate program boolean stop = false; while (!stop) { // create Scanner Scanner input = new Scanner( System.in ); // Begin Interegation of User System.out.print( " Please Enter Product ID Number or stop to End Program: " ); myProduct.setNum(input.nextLine()); if (myProduct.getunitNum().equalsIgnoreCase("stop"))//Retrieve from class CtowerProduct //Bolean Variable if/else result variable 'stop' { System.out.print( " The program is now complete Thank You " ); stop = true; } else //Bolean Variable if/else result variable 'myProduct.getunitNum' { System.out.println(); //SPACE System.out.print( " Please Enter Product Value: " ); myProduct.setunitPrice(input.nextFloat()); while (myProduct.getunitPrice() <=0)//Positive Number Check //Retrieve from class CtowerProduct { System.out.println(); //SPACE System.out.println( " Product Value Must be a Positive Number: " ); System.out.println(); //SPACE System.out.println( " Please Enter Product Value Again: " ); myProduct.setunitPrice(input.nextFloat()); System.out.println(); //SPACE } { System.out.println(); //SPACE System.out.print( " Please Enter Product Name: " ); myProduct.setunitName(input.nextLine()); } System.out.println(); //SPACE System.out.print( " Please Enter the Number of These Products in Inventory: " ); myProduct.setunitTotal(input.nextFloat()); while (myProduct.getunitTotal() <=0)//Positive Number Check //Retrieve from class CtowerProduct { System.out.println(); //SPACE System.out.println( " Total Number of Products Must be a Positive Number: " ); System.out.println(); //SPACE System.out.print( " Please Enter the Number of These Products in Inventory Again: " ); myProduct.setunitTotal(input.nextFloat()); System.out.println(); //SPACE } System.out.println(); //SPACE System.out.println(); //SPACE System.out.println(myProduct.getunitNum());//Retrieve from class CtowerProduct System.out.println(); //SPACE System.out.printf( "Value of Inventory is $%.2f",myProduct.unitTotalValue());//Retrieve from class CtowerProduct System.out.println(); //SPACE System.out.println(); //SPACE } } } } //End Class class CtowerProduct {//Start Class private float unitTotalValue; private float unitPrice; private float unitTotal; private String unitNum; private String unitName; //Constructor //Constructor public CtowerProduct(String punitNum, float punitPrice, String punitName, float punitTotal, float punitTotalValue) { unitNum = punitNum; unitPrice = punitPrice; unitName = punitName; unitTotal = punitTotal; unitTotalValue = punitTotalValue; } //End Constructor public void setNum (String unitNum) //Store Declaration { this.unitNum = unitNum; //Store Method } public String getunitNum() { return unitNum; } public void setunitPrice (float unitPrice) //Store Declaration { this.unitPrice = unitPrice; //Store Method } public float getunitPrice () { return unitPrice; } public void setunitName (String unitName) //Store Declaration { this.unitName = unitName; //Store Method } public String getunitName() { return unitName; } public void setunitTotal (float unitTotal) //Store Declaration { this.unitTotal = unitTotal; //Store Method } public float getunitTotal () { return unitTotal; } public float unitTotalValue () // Total Value of All Units Calculation { return unitPrice * unitTotal; } }//End Class