Results 1 to 8 of 8
- 04-06-2011, 01:48 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 15
- Rep Power
- 0
Need Help please don't know where to start.
:confused:I need help with my program for my intro to Java class. I have the first part of the assignment running perfectly, now I have to Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
I have read my book, but it makes no sence to me. Can someone please help me figure this out?
My code is below.
Java Code:package product; import java.util.Scanner;// program uses class Scanner public class product { // main method begins execution of Java application public static void main(String[] args) { // Multiplication program to calculate payroll // create Scanner to obtain input from command window Scanner input = new Scanner(System.in); boolean enterMoreData = true; String proName; while(enterMoreData){ //get product name or stop program System.out.print("Enter product name or stop to quit: " ); proName = input.nextLine(); if (proName.equalsIgnoreCase("stop")) { System.out.println(" Good bye! Thank You for using inventory organizer."); System.exit(0);} // get product number int proNumber; do { System.out.println(" Please enter the product identification number for inventory: "); proNumber = input.nextInt(); if (proNumber < 0) { System.out.println("number must be positive, please try again. "); } } while (proNumber < 0); int proQuant; // get product quantity in inventory do { System.out.println(" Please enter the quantity of product in inventory: "); proQuant = input.nextInt(); if (proQuant < 0) { System.out.println("number must be positive, please try again. "); } } while ( proQuant < 0); double proPrice; // get product do { System.out.println("Please enter product price: "); proPrice = input.nextDouble(); if (proPrice < 0) { System.out.println("number must be positive, please try again."); } } while ( proPrice < 0); Item item = new Item (proName, proNumber, proQuant, proPrice); System.out.printf("Product name is: %s\n Product number is : %.2f\n " + "Product quantity in stock is: %.2f\n Product price is: %.2f\n Total of products" + " in inventory is: $ %.2f\n ", item.proName, item.proNumber, item.proQuantity, item.proPrice, item.getproTotal()); proName = input.nextLine(); }// end while } //end method main } //end class product class Item //creat new class Product { //input variables String proName; double proNumber; double proQuantity; double proPrice; double proTotal; // Get input public Item(String name, double number, double quant, double price) { this.proName = name; this.proNumber = number; this.proQuantity = quant; this.proPrice = price; computeproTotal(); } // method to compute proTotal private void computeproTotal() { proTotal = proQuantity * proPrice; } // method to get Total public double getproTotal() { return proTotal; } }// end class Product
- 04-06-2011, 01:52 PM #2
Some recommended reading:
Starting Writing a Program
Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-06-2011, 02:01 PM #3
Are you asking how to use Arrays?
- 04-06-2011, 02:45 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 15
- Rep Power
- 0
Dark, Yes I am asking how to use arrays and implement them into my program.
Kevin Workman, thank you for the links I will check them out right now.
- 04-06-2011, 05:01 PM #5
Doesn't Inventory season fall in September?
- 04-06-2011, 10:14 PM #6
Member
- Join Date
- Apr 2011
- Posts
- 15
- Rep Power
- 0
For some reason, the String variables are not being recognized. Could someone give me a hint as to why? My code is below that I have so far.
Java Code:package inventory; // This program displays inventory /** * * @author Julie */ public class inventory { public static void main(String[] args) { // TODO code application logic here { String[] ProductName = new String[5]; ProductName[0] = CD; ProductName[1] = Shirt; ProductName[2] = Pants; ProductName[3] = Hat; ProductName[4] = Shoes; } { int[] ProductNumber = new int [5]; ProductNumber[0] = 2525; ProductNumber[1] = 2526; ProductNumber[2] = 2527; ProductNumber[3] = 2528; ProductNumber[4] = 2529;} { int ProductQuantity [] = new int [5]; ProductQuantity[0] = 4; ProductQuantity[1] = 6; ProductQuantity[2] = 15; ProductQuantity[3] = 4; ProductQuantity[4] = 3; } { double ProductPrice[] = new double[5]; ProductPrice[0] = 14.99; ProductPrice[1] = 12.58; ProductPrice[2] = 22.58; ProductPrice[3] = 10.72; ProductPrice[4] = 52.58; } }// end main }//end class inventory
- 04-06-2011, 10:15 PM #7
Member
- Join Date
- Jan 2011
- Location
- Gainesville, FL
- Posts
- 45
- Rep Power
- 0
Strings should be in quotations.
String s = "Welcome to Java!";
- 04-06-2011, 11:30 PM #8
Member
- Join Date
- Apr 2011
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
Where to start - GUI
By matejm1994 in forum New To JavaReplies: 2Last Post: 01-30-2011, 05:02 PM -
Start Swing GUI program by Java Web Start with IE in Eclipse debug mode
By albertkao in forum EclipseReplies: 1Last Post: 01-18-2011, 06:27 PM -
How do you start a Java program from the "Start" menu under Windows?
By ScottVal in forum New To JavaReplies: 5Last Post: 03-20-2009, 10:04 PM -
Where to start?
By McChill in forum New To JavaReplies: 5Last Post: 02-19-2009, 02:26 PM -
Web Start
By DannyZB in forum NetBeansReplies: 0Last Post: 11-14-2008, 12:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks