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 08-03-2007, 09:27 AM
Member
 
Join Date: Jul 2007
Posts: 9
jamesr2b is on a distinguished road
Help Please
Line 265: public class Inventory



{ // begin class Inventory



CDInventoryProgram.java:265: class Inventory is public, should be declared in a
file named Inventory.java
public class Inventory
^


Help Please anyone
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-03-2007, 09:49 AM
Member
 
Join Date: Jul 2007
Posts: 72
Swamipsn is on a distinguished road
I cant get your problem exactly, any way check file name and class name are same or not?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-03-2007, 10:12 AM
Member
 
Join Date: Jul 2007
Posts: 9
jamesr2b is on a distinguished road
More Info on code
This ie the entire application if it helps. Thanks for you time and quick response!


Code:
import java.util.*; import java.text.NumberFormat; class WelcomeMessage { // start class WelcomeMessage // the WelcomeMessage has two fields private String line_1; private String line_2; // the WelcomeMessage has one constructor public WelcomeMessage(String line1, String line2) { line_1 = new String(line1); line_2 = new String(line2); } } // end class WelcomeMessage class Item implements Comparable { // begin class Item // class Item fields private String title; private int stockNum; private int stockQty; private double price; private double calcvalue; public Item( ) { String title = " "; int stockNum = 0; int stockQty = 0; double price = 0.00; double calcvalue = 0.00; } // public Item(String cd_title, short stock_num, short stock_qty, double unit_price ) // { // begin Item class constructor // // title = new String(cd_title); // stockNum = new Short(stock_num); // stockQty = new Short(stock_qty); // price = new Double(unit_price); // // } // end Item class constructor // Item class constructor public Item(String title, int stockNum, int stockQty, double price) { this.title = title; this.stockNum = stockNum; this.stockQty = stockQty; this.price = price; } // class method to get the title public String getTitle( ) { return title; } // class method to set the title public void setTitle(String title) { this.title = title; } // class method to get the stock number public int getStockNum( ) { return stockNum; } // class method to set the stock number public void setStockNum(int stockNum) { this.stockNum = stockNum; } // class method to get the stock quantity public int getStockQty( ) { return stockQty; } // class method to set the stock quantity public void setStockQty(int stockQty) { this.stockQty = stockQty; } // class method to get the price of each unit public Double getPrice( ) { return price; } // class method to set the price of each unit public void setPrice(Double price) { this.price = price; } // class method to calculate the inventory value public Double calcValue( ) { return getStockQty( ) * getPrice( ); } // public int compareTo(Object o) { Item c = (Item) o; return title.compareTo(c.getTitle( ) ); } public String toString( ) { return "Title: " + title + "\nStock Number: " + stockNum + "\nQty In Stock: " + stockQty + "\nUnit Price: $" + price + "\nIn Stock Value: $" + (stockQty * price); } } // end class Item public class Inventory { // begin class Inventory public static void main(String args [ ] ) { // begin main WelcomeMessage welcome; // create WelcomeMessage object welcome // initilize fields of welcome String line_1 = "\nWelcome to the CD Inventory Program!"; String line_2 = "\nThis program displays the CDs in stock alphabetically by Title\nand then calculates the value of the current CD inventory in stock.\n"; // print welcome message System.out.println( line_1); System.out.println( line_2 ); Item[ ] cds = new Item[7]; // create array // fill the elements cds[0] = new Item( ); cds[0].setTitle("Disco Stomp"); cds[0].setStockNum(10001); cds[0].setStockQty(10); cds[0].setPrice(9.99); cds[1] = new Item( ); cds[1].setTitle("Don't Stop Dancing"); cds[1].setStockNum(10002); cds[1].setStockQty(8); cds[1].setPrice(14.99); cds[2] = new Item( ); cds[2].setTitle(" Get The Funk Out Of Ma Face"); cds[2].setStockNum(10003); cds[2].setStockQty(5); cds[2].setPrice(16.99); cds[3] = new Item( ); cds[3].setTitle("Casanova"); cds[3].setStockNum(10004); cds[3].setStockQty(13); cds[3].setPrice(10.99); cds[4] = new Item( ); cds[4].setTitle("When You've Been Blessed"); cds[4].setStockNum(10005); cds[4].setStockQty(6); cds[4].setPrice(12.99); cds[5] = new Item( ); cds[5].setTitle("A House Is Not A Home"); cds[5].setStockNum(10006); cds[5].setStockQty(12); cds[5].setPrice(12.99); cds[6] = new Item( ); cds[6].setTitle(" Fortunate"); cds[6].setStockNum(10007); cds[6].setStockQty(8); cds[6].setPrice(12.99); // call the array sort utility for cds Arrays.sort(cds); // print the cd inventory by title from compare titles in Item class for (Item c: cds) { System.out.println(c); System.out.println( ); } // format, calculate and print the inventory value double value = 0.00; NumberFormat currencyFormat = NumberFormat.getCurrencyInstance( ); for(int a = 0; a < cds.length; a++) { value = value + cds[a].calcValue( ); } String formattedValue = currencyFormat.format(value); System.out.println("The current CD inventory value is: " + formattedValue); // // initialize fields of item // String title = "Disco Stomp"; // Short stockNum = 10001; // Short stockQty = 10; // Double price = 12.99; // // // store item information to item object of Item class // item = new Item( title, stockNum, stockQty, price ); // // // initialize value // Double value = item.calcValue( ); // // System.out.println( "\nCurrent CD Inventory:" ); // System.out.printf( "\nTitle: " + item.getTitle( ) ); // System.out.printf( "\nStock Number: " + item.getStockNum( ) ); // System.out.printf( "\nQuantity: " + item.getStockQty( ) ); // System.out.printf( "\nPrice: " + item.getPrice( ) ); // System.out.printf( "\n\nThe current CD inventory value is: $" + item.calcValue( ) ); // System.out.println(); } // end main } // end class Invent

Last edited by levent : 08-03-2007 at 04:12 PM. Reason: Code placed inside [code] tag.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-03-2007, 10:32 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Code:
CDInventoryProgram.java:265: class Inventory is public, should be declared in a file named Inventory.java public class Inventory ^
Looks like the file name is "CDInventoryProgram". You may have only one outer class in the file with the public modifier and this class must have the same name as the file name and will also be the class with the main method. So if the file name is really "CDInventoryProgram" then either change the file name to "Inventory" or remove the public modifier from the Inventory class signature and remove the main method from it.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-04-2007, 07:12 AM
Member
 
Join Date: Jul 2007
Posts: 9
jamesr2b is on a distinguished road
Thanks fo Help
Thank you for you response that was exactly the problem. I needed to make the public class name the same as my file name...thank you for your time.
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



All times are GMT +3. The time now is 12:07 PM.


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