Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
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-2008, 09:07 PM
Member
 
Join Date: Jul 2008
Posts: 43
ljk8950 is on a distinguished road
Inventory Program Part 3 - DUE TODAY (7/28/08)
PLEASE HELP!!!!

I know we are not suppose to post more than one on the same issue. However, I am panicking over this assignment which is due today. I have been working on it for 5 days straight. I need someone to point me in the right direction of how to get the manufacturer sublclass to display a manufacturer for each supply and how to get the restocking fee to display. I can get the program to compile but these items are not displayed correctly. The manufacturer feature seems to display the same manufacturer for all the supplies. I have only entered one thus far. However, when I enter multiple manufacturers I get error codes. Below is my most current version of the program and below it is what compiles. Thanks to anyone who can help me before I have a complete melt down over this project. I have placed several calls and emails to my teacher in the last several days and he has not responded. Therefore, I will be eternally grateful to anyone who can help me.

Code:
// CheckPoint: InventoryProgramPart3.java // Week 6 // This program calculates inventory value import java.util.Scanner; import java.util.Arrays; public class InventoryProgramPart3 { // main method begins program execution public static void main(String args[] ) { // create Scanner to obtain input from command window Scanner input = new Scanner( System.in ); // display a welcome message to the InventoryProgramPart3 user System.out.println( "Welcome to Inventory Program Part 3!" ); // office supplies supplies[] supplies = new supplies[100]; // an array of 100 supplies manufacturer[] manufacturer = new manufacturer[100]; supplies notepads = new supplies( 4000, "notepads", 60, 2.75 ); supplies pencils = new supplies( 5000, "pencils", 75, 1.25 ); supplies folders = new supplies( 2000, "folders", 30, 4.75 ); supplies envelopes = new supplies( 1000, "envelopes", 15, 5.25 ); supplies markers = new supplies( 3000, "markers", 45, 3.50 ); // display the inventories one at a time envelopes.showInventory(); folders.showInventory(); markers.showInventory(); notepads.showInventory(); pencils.showInventory(); // sort supplies by name for ( int i = 0; i < args.length; i++ ) System.out.println( args[i] + ", " ); double array[] = { 78.75, 142.50, 157.50, 165.00, 93.75 }; double total = 0; // add each element's value to total for ( int counter = 0; counter < array.length; counter++) total += array[ counter ]; System.out.printf( "\nTotal inventory value is: $%.2f\n", total ); System.out.println( "\nThank you for using Inventory Program Part 3!\n" ); } // end method main } // end class InventoryProgramPart3 // Office Supplies class supplies { public int suppliesNumber; public String suppliesName = new String(); public int suppliesUnits; public double suppliesPrice; // set supplies number public void setSuppliesNumber( int number ) { this.suppliesNumber = number; } // end method set supplies number // return supplies number public int getSuppliesNumber() { return suppliesNumber; } // end method get supplies number // set supplies name public void setSuppliesName( String name ) { this.suppliesName = name; } // end method set supplies name // return supplies name public String getSuppliesName() { return suppliesName; } // end method get supplies name // set supplies in stock public void setSuppliesUnits( int units ) { this.suppliesUnits = units; } // end method set supplies units // return supplies units public int getSuppliesUnits() { return suppliesUnits; } // end method get supplies units // set supplies price public void setSuppliesPrice( double price ) { this.suppliesPrice = price; } // end method set supplies price // return supplies price public double getSuppliesPrice() { return suppliesPrice; } // end method get supplies price // calculate supplies inventory value public double getValue() { return suppliesUnits * suppliesPrice; } // end method supplies inventory value // four-argument constructor supplies( int number, String name, int units, double price ) { suppliesNumber = number; suppliesName = name; suppliesUnits = units; suppliesPrice = price; } // end four-argument constructor // display inventory public void showInventory() { System.out.println(); // outputs blank line System.out.println( "Product Number: "+suppliesNumber ); System.out.println( "Product Name: "+suppliesName ); System.out.println( "Units in Stock: "+suppliesUnits ); System.out.printf( "Unit Price: $%.2f", suppliesPrice ); manufacturer supplies = new manufacturer ( 4000, "notepads", 60, 2.75, "Ampad" ); System.out.println( "\nManufacturer: "+supplies.getManufacturer() ); // value() method and display the value System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n", getValue() ); } // end display inventory } // end class supplies class manufacturer extends supplies { // holds the supplies manufacturer private String suppliesManufacturer; // five-argument constructor manufacturer( int number, String name, int units, double price, String manufacturer ) { super( number, name, units, price ); suppliesManufacturer = manufacturer; } // end five-argument constructor // set supplies manufacturer public void setManufacturer( String manufacturer ) { this.suppliesManufacturer = manufacturer; } // end method set supplies manufacturer // return supplies manufacturer public String getManufacturer() { return suppliesManufacturer; } // end method get supplies manufacturer // add 5% restocking fee public double getValue() { return super.getValue() * 1.05; } // end method return supplies manufacturer // calculate restocking fee public double getRestockingFee() { return super.getValue() * .05; } //end method calculate restocking fee //return String representation of suppliesManufacturer public String toString() { String formatString = "Manufacturer: %s"; formatString += "Restocking Fee: $%.2f"; formatString = String.format( formatString, suppliesManufacturer, super.getValue() * 0.05 ); return( formatString + super.toString() ); } // end toString() // display inventory public void showInventory() { super.showInventory(); System.out.println( toString() ); System.out.println( "\nManufacturer: "+getManufacturer() ); // Display value plus restocking fee System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n", getRestockingFee() ); } // end method display inventory } // end class manufacturer
Below is what displays when the program executes:

Code:
Welcome to Inventory Program Part 3! Product Number: 1000 Product Name: envelopes Units in Stock: 15 Unit Price: $5.25 Manufacturer: Ampad Inventory value of envelopes is = $78.75 Product Number: 2000 Product Name: folders Units in Stock: 30 Unit Price: $4.75 Manufacturer: Ampad Inventory value of folders is = $142.50 Product Number: 3000 Product Name: markers Units in Stock: 45 Unit Price: $3.50 Manufacturer: Ampad Inventory value of markers is = $157.50 Product Number: 4000 Product Name: notepads Units in Stock: 60 Unit Price: $2.75 Manufacturer: Ampad Inventory value of notepads is = $165.00 Product Number: 5000 Product Name: pencils Units in Stock: 75 Unit Price: $1.25 Manufacturer: Ampad Inventory value of pencils is = $93.75 Total inventory value is: $637.50 Thank you for using Inventory Program Part 3!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-27-2008, 09:11 PM
Member
 
Join Date: Jul 2008
Posts: 43
ljk8950 is on a distinguished road
By the Way
Below is the exact instructions for the assignment:

· Due Date: Sunday, July 28, 2008 at midnight

· 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 previously created for the product class. The subclass method should also add a 5% restocking fee to the value of
the inventory of that product.

· Modify the output to display this additional feature you have chosen and the restocking fee.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-27-2008, 09:59 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
formatString =
Take a look at your code and be sure you are concatenating to the current value vs assigning a new value
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-27-2008, 10:11 PM
Member
 
Join Date: Jul 2008
Posts: 43
ljk8950 is on a distinguished road
Reply to Norm
Norm,

Below is my updated code. I did noticed I had a couple things referred to as manufacturer vs. suppliesManufacturer. I changed those. However, the outcome is still the same. If I am not calling a method right, I just don't see it. Do you see anything in my code that I should look at in particular? Any feedback would be appreciated. Thank you!


Code:
// CheckPoint: InventoryProgramPart3.java // Week 6 // This program calculates inventory value import java.util.Scanner; import java.util.Arrays; public class InventoryProgramPart3 { // main method begins program execution public static void main(String args[] ) { // create Scanner to obtain input from command window Scanner input = new Scanner( System.in ); // display a welcome message to the InventoryProgramPart3 user System.out.println( "Welcome to Inventory Program Part 3!" ); // office supplies supplies[] supplies = new supplies[100]; // an array of 100 supplies manufacturer[] manufacturer = new manufacturer[100]; supplies notepads = new supplies( 4000, "notepads", 60, 2.75 ); supplies pencils = new supplies( 5000, "pencils", 75, 1.25 ); supplies folders = new supplies( 2000, "folders", 30, 4.75 ); supplies envelopes = new supplies( 1000, "envelopes", 15, 5.25 ); supplies markers = new supplies( 3000, "markers", 45, 3.50 ); // display the inventories one at a time envelopes.showInventory(); folders.showInventory(); markers.showInventory(); notepads.showInventory(); pencils.showInventory(); // sort supplies by name for ( int i = 0; i < args.length; i++ ) System.out.println( args[i] + ", " ); double array[] = { 78.75, 142.50, 157.50, 165.00, 93.75 }; double total = 0; // add each element's value to total for ( int counter = 0; counter < array.length; counter++) total += array[ counter ]; System.out.printf( "\nTotal inventory value is: $%.2f\n", total ); System.out.println( "\nThank you for using Inventory Program Part 3!\n" ); } // end method main } // end class InventoryProgramPart3 // Office Supplies class supplies { public int suppliesNumber; public String suppliesName = new String(); public int suppliesUnits; public double suppliesPrice; // set supplies number public void setSuppliesNumber( int number ) { this.suppliesNumber = number; } // end method set supplies number // return supplies number public int getSuppliesNumber() { return suppliesNumber; } // end method get supplies number // set supplies name public void setSuppliesName( String name ) { this.suppliesName = name; } // end method set supplies name // return supplies name public String getSuppliesName() { return suppliesName; } // end method get supplies name // set supplies in stock public void setSuppliesUnits( int units ) { this.suppliesUnits = units; } // end method set supplies units // return supplies units public int getSuppliesUnits() { return suppliesUnits; } // end method get supplies units // set supplies price public void setSuppliesPrice( double price ) { this.suppliesPrice = price; } // end method set supplies price // return supplies price public double getSuppliesPrice() { return suppliesPrice; } // end method get supplies price // calculate supplies inventory value public double getValue() { return suppliesUnits * suppliesPrice; } // end method supplies inventory value // four-argument constructor supplies( int number, String name, int units, double price ) { suppliesNumber = number; suppliesName = name; suppliesUnits = units; suppliesPrice = price; } // end four-argument constructor // display inventory public void showInventory() { System.out.println(); // outputs blank line System.out.println( "Product Number: "+suppliesNumber ); System.out.println( "Product Name: "+suppliesName ); System.out.println( "Units in Stock: "+suppliesUnits ); System.out.printf( "Unit Price: $%.2f", suppliesPrice ); manufacturer supplies = new manufacturer ( 4000, "notepads", 60, 2.75, "Ampad" ); System.out.println( "\nManufacturer: "+supplies.getSuppliesManufacturer() ); // value() method and display the value System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n", getValue() ); } // end display inventory } // end class supplies class manufacturer extends supplies { // holds the supplies manufacturer private String suppliesManufacturer; // five-argument constructor manufacturer( int number, String name, int units, double price, String manufacturer ) { super( number, name, units, price ); suppliesManufacturer = manufacturer; } // end five-argument constructor // set supplies manufacturer public void setSuppliesManufacturer( String manufacturer ) { this.suppliesManufacturer = manufacturer; } // end method set supplies manufacturer // return supplies manufacturer public String getSuppliesManufacturer() { return suppliesManufacturer; } // end method get supplies manufacturer // add 5% restocking fee public double getValue() { return super.getValue() * 1.05; } // end method return supplies manufacturer // calculate restocking fee public double getRestockingFee() { return super.getValue() * .05; } //end method calculate restocking fee //return String representation of suppliesManufacturer public String toString() { String formatString = "Manufacturer: %s"; formatString += "Restocking Fee: $%.2f"; formatString = String.format( formatString, suppliesManufacturer, super.getValue() * 0.05 ); return( formatString + super.toString() ); } // end toString() // display inventory public void showInventory() { super.showInventory(); System.out.println( toString() ); System.out.println( "\nManufacturer: "+getSuppliesManufacturer() ); // Display value plus restocking fee System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n", getRestockingFee() ); } // end method display inventory } // end class manufacturer
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-27-2008, 10:15 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Try some debugging!
Add some println() statements to your code where you think there is a problem with values of variables and see what's happening.

Last edited by Norm : 07-27-2008 at 10:18 PM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-27-2008, 10:29 PM
Member
 
Join Date: Jul 2008
Posts: 43
ljk8950 is on a distinguished road
Reply to Norm
I have done that already. I keep getting the "cannot find symbol error" message. So I delete the println and try something else. The cannot find symbol error message does not tell me where the error is or how to correct it. I think I have spent the last 48 hours making changes and deleting the changes when they do not work. I figured if my program at least compiles I am better off than when it doesn't compile. This assignment only required we had a subclass and display additional output. Do I need to add anything to my supplies class or main to get this to happen? Or, is my error only simply in my subclass somewhere? Thanks for any help you can give me.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-27-2008, 10:43 PM
Member
 
Join Date: Jul 2008
Posts: 43
ljk8950 is on a distinguished road
Reply to Norm
Norm,

Below are two sections of my code that I am not sure if it is right. Maybe this is where my problem is. Can you please take a look and let me know what you think? Thank you!

Code:
// set supplies manufacturer public void setSuppliesManufacturer( String manufacturer ) { this.suppliesManufacturer = manufacturer; } // end method set supplies manufacturer
Code:
//return String representation of suppliesManufacturer public String toString() { String formatString = "Manufacturer: %s"; formatString += "Restocking Fee: $%.2f"; formatString = String.format( formatString, suppliesManufacturer, super.getValue() * 0.05 ); return( formatString + super.toString() ); } // end toString() // display inventory public void showInventory() { super.showInventory(); System.out.println( toString() ); System.out.println( "\nManufacturer: "+getSuppliesManufacturer() ); // Display value plus restocking fee System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n", getRestockingFee() ); } // end method display inventory
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-28-2008, 12:28 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
I keep getting the "cannot find symbol error" message.
You need to post the compiler output when you get errors you don't understand. You are either misspelling something or don't have the correct path set (done with import ...) for the compiler to find the definition for the symbol. Don't ignore it! YOU need to know how to debug your program. System.out.println() is one of the tools to use.
The code you show looks like it would print something. There appears to be three print statements. What's missing and from what print statement?

Why do you call super.toString()?
Have you read the API doc for the toString() method? What does it return? Do you have any interest in that?
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
Java Inventory Program Part 3 ljk8950 New To Java 18 07-28-2008 07:47 AM
Inventory Program modification help badness Java Applets 1 01-17-2008 07:24 AM
Inventory part 3 program problems badness New To Java 1 12-17-2007 09:00 AM
Inventory part 2 help please badness New To Java 1 12-12-2007 09:51 AM
Inventory program Nexcompac New To Java 3 07-27-2007 07:51 PM


All times are GMT +3. The time now is 02:53 AM.


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