Problem with restock fee not reporting

Thread Solved

Join Date: May 2008
Posts: 6
Reputation: javauser215 is an unknown quantity at this point 
Solved Threads: 0
javauser215 javauser215 is offline Offline
Newbie Poster

Problem with restock fee not reporting

 
0
  #1
May 4th, 2008
My program compiles and runs okay, but is not displaying my restocking fee and I am not sure why. Attached is my printout of how it displays.

  1. //Product.java works with Inventory4.java file
  2.  
  3. import java.util.Scanner; // program uses class Scanner
  4. public class Product4
  5. {
  6. //Private Variables
  7.  
  8. private String name; //Product name
  9. private int identificationNumber; //The product identification number
  10. private int unitsInStock; //Number of units in stock
  11. private double unitPriceInDollars; //The price of each unit in dollars
  12. private double restockFee; //price for restocking units
  13.  
  14.  
  15. //Constructors
  16.  
  17. //Default constructor
  18. public Product4()
  19. {
  20. //Set some default values for each private variable
  21. name = "";
  22. identificationNumber = 0;
  23. unitsInStock = 0;
  24. unitPriceInDollars = 0.00;
  25. restockFee = 0.00;
  26.  
  27. }//End Inventory constructor
  28.  
  29. Product4 inventory [] = new Product4 [5];
  30.  
  31. //Initialization constructor
  32. public Product4(
  33. String nameIn, int identificationNumberIn,
  34. int unitsInStockIn, double unitPriceInDollarsIn, double restockFeeIn
  35. )
  36. {
  37.  
  38. //Set the item name--use the set methods to enforce bounds checking
  39. setName( nameIn );
  40.  
  41. //Set the item identifcation number
  42. setIdentificationNumber( identificationNumberIn );
  43.  
  44. //Set the number of units in stock
  45. setUnitsInStock( unitsInStockIn );
  46.  
  47. //Set the unit price in dollars
  48. setUnitPriceInDollars( unitPriceInDollarsIn );
  49.  
  50. }//End Inventory constructor
  51.  
  52. //Stores the item name
  53. public void setName( String nameIn )
  54. {
  55. name = nameIn; //Store the item name
  56.  
  57. }//End setName
  58.  
  59. //Stores the product identification number
  60. public void setIdentificationNumber( int identificationNumberIn )
  61. {
  62. //Store the item identification number
  63. // If the value is negative, then store 0
  64. identificationNumber = ( (identificationNumberIn > 0) ? identificationNumberIn : 0 );
  65.  
  66. }//End setID
  67.  
  68. //Stores the number of units in stock
  69. public void setUnitsInStock( int unitsInStockIn )
  70. {
  71. //Store the number of units in stock
  72. // If the value is negative, then store 0
  73. unitsInStock = ( (unitsInStockIn > 0)?unitsInStockIn:0 );
  74.  
  75. }//End setUnitsInStock
  76.  
  77. //Stores the price of each unit in dollars
  78. public void setUnitPriceInDollars( double unitPriceInDollarsIn )
  79. {
  80. //Store the unit price
  81. // If the value is negative, then store 0.0
  82. unitPriceInDollars = ( (unitPriceInDollarsIn > 0.0)?unitPriceInDollarsIn:0.0);
  83.  
  84. }//End setUnitPriceInDollars
  85.  
  86. //Stores the item restock fee
  87. public void setRestockFee( double restockFeeIn )
  88. {
  89. restockFee = ( (restockFeeIn > 0.0)?restockFeeIn:0.0 ); //Store the item restock fee
  90.  
  91. }//End setRestockFee
  92.  
  93. //Returns the item name
  94. public String getName()
  95. {
  96. return ( name ); //Return the identification name
  97.  
  98. } // End getName
  99.  
  100. //Returns the item identification number
  101. public int getIdentificationNumber()
  102. {
  103. return ( identificationNumber ); //Return the identification number
  104.  
  105. }//End getIdentificationNumber
  106.  
  107. //Returns the number of units in stock
  108. public int getUnitsInStock()
  109. {
  110. return( unitsInStock ); //Return the number of units in stock
  111.  
  112. }//End getUnitsInStock
  113.  
  114. //Returns the price of each unit
  115. public double getUnitPriceInDollars()
  116. {
  117. return( unitPriceInDollars ); //Return the unit price
  118.  
  119. }//End getUnitPriceInDollars
  120.  
  121. //Returns the restocking fee
  122. public double getRestockFee()
  123. {
  124. return( restockFee );
  125. }
  126. //Other Methods
  127.  
  128. //Returns the total value of the inventory in dollars
  129. public double stockValueInDollars()
  130. {
  131. return ( unitsInStock * unitPriceInDollars );
  132.  
  133. }//End stockValueInDollars
  134.  
  135. //Returns a formatted String for output purposes
  136. public String toString()
  137. {
  138. String formatString = "Identification Number : %d\n";
  139. formatString += "Product : %s\n";
  140. formatString += "Units In Stock : %d\n";
  141. formatString += "Unit Price : $%.2f\n";
  142. formatString += "Stock Value : $%.2f\n\n";
  143. formatString += "Restocking Fee : $%.2f\n";
  144.  
  145. return ( String.format( formatString, identificationNumber, name, unitsInStock,
  146. unitPriceInDollars, stockValueInDollars(), restockFee )
  147. );
  148.  
  149. }//End toString()
  150.  
  151. //Display an array of products and their value
  152. public static void listInventory ( Product4 inventory[] )
  153. {
  154. //Print each product
  155. for ( Product4 product:inventory )
  156. {
  157. //Print product
  158. System.out.println( product.toString () );
  159. }//End for
  160. System.out.printf( "Total Inventory Value: $%.2f\n", totalValue ( inventory ) );
  161. }//End method listInventory()
  162.  
  163. //Calculate and return total value of inventory
  164. public static double totalValue( Product4 inventory[] )
  165. {
  166. double inventoryValue = 0.0;
  167. for ( Product4 product: inventory )
  168. {
  169. //Add the total value of this product to the total value of inventory
  170. inventoryValue += product.stockValueInDollars();
  171. }//End enhanced for
  172. return ( inventoryValue ); //returns the value of all inventory
  173.  
  174. }//End totalValue method
  175.  
  176. //Overloads the String objects compareTo() function so Product can be compared and sorted
  177. public int compareTo ( Product4 aProduct )
  178. {
  179. //Compare the name of this product to the passed Product ( aProduct )
  180. return( name.compareTo ( aProduct.getName() ) );
  181. }
  182. //Sorts the Product array by name
  183. public static void sortAlphabetical ( Product4 inventory[] )
  184. {
  185. Product4 temp; //for swapping
  186. int bottom;
  187. int i;
  188.  
  189. //This is called a bubble sort
  190. for (bottom = inventory.length-1; bottom > 0; bottom--)
  191. {
  192. for ( i = 0; i < bottom; i ++ )
  193. {
  194. //If inventory[i] is lexographically greater than inventory[i+1], then swap the two around
  195. if ( inventory[i].compareTo ( inventory[i+1] ) > 0 )
  196. {
  197. //swap inventory[i] with inventory[i+1]
  198. temp = inventory[i];
  199. inventory[i] = inventory[i+1];
  200. inventory[i+1] = temp;
  201. }//End if
  202. }//End for
  203. }//End for
  204. }//End alphabetical sort method
  205.  
  206. }//End class Product

---------

  1. //Works with Product4.java file
  2.  
  3. import java.util.Arrays;
  4. public class Inventory4
  5. {
  6. public static void main( String args[] )
  7. {
  8.  
  9. double restockFee = 0.05;
  10.  
  11. //Declare and initialize the inventory array
  12. Product4 inventory []; //Array variables
  13.  
  14. //Size of the array
  15. inventory = new Product4[5];
  16.  
  17. //Initialize each array using the Product Constructor
  18.  
  19. inventory[0] = new Product4("HP BLACK", 1, 3, 72.91, 3.65);
  20. inventory[1] = new Product4("HP 41 COLOR", 2, 2, 21.29, 1.06);
  21. inventory[2] = new Product4("HP 78 TRI-COLOR", 3, 4, 22.45, 1.12);
  22. inventory[3] = new Product4("HP 102 Gray", 4, 16, 22.99, 1.15);
  23. inventory[4] = new Product4("HP Black", 5, 14, 13.60, 0.68);
  24.  
  25. //Sorts the Array Variables
  26. Product4.sortAlphabetical ( inventory );
  27. int x = inventory[0].compareTo ( inventory [1] );
  28. System.out.println ( x+"\n" );
  29.  
  30. for ( int i=0; i<5; i++ )
  31. System.out.println ( inventory[i].toString() );
  32.  
  33. //Display each product in the array, including the total value of inventory
  34. Product4.listInventory( inventory );
  35. } //End main
  36.  
  37. } //End Array Inventory4

I appreciate whatever assistance is offered. Thank you.
Attached Thumbnails
Inventory4.JPG  
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 6
Reputation: javauser215 is an unknown quantity at this point 
Solved Threads: 0
javauser215 javauser215 is offline Offline
Newbie Poster

Re: Problem with restock fee not reporting

 
0
  #2
May 5th, 2008
I fixed my problem, I forget to SET it. Thanks.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC