Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-27-2007, 08:05 AM
Member
 
Join Date: Jul 2007
Posts: 5
Nexcompac is on a distinguished road
Inventory program
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.

Code:
/* * Main.java * * Created on July 19, 2007, 5:54 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. * *List item number, product name, quantity, price per unit, value of product, and total value of inventory. */ import java.util.Scanner;//program uses class Scanner //ShowInventory program public class ShowInventory { //main method begins execution of java application public static void main (String args[]) { Scanner myScanner = new Scanner (System.in); //item name variable String itemName1 = cd;//item name for inventory of music cd String itemName2 = dvd;//item name for inventory of video media String itemName3 = book;//item name for inventory of printed media //item code variable int code1 = 1000;//item code assigned to music cds int code2 = 2000;//item code assigned to video media int code3 = 3000;//item code assigned to printed media //item quantity variable int quantity1 = 15;//number of music cds on-hand int quantity2 = 11;//number of video media on-hand int quantity3 = 27;//number of printed media on-hand //price of media variable double price1 = 14.99;//assigned price of music cd double price2 = 19.99;//assigned price of video media double price3 = 12.99;//assigned price of printed media //cd class CD { private String name; private int itemCode; private int itemQuantity; private double itemPrice; //constructor to initialize the item with the information provided public CD(String name, int itemCode, int itemQuantity, double itemPrice) { setName(name); setItemCode(itemCode); setItemQuantity(itemQuantity); setItemPrice(itemPrice); } //get item name public String getName() { return this.name; } //set item name private void setName(String name) { this.name = name; } //set item code private void setItemCode(int itemCode) { this.itemCode = itemCode; } //set item quantity private void setItemQuantity(int itemQuantity) { this.itemQuantity = itemQuantity; } //set price of item private void setItemPrice (double itemPrice) { this.itemPrice = itemPrice; } //calculate value of item on-hand public double getItemValue() { return this.itemQuantity * this.itemPrice; } //DVD class DVD { private String name; private int itemCode; private int itemQuantity; private double itemPrice; //constructor to initialize the item with the information provided public DVD(String name, int itemCode, int itemQuantity, double itemPrice) { setName(name); setItemCode(itemCode); setItemQuantity(itemQuantity); setItemPrice(itemPrice); } //get item name public String getName() { return this.name; } //set item name private void setName(String name) { this.name = name; } //set item code private void setItemCode(int itemCode) { this.itemCode = itemCode; } //set item quantity private void setItemQuantity(int itemQuantity) { this.itemQuantity = itemQuantity; } //set price of item private void setItemPrice (double itemPrice) { this.itemPrice = itemPrice; } //calculate value of item on-hand public double getItemValue() { return this.itemQuantity * this.itemPrice; } //book class Book { private String name; private int itemCode; private int itemQuantity; private double itemPrice; //constructor to initialize the item with the information provided public Book(String name, int itemCode, int itemQuantity, double itemPrice) { setName(name); setItemCode(itemCode); setItemQuantity(itemQuantity); setItemPrice(itemPrice); } //get item name public String getName() { return this.name; } //set item name private void setName(String name) { this.name = name; } //set item code private void setItemCode(int itemCode) { this.itemCode = itemCode; } //set item quantity private void setItemQuantity(int itemQuantity) { this.itemQuantity = itemQuantity; } //set price of item private void setItemPrice (double itemPrice) { this.itemPrice = itemPrice; } //calculate value of item on-hand public double getItemValue() { return this.itemQuantity * this.itemPrice; } //calculate combined value of all inventory double inventoryValue = cdItemPrice + dvdItemPrice + bookItemPrice; //build array to house data //InitInventory.java public class InitInventory //initializer list specifies the value for each element { String inventory[] = {CD, DVD, Book}; int itemcode [] = {1000, 2000, 3000}; int itemquantity [] = {15,11,27}; double itemprice [] = {14.99, 19.99, 12.99}; double itemvalue [] = {15*14.99, 11*19.99, 27*12.99}; System.out.printf("%s&s\n", "Index", "Value");//column headings //output each array elements value for (String counter = 0; counter < array.length; counter ++) System.out.printf("%5d%8d\n", counter, array[counter]); for (int counter = 0; counter < array.length; counter ++) System.out.printf("%5d%8d\n", counter, array[counter]); for (double counter = 0; counter < array.length; counter ++) System.out.printf("%5d%8d\n", counter, array[counter]); }//end class InitInventory }//end main }//end ShowInventory

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

Here are the errors in more detail.

Code:
C:\Users\Brian\Documents\ShowInventory.java:222: <identifier> expected System.out.printf("%s&s\n", "Index", "Value");//column headings ^ C:\Users\Brian\Documents\ShowInventory.java:222: illegal start of type System.out.printf("%s&s\n", "Index", "Value");//column headings ^ C:\Users\Brian\Documents\ShowInventory.java:225: illegal start of type for (String counter = 0; counter < array.length; counter ++) ^ C:\Users\Brian\Documents\ShowInventory.java:225: > expected for (String counter = 0; counter < array.length; counter ++) ^ C:\Users\Brian\Documents\ShowInventory.java:225: <identifier> expected for (String counter = 0; counter < array.length; counter ++) ^ C:\Users\Brian\Documents\ShowInventory.java:226: <identifier> expected System.out.printf("%5d%8d\n", counter, array[counter]); ^ C:\Users\Brian\Documents\ShowInventory.java:226: illegal start of type System.out.printf("%5d%8d\n", counter, array[counter]); ^ C:\Users\Brian\Documents\ShowInventory.java:228: illegal start of type for (int counter = 0; counter < array.length; counter ++) ^ C:\Users\Brian\Documents\ShowInventory.java:228: > expected for (int counter = 0; counter < array.length; counter ++) ^ C:\Users\Brian\Documents\ShowInventory.java:228: <identifier> expected for (int counter = 0; counter < array.length; counter ++) ^ C:\Users\Brian\Documents\ShowInventory.java:229: <identifier> expected System.out.printf("%5d%8d\n", counter, array[counter]); ^ C:\Users\Brian\Documents\ShowInventory.java:229: illegal start of type System.out.printf("%5d%8d\n", counter, array[counter]); ^ C:\Users\Brian\Documents\ShowInventory.java:231: illegal start of type for (double counter = 0; counter < array.length; counter ++) ^ C:\Users\Brian\Documents\ShowInventory.java:231: > expected for (double counter = 0; counter < array.length; counter ++) ^ C:\Users\Brian\Documents\ShowInventory.java:231: <identifier> expected for (double counter = 0; counter < array.length; counter ++) ^ C:\Users\Brian\Documents\ShowInventory.java:232: <identifier> expected System.out.printf("%5d%8d\n", counter, array[counter]); ^ C:\Users\Brian\Documents\ShowInventory.java:232: illegal start of type System.out.printf("%5d%8d\n", counter, array[counter]); ^ C:\Users\Brian\Documents\ShowInventory.java:238: reached end of file while parsing }//end ShowInventory ^ 18 errors Tool completed with exit code 1
Any help would be welcome
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-27-2007, 02:27 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
As far as i know, the method was not System.out.printf. It was System.out.println?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-27-2007, 03:25 PM
Member
 
Join Date: Jul 2007
Posts: 5
Nexcompac is on a distinguished road
Quote:
Originally Posted by levent View Post
As far as i know, the method was not System.out.printf. It was System.out.println?
Where can I go to get the key words to define what I want specificly?

I will try changing that up and see what results. Thanks
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-27-2007, 06:51 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Quote:
Where can I go to get the key words to define what I want specificly?
As far as i understand what you said, you are looking for javadoc of Java SE. You can find it here. It will give you which classes you can use and which methods these classes have in addition to brief descriptions of them.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Final Inventory tweeks badness New To Java 1 01-20-2008 09:18 AM
Inventory Program modification help badness Java Applets 1 01-17-2008 06:24 AM
Inventory part 3 program problems badness New To Java 1 12-17-2007 08:00 AM
Inventory part 2 help please badness New To Java 1 12-12-2007 08:51 AM
How to execute an External Program through Java program JavaBean Java Tips 0 10-04-2007 10:33 PM


All times are GMT +3. The time now is 09:47 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org