473,788 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inventory program

nexcompac
22 New Member
Ok, I posted a similar post but now need to jump back into it. Here is what I have been able to clean up. I am using textpad and jbuilder.

Still getting used to the whole java world and I am trying to compile a program using TextPad. Here is what I have so far.

Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * Main.java
  3.  *
  4.  * Created on July 19, 2007, 5:54 PM
  5.  *
  6.  * To change this template, choose Tools | Template Manager
  7.  * and open the template in the editor.
  8.  *
  9.  *List item number, product name, quantity, price per unit, value of product, and total value of inventory.
  10.  */
  11.  
  12.  
  13. import java.util.Scanner;//program uses class Scanner
  14.  
  15. //ShowInventory program
  16. public class ShowInventory
  17.  
  18. { //main method begins execution of java application
  19.     public static void main (String args[])
  20.         {
  21.             Scanner myScanner = new Scanner (System.in);
  22.  
  23.             //item name variable
  24.             String itemName1 = cd;//item name for inventory of music cd
  25.             String itemName2 = dvd;//item name for inventory of video media
  26.             String itemName3 = book;//item name for inventory of printed media
  27.  
  28.             //item code variable
  29.             int code1 = 1000;//item code assigned to music cds
  30.             int code2 = 2000;//item code assigned to video media
  31.             int code3 = 3000;//item code assigned to printed media
  32.  
  33.             //item quantity variable
  34.             int quantity1 = 15;//number of music cds on-hand
  35.             int quantity2 = 11;//number of video media on-hand
  36.             int quantity3 = 27;//number of printed media on-hand
  37.  
  38.             //price of media variable
  39.             double price1 = 14.99;//assigned price of music cd
  40.             double price2 = 19.99;//assigned price of video media
  41.             double price3 = 12.99;//assigned price of printed media
  42.  
  43.  
  44.             //cd
  45.  
  46.             class CD
  47.             {
  48.               private String name;
  49.               private int itemCode;
  50.               private int itemQuantity;
  51.               private double itemPrice;
  52.  
  53.               //constructor to initialize the item with the information provided
  54.               public CD(String name, int itemCode, int itemQuantity, double itemPrice)
  55.               {
  56.                   setName(name);
  57.                   setItemCode(itemCode);
  58.                   setItemQuantity(itemQuantity);
  59.                   setItemPrice(itemPrice);
  60.               }
  61.  
  62.               //get item name
  63.               public String getName()
  64.               {
  65.                   return this.name;
  66.               }
  67.  
  68.               //set item name
  69.               private void setName(String name)
  70.               {
  71.                   this.name = name;
  72.               }
  73.  
  74.               //set item code
  75.               private void setItemCode(int itemCode)
  76.               {
  77.                   this.itemCode = itemCode;
  78.               }
  79.  
  80.               //set item quantity
  81.               private void setItemQuantity(int itemQuantity)
  82.               {
  83.                   this.itemQuantity = itemQuantity;
  84.               }
  85.  
  86.               //set price of item
  87.               private void setItemPrice (double itemPrice)
  88.               {
  89.                   this.itemPrice = itemPrice;
  90.               }
  91.  
  92.               //calculate value of item on-hand
  93.               public double getItemValue()
  94.               {
  95.                   return this.itemQuantity * this.itemPrice;
  96.               }
  97.  
  98.  
  99.             //DVD
  100.             class DVD
  101.             {
  102.               private String name;
  103.               private int itemCode;
  104.               private int itemQuantity;
  105.               private double itemPrice;
  106.  
  107.               //constructor to initialize the item with the information provided
  108.               public DVD(String name, int itemCode, int itemQuantity, double itemPrice)
  109.               {
  110.                   setName(name);
  111.                   setItemCode(itemCode);
  112.                   setItemQuantity(itemQuantity);
  113.                   setItemPrice(itemPrice);
  114.               }
  115.  
  116.               //get item name
  117.               public String getName()
  118.               {
  119.                   return this.name;
  120.               }
  121.  
  122.               //set item name
  123.               private void setName(String name)
  124.               {
  125.                   this.name = name;
  126.               }
  127.  
  128.               //set item code
  129.               private void setItemCode(int itemCode)
  130.               {
  131.                   this.itemCode = itemCode;
  132.               }
  133.  
  134.               //set item quantity
  135.               private void setItemQuantity(int itemQuantity)
  136.               {
  137.                   this.itemQuantity = itemQuantity;
  138.               }
  139.  
  140.               //set price of item
  141.               private void setItemPrice (double itemPrice)
  142.               {
  143.                   this.itemPrice = itemPrice;
  144.               }
  145.  
  146.               //calculate value of item on-hand
  147.               public double getItemValue()
  148.               {
  149.                   return this.itemQuantity * this.itemPrice;
  150.               }
  151.  
  152.             //book
  153.             class Book
  154.             {
  155.               private String name;
  156.               private int itemCode;
  157.               private int itemQuantity;
  158.               private double itemPrice;
  159.  
  160.               //constructor to initialize the item with the information provided
  161.               public Book(String name, int itemCode, int itemQuantity, double itemPrice)
  162.               {
  163.                   setName(name);
  164.                   setItemCode(itemCode);
  165.                   setItemQuantity(itemQuantity);
  166.                   setItemPrice(itemPrice);
  167.               }
  168.  
  169.               //get item name
  170.               public String getName()
  171.               {
  172.                   return this.name;
  173.               }
  174.  
  175.               //set item name
  176.               private void setName(String name)
  177.               {
  178.                   this.name = name;
  179.               }
  180.  
  181.               //set item code
  182.               private void setItemCode(int itemCode)
  183.               {
  184.                   this.itemCode = itemCode;
  185.               }
  186.  
  187.               //set item quantity
  188.               private void setItemQuantity(int itemQuantity)
  189.               {
  190.                   this.itemQuantity = itemQuantity;
  191.               }
  192.  
  193.               //set price of item
  194.               private void setItemPrice (double itemPrice)
  195.               {
  196.                   this.itemPrice = itemPrice;
  197.               }
  198.  
  199.               //calculate value of item on-hand
  200.               public double getItemValue()
  201.               {
  202.                   return this.itemQuantity * this.itemPrice;
  203.               }
  204.  
  205.               //calculate combined value of all inventory
  206.               double inventoryValue = cdItemPrice + dvdItemPrice + bookItemPrice;
  207.  
  208.  
  209.  
  210.               //build array to house data
  211.               //InitInventory.java
  212.         public class InitInventory
  213.  
  214.         //initializer list specifies the value for each element
  215.         {
  216.          String inventory[] = {CD, DVD, Book};
  217.          int itemcode [] = {1000, 2000, 3000};
  218.          int itemquantity [] = {15,11,27};
  219.          double itemprice [] = {14.99, 19.99, 12.99};
  220.          double itemvalue [] = {15*14.99, 11*19.99, 27*12.99};
  221.  
  222.          System.out.printf("%s&s\n", "Index", "Value");//column headings
  223.  
  224.          //output each array elements value
  225.          for (String counter = 0; counter < array.length; counter ++)
  226.              System.out.printf("%5d%8d\n", counter, array[counter]);
  227.  
  228.          for (int counter = 0; counter < array.length; counter ++)
  229.              System.out.printf("%5d%8d\n", counter, array[counter]);
  230.  
  231.          for (double counter = 0; counter < array.length; counter ++)
  232.              System.out.printf("%5d%8d\n", counter, array[counter]);
  233.          }//end class InitInventory
  234.  
  235.     }//end main
  236.  
  237.  
  238. }//end ShowInventory
  239.  
  240.  

Now I seem to be getting 18 errors. Which sucks. Here are the errors.

Here are the errors in more detail.

Expand|Select|Wrap|Line Numbers
  1. C:\Users\Brian\Documents\ShowInventory.java:222: <identifier> expected
  2.          System.out.printf("%s&s\n", "Index", "Value");//column headings
  3.                           ^
  4. C:\Users\Brian\Documents\ShowInventory.java:222: illegal start of type
  5.          System.out.printf("%s&s\n", "Index", "Value");//column headings
  6.                            ^
  7. C:\Users\Brian\Documents\ShowInventory.java:225: illegal start of type
  8.          for (String counter = 0; counter < array.length; counter ++)
  9.          ^
  10. C:\Users\Brian\Documents\ShowInventory.java:225: > expected
  11.          for (String counter = 0; counter < array.length; counter ++)
  12.                                                         ^
  13. C:\Users\Brian\Documents\ShowInventory.java:225: <identifier> expected
  14.          for (String counter = 0; counter < array.length; counter ++)
  15.                                                                  ^
  16. C:\Users\Brian\Documents\ShowInventory.java:226: <identifier> expected
  17.              System.out.printf("%5d%8d\n", counter, array[counter]);
  18.                               ^
  19. C:\Users\Brian\Documents\ShowInventory.java:226: illegal start of type
  20.              System.out.printf("%5d%8d\n", counter, array[counter]);
  21.                                ^
  22. C:\Users\Brian\Documents\ShowInventory.java:228: illegal start of type
  23.          for (int counter = 0; counter < array.length; counter ++)
  24.          ^
  25. C:\Users\Brian\Documents\ShowInventory.java:228: > expected
  26.          for (int counter = 0; counter < array.length; counter ++)
  27.                                                      ^
  28. C:\Users\Brian\Documents\ShowInventory.java:228: <identifier> expected
  29.          for (int counter = 0; counter < array.length; counter ++)
  30.                                                               ^
  31. C:\Users\Brian\Documents\ShowInventory.java:229: <identifier> expected
  32.              System.out.printf("%5d%8d\n", counter, array[counter]);
  33.                               ^
  34. C:\Users\Brian\Documents\ShowInventory.java:229: illegal start of type
  35.              System.out.printf("%5d%8d\n", counter, array[counter]);
  36.                                ^
  37. C:\Users\Brian\Documents\ShowInventory.java:231: illegal start of type
  38.          for (double counter = 0; counter < array.length; counter ++)
  39.          ^
  40. C:\Users\Brian\Documents\ShowInventory.java:231: > expected
  41.          for (double counter = 0; counter < array.length; counter ++)
  42.                                                         ^
  43. C:\Users\Brian\Documents\ShowInventory.java:231: <identifier> expected
  44.          for (double counter = 0; counter < array.length; counter ++)
  45.                                                                  ^
  46. C:\Users\Brian\Documents\ShowInventory.java:232: <identifier> expected
  47.              System.out.printf("%5d%8d\n", counter, array[counter]);
  48.                               ^
  49. C:\Users\Brian\Documents\ShowInventory.java:232: illegal start of type
  50.              System.out.printf("%5d%8d\n", counter, array[counter]);
  51.                                ^
  52. C:\Users\Brian\Documents\ShowInventory.java:238: reached end of file while parsing
  53. }//end ShowInventory
  54.  ^
  55. 18 errors
  56.  
  57. Tool completed with exit code 1
  58.  
Any help would be welcome :confused:
Jul 27 '07 #1
4 2312
JosAH
11,448 Recognized Expert MVP
Your curly brackets don't match, i.e. not every { has a matching }.

kind regards,

Jos
Jul 27 '07 #2
nexcompac
22 New Member
What is the best way to keep track and fix my brackets?
Jul 27 '07 #3
r035198x
13,262 MVP
What is the best way to keep track and fix my brackets?
Indent your code well and use an editor that helps you to format your code nicely.
Jul 27 '07 #4
JoeMac3313
16 New Member
If your instructor has you use command line try using Notepad++, when you place your cursor over a curly brace it will red out the match.
Jul 29 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

13
3998
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate button "Unexpected Error":3251 operation is not supported for this type of object.The demo cd has two databases, one is called inventory and the other just has the tables for the design called inventory data. When you run inventory the database works...
109
25898
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the assignments... 4. CheckPoint: Inventory Program Part 1 • Resource: Java: How to Program • Due Date: Day 5 forum • Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD...
0
7116
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past the due date 10% of the grade is taken off. I think I'm coming down with the flu and my brain is just not processing this assignment. Here is the assignment: Modify the Inventory program by adding a button to the GUI that allows the user to move...
9
7612
by: xxplod | last post by:
I am suppose 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. • Create a method to calculate...
3
7010
by: cblank | last post by:
I need some help if someone could help me. I know everyone is asking for help in java. But for some reason I'm the same as everyone else when it comes to programming in java. I have an inventory program that I have built so far with no problem. But I cannot figure out how to turn it into a GUI application. This is what I'm trying to get it to do. Modify the Inventory Program to use a GUI. The GUI should display the information one product...
2
2543
by: pinkf24 | last post by:
I cannot figure out how to add the following: Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the number of units in stock, and the price of each unit. An item added to the inventory should have an item number one more than the previous last item. Add a Save button to the GUI that saves the...
1
2661
by: jcato77 | last post by:
I need help with a class project I'm working on, Below is my assignment and the code I have currently created. Assignment: Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method...
3
4487
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI 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 GUI should display the value of the entire inventory, the additional attribute, and the restocking fee. Here is my Inventory program from 1 to 3: package...
2
4447
by: blitz1989 | last post by:
Hello all, I'm new to this forum and Java and having a alot of problems understanding this language. I am working on an invetory program part 4. The assignment requirements are listed but the reading has very little in it that helps can someone take a look at this code and point me in the right direction please. Thanks for any help that is offered. //Modify the Inventory Program to use a GUI. The GUI should display the //informationone...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.