Need Help with java Inventory program Part3

Reply

Join Date: Nov 2008
Posts: 3
Reputation: apeaser is an unknown quantity at this point 
Solved Threads: 0
apeaser apeaser is offline Offline
Newbie Poster

Need Help with java Inventory program Part3

 
0
  #1
Nov 2nd, 2008
I need help with this code. I am already a week late on this part because part 2 took to long to code. I am not getting the LeatherBlueDot class to compile. I am getting a message that in my constructor statement saying each variable has private access in class SoftballInv3, but I used the super method to declare them. I am not if I am explaining this correctly. I am very new to Java and struggling. Can anyone help? I am posting three classes needed. The Test class is supposed to display the arrays. Here they are beginning with the Test class.

  1. // Inventory program part two
  2. // for softball inventories
  3. // from Als sporting goods
  4.  
  5.  
  6. public class SoftballInvTest3
  7. {
  8. // begins main method
  9. public static void main ( String args[])
  10. {
  11. // creats a welcome message
  12. System.out.println( "Welcome to Al's Sporting Goods softball inventory" );
  13.  
  14. // displays headers for the inventory
  15. System.out.printf( "\n%4s%26s%10s%5s%9s%11s%13s", "ITEM", "BRAND NAME", "TYPE", "QTY",
  16. "PRICE", "RESTOCK", "INV VALUE" );
  17.  
  18. // lists all of the arrays used in this program
  19. int itemNumber[] = {1001,1002,1003,1004,1005,1006, 1007};
  20. int ballCount[] = {36, 48, 12, 72, 24, 96, 24 };
  21. double ballPrice[] = { 5.99, 4.99, 5.49, 6.99, 7.99, 1.99, 3.99 };
  22. String itemName[] = {"Blue Dot-Worth", "Gold Dot-Worth", "Green Dot-Worth", "Super Blue Dot-Worth",
  23. "Demarini Evil Ball", "Rawlings practice balls", "Demarini Core 44" };
  24. double subTotal[] = new double [7];
  25. double reStock[] = new double [7];
  26. String coverType[] = {"leather", "synthetic", "synthetic", "leather", "synthetic",
  27. "leather", "leather"};
  28.  
  29. // created new objects of softballinv2 class
  30. SoftballInv3 softBall1 = new SoftballInv3();
  31. LeatherBlueDot softBall2 = new LeatherBlueDot();
  32. // uses methods of softballinv public class to determine value
  33.  
  34. softBall1.sortArrayName(itemName);
  35. softBall1.displayArrays(itemNumber, ballCount, ballPrice, itemName, subTotal);
  36. softBall1.getTotalOfInv(subTotal);
  37. softBall2.getReStock(stock);
  38. softBall2.getTotalOfInv(subTotal);
  39. softBall2.sortArrayName( itemName);
  40. softBall2.displayArrays(itemNumber, ballCount, coverType, ballPrice, reStock, itemName, subTotal);
  41. } // ends main method
  42. } // ends public class
  43.  
  44. // This is class of SoftballInvPart3
  45. // this file computes totals and
  46. // creates array
  47.  
  48. public class SoftballInv3
  49. {
  50.  
  51. private int item[]; // array of item numbers
  52. private String name[];
  53. private int balls[]; // array for quantity of balls
  54. private double prices[]; // array for price of each ball
  55. private double subs[]; // array created for totals of item inventory
  56.  
  57.  
  58. // constructor that initializes arrays for each element of inventory list
  59. public SoftballInv3(int itemNumber[], String itemName[], int ballCount[], double ballPrice[], double subTotal[])
  60. {
  61.  
  62.  
  63. item = itemNumber; // stores item number in array
  64. balls = ballCount; // stores number of balls per for item number
  65. prices = ballPrice; // stores price of each ball
  66. subs = subTotal; // stores total price of each item
  67. name = itemName; // stores brand Names
  68.  
  69.  
  70.  
  71.  
  72.  
  73. }// end public Softball array constructor
  74.  
  75. // method to display value of entire inventory
  76. public void getTotalOfInv(double subs[])
  77. {
  78.  
  79. double total = 0;
  80.  
  81. for ( int counter = 0; counter < subs.length; counter++ )
  82. total += subs[ counter ];
  83. System.out.printf( "\nTotal of entire inventory is: %.2f\n", total );
  84.  
  85. } // end set display value method
  86.  
  87.  
  88. // method call to displays sorted arrays
  89. public void displayArrays(int item[], int balls[], double prices[], String name[], double subs[])
  90. {
  91. for ( int j = 0; j < name.length; j++)
  92. System.out.printf("%4s%26s%15s%9s%24.2f\n", item[j], name[j], balls[j],
  93. prices[j], subs[j] = (balls[j] * prices[j]));
  94. } // end method to display the arrays
  95.  
  96. // method to sort the the itemName array alphabetically
  97. public void sortArrayName(String itemName[])
  98. {
  99. int j;
  100. boolean flag = true; //to determine when the sort is finished
  101. String temp;
  102.  
  103. while ( flag ) // loops through array while flag is false
  104. {
  105. flag = false;
  106. for ( j = 0; j <itemName.length - 1; j++ )
  107. {
  108. if ( itemName[ j ].compareToIgnoreCase( itemName[ j+1 ] ) > 0 )
  109. { // ascending sort
  110. temp = itemName[ j ];
  111. itemName[ j ] = itemName[ j+1];
  112. itemName [ j+1] = temp;
  113. flag = true;
  114. } // end if
  115. }
  116. } // end while
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123. } // end class SoftballInv2
  124.  
  125. // This class is sub class of
  126. // of the SoftballInv3 class
  127. // that uses inheritance to add one more
  128. // item to products
  129.  
  130. public class LeatherBlueDot extends SoftballInv3
  131. {
  132. private double stock[]; //re-stock fee for leather balls
  133. private String cover[]; // initiates array variable
  134.  
  135. // five argument constructor
  136. public LeatherBlueDot(int itemNumber[], String itemName[], String coverType[], int ballCount[],
  137. double ballPrice[], double subTotal[], double reStock[])
  138. {
  139.  
  140. super( item, name, balls, prices, subs );
  141.  
  142. getReStock( stock ); // method to add restocking fee
  143. System.out.printf( "\nThe new inventory that adds a restocking fee and cover type:\n");
  144. stock = reStock;
  145. cover = coverType;
  146.  
  147. }// end constructor
  148.  
  149. // adds restocking fee to total price of each product
  150. public void getReStock( double prices[] )
  151. {
  152. double stock = 0;
  153.  
  154. for ( int counter = 0; counter < prices.length; counter++ )
  155.  
  156. stock = prices[ counter ] * 1.05;
  157.  
  158. } // end method
  159.  
  160.  
  161.  
  162.  
  163. public double getTotalOfInv()
  164. {
  165. return getTotalOfInv();
  166. }
  167.  
  168.  
  169. // method call to displays sorted arrays
  170. public void displayArrays(int item[], String name[], String cover[], int balls[], double prices[],
  171. double stock[], double subs[])
  172.  
  173. {
  174. for ( int j = 0; j < name.length; j++)
  175. System.out.printf("%4s%26s%15s%9s%24.2f\n", item[j], name[j], cover[j], balls[j],
  176. prices[j], stock[j], subs[j] = (balls[j] * prices[j]));
  177.  
  178. } // end method to display the arrays
  179.  
  180.  
  181. }
Last edited by ~s.o.s~; Nov 2nd, 2008 at 2:54 am. Reason: Added code tags, learn to use them.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Need Help with java Inventory program Part3

 
0
  #2
Nov 2nd, 2008
exactly as you said, they are private, make them protected
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 3
Reputation: apeaser is an unknown quantity at this point 
Solved Threads: 0
apeaser apeaser is offline Offline
Newbie Poster

Re: Need Help with java Inventory program Part3

 
0
  #3
Nov 2nd, 2008
I had already tried that once before and didn't work but I went ahead and tried again just to see what error I was getting. There are 5 errors, all say the same thing for each variable from softballinv3 class. The messages are "can't reference variable before super type constructor has been called". I don't understand why it says that because the super type constructor is the first statement in the class.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 3
Reputation: apeaser is an unknown quantity at this point 
Solved Threads: 0
apeaser apeaser is offline Offline
Newbie Poster

Re: Need Help with java Inventory program Part3

 
0
  #4
Nov 2nd, 2008
Here is my code again. Nothing has changed, I am just wrapping the code in tags correctly this time.

  1.  
  2. // Inventory program part two
  3. // for softball inventories
  4. // from Als sporting goods
  5.  
  6.  
  7. public class SoftballInvTest3
  8. {
  9. // begins main method
  10. public static void main ( String args[])
  11. {
  12. // creats a welcome message
  13. System.out.println( "Welcome to Al's Sporting Goods softball inventory" );
  14.  
  15. // displays headers for the inventory
  16. System.out.printf( "\n%4s%26s%10s%5s%9s%11s%13s", "ITEM", "BRAND NAME", "TYPE", "QTY",
  17. "PRICE", "RESTOCK", "INV VALUE" );
  18.  
  19. // lists all of the arrays used in this program
  20. int itemNumber[] = {1001,1002,1003,1004,1005,1006, 1007};
  21. int ballCount[] = {36, 48, 12, 72, 24, 96, 24 };
  22. double ballPrice[] = { 5.99, 4.99, 5.49, 6.99, 7.99, 1.99, 3.99 };
  23. String itemName[] = {"Blue Dot-Worth", "Gold Dot-Worth", "Green Dot-Worth", "Super Blue Dot-Worth",
  24. "Demarini Evil Ball", "Rawlings practice balls", "Demarini Core 44" };
  25. double subTotal[] = new double [7];
  26. double reStock[] = new double [7];
  27. String coverType[] = {"leather", "synthetic", "synthetic", "leather", "synthetic",
  28. "leather", "leather"};
  29.  
  30. // created new objects of softballinv2 class
  31. SoftballInv3 softBall1 = new SoftballInv3();
  32. LeatherBlueDot softBall2 = new LeatherBlueDot();
  33. // uses methods of softballinv public class to determine value
  34.  
  35. softBall1.sortArrayName(itemName);
  36. softBall1.displayArrays(itemNumber, ballCount, ballPrice, itemName, subTotal);
  37. softBall1.getTotalOfInv(subTotal);
  38. softBall2.getReStock(stock);
  39. softBall2.getTotalOfInv(subTotal);
  40. softBall2.sortArrayName( itemName);
  41. softBall2.displayArrays(itemNumber, ballCount, coverType, ballPrice, reStock, itemName, subTotal);
  42. } // ends main method
  43. } // ends public class
  44.  
  45. // This is class of SoftballInvPart3
  46. // this file computes totals and
  47. // creates array
  48.  
  49. public class SoftballInv3
  50. {
  51.  
  52. private int item[]; // array of item numbers
  53. private String name[];
  54. private int balls[]; // array for quantity of balls
  55. private double prices[]; // array for price of each ball
  56. private double subs[]; // array created for totals of item inventory
  57.  
  58.  
  59. // constructor that initializes arrays for each element of inventory list
  60. public SoftballInv3(int itemNumber[], String itemName[], int ballCount[], double ballPrice[], double subTotal[])
  61. {
  62.  
  63.  
  64. item = itemNumber; // stores item number in array
  65. balls = ballCount; // stores number of balls per for item number
  66. prices = ballPrice; // stores price of each ball
  67. subs = subTotal; // stores total price of each item
  68. name = itemName; // stores brand Names
  69.  
  70.  
  71.  
  72.  
  73.  
  74. }// end public Softball array constructor
  75.  
  76. // method to display value of entire inventory
  77. public void getTotalOfInv(double subs[])
  78. {
  79.  
  80. double total = 0;
  81.  
  82. for ( int counter = 0; counter < subs.length; counter++ )
  83. total += subs[ counter ];
  84. System.out.printf( "\nTotal of entire inventory is: %.2f\n", total );
  85.  
  86. } // end set display value method
  87.  
  88.  
  89. // method call to displays sorted arrays
  90. public void displayArrays(int item[], int balls[], double prices[], String name[], double subs[])
  91. {
  92. for ( int j = 0; j < name.length; j++)
  93. System.out.printf("%4s%26s%15s%9s%24.2f\n", item[j], name[j], balls[j],
  94. prices[j], subs[j] = (balls[j] * prices[j]));
  95. } // end method to display the arrays
  96.  
  97. // method to sort the the itemName array alphabetically
  98. public void sortArrayName(String itemName[])
  99. {
  100. int j;
  101. boolean flag = true; //to determine when the sort is finished
  102. String temp;
  103.  
  104. while ( flag ) // loops through array while flag is false
  105. {
  106. flag = false;
  107. for ( j = 0; j <itemName.length - 1; j++ )
  108. {
  109. if ( itemName[ j ].compareToIgnoreCase( itemName[ j+1 ] ) > 0 )
  110. { // ascending sort
  111. temp = itemName[ j ];
  112. itemName[ j ] = itemName[ j+1];
  113. itemName [ j+1] = temp;
  114. flag = true;
  115. } // end if
  116. }
  117. } // end while
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124. } // end class SoftballInv2
  125.  
  126. // This class is sub class of
  127. // of the SoftballInv3 class
  128. // that uses inheritance to add one more
  129. // item to products
  130.  
  131. public class LeatherBlueDot extends SoftballInv3
  132. {
  133. private double stock[]; //re-stock fee for leather balls
  134. private String cover[]; // initiates array variable
  135.  
  136. // five argument constructor
  137. public LeatherBlueDot(int itemNumber[], String itemName[], String coverType[], int ballCount[],
  138. double ballPrice[], double subTotal[], double reStock[])
  139. {
  140.  
  141. super( item, name, balls, prices, subs );
  142.  
  143. getReStock( stock ); // method to add restocking fee
  144. System.out.printf( "\nThe new inventory that adds a restocking fee and cover type:\n");
  145. stock = reStock;
  146. cover = coverType;
  147.  
  148. }// end constructor
  149.  
  150. // adds restocking fee to total price of each product
  151. public void getReStock( double prices[] )
  152. {
  153. double stock = 0;
  154.  
  155. for ( int counter = 0; counter < prices.length; counter++ )
  156.  
  157. stock = prices[ counter ] * 1.05;
  158.  
  159. } // end method
  160.  
  161.  
  162.  
  163.  
  164. public double getTotalOfInv()
  165. {
  166. return getTotalOfInv();
  167. }
  168.  
  169.  
  170. // method call to displays sorted arrays
  171. public void displayArrays(int item[], String name[], String cover[], int balls[], double prices[],
  172. double stock[], double subs[])
  173.  
  174. {
  175. for ( int j = 0; j < name.length; j++)
  176. System.out.printf("%4s%26s%15s%9s%24.2f\n", item[j], name[j], cover[j], balls[j],
  177. prices[j], stock[j], subs[j] = (balls[j] * prices[j]));
  178.  
  179. } // end method to display the arrays
  180.  
  181.  
  182. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,574
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 199
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Need Help with java Inventory program Part3

 
0
  #5
Nov 2nd, 2008
Suggestions:

1. Where your LeatherBlueDot constructor (the one with 6 arguments) calls super, the arguments you have in super don't exist. item, name, balls, prices, and subs are not defined in the LeatherBlueDot class. You probably meant to say super( itemNumber, itemName, ballCount, ballPrice, subTotal );

2. You have the line SoftballInv3 softBall1 = new SoftballInv3(); but you don't have a no argument constructor in your SoftBallInv3 class. You have LeatherBlueDot softBall2 = new LeatherBlueDot(); but you don't have that constructor in the LeatherBlueDot class either.

3. softBall2.getReStock(stock); Where is stock declared?
4. softBall2.displayArrays(itemNumber, ballCount, coverType, ballPrice, reStock, itemName, subTotal); You seem to be calling this wrong (with the wrong number or types of arguments)
Last edited by BestJewSinceJC; Nov 2nd, 2008 at 1:01 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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