Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 13th, 2008, 3:52 AM   #1
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
review javadocs and method design

I have uploaded the pdf that describes the homework assignment and a "jar.zip" file. remove the .zip part to double click and run. the source is inside of the "jar.zip"

I am new to using javadoc and find myself at a loss as to what to write. The comments always seem pointless because params and methods are rather self explanatory. I feel as though I end up repeating myself when describing many methods. particularity one's with return statements where I have to comment the return value and what the method dose. I would like advice on how to do javadoc commenting as apposed to normal commenting

The part I'm most concerned about is the add method in ShoppingCart. I know it works but I don't think it is the best way of doing it. Every time a textfield in the GUI has action with a valid number it sends a new ItemOrder object to ShoppingCart to add to an array list used for computing the cost. So when changing a textfield from one number to another the last occurrence of that same order must be removed or altered to reflect the new change.

After those two issues would you please give a over all look at the logic and design I used.

Thank you.
Attached Files
File Type: pdf hw1-shopping.pdf (144.7 KB, 2 views)
File Type: zip assignmnet1.jar.zip (13.5 KB, 0 views)
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Jan 15th, 2008, 3:30 AM   #2
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
Re: review javadocs and method design

My main question is about this add method in ShippingCart class. It is called every time an action occurse in a text field where quantity requests are entered. So when a selection of 5 stickers is made 5 ItemOrder objects are added to an array list called my_order_list. Changing an order from 5 to 3 sends 3 ItemOrder objects to the list. This new quantity has to replace the old one in the array list. ItemOrder can return a string representation of the order requests. I use this string to compare ItemOrders in the arraylist. If a new request's string matches one already in the list I over write it with the new one else I add the new request.

OK so here is my question. Is this line 100% A OK java goodness?
if (the_order.getItem().equals(my_order_list.get(i).getItem()))
Do i need to override some thing or use some other method instead of equals? Am I comparing the right things( strings or hash codes)? Im not sure of the inner workigns of java that this may relate to so I dont know if the above line is correct.

java Syntax (Toggle Plain Text)
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. /**
  5.  * <code>ShoppingCart</code> holds a collection of <code>ItemOrder</code> objects
  6.  * in an array list. The list is used to calculate total cost and to add new
  7.  * purchases requests.
  8.  *
  9.  * @author Christopher Martin
  10.  * @version 1.0
  11.  *
  12.  */
  13.  
  14. public class ShoppingCart
  15. {
  16. /**
  17.   * Constant used to compute the 10% discount.
  18.   */
  19. private static final double DISCOUNT = 0.9;
  20.  
  21. /**
  22.   * Array list for holding ItemOrder objects that contain order name and
  23.   * quantity.
  24.   */
  25. private List <ItemOrder> my_order_list;
  26.  
  27. /**
  28.   * A flag for determining if an overall discount should be applied to the
  29.   * final total.
  30.   */
  31. private boolean my_discount;
  32.  
  33. /**
  34.   * Create an empty array list to hold purchases requests in the form of
  35.   * ItmeOrder objects. There are no parameters on purpose.
  36.   */
  37. public ShoppingCart()
  38. {
  39. my_order_list = new ArrayList<ItemOrder>();
  40. }
  41.  
  42. /**
  43.   * Goes through the array list and replaced old ItemOrders with the new one.
  44.   * If there is no previous entry an new one is added with out replacement.
  45.   *
  46.   * @param the_order A new request of purchase for an item.
  47.   */
  48. public void add(final ItemOrder the_order)
  49. {
  50. for (int i = 0; i < my_order_list.size(); i++)
  51. {
  52. //compare the string representation of Items in the list to the param Item.
  53. if (the_order.getItem().equals(my_order_list.get(i).getItem()))
  54. {
  55. //replace and exit method
  56. my_order_list.set(i, the_order);
  57. return;
  58. }
  59. }
  60. //add if not in the list already
  61. my_order_list.add(the_order);
  62. }
  63.  
  64. /**
  65.   * Turn on or off the discount to be applied to all items.
  66.   * @param the_discount Indicator to determine if discount should be applied.
  67.   */
  68. public void setDiscount(final boolean the_discount)
  69. {
  70. my_discount = the_discount;
  71. }
  72.  
  73. /**
  74.   * Goes through the array list of ItemOrders calculating the total including
  75.   * a discount when applicable.
  76.   *
  77.   * @return total cost of all items based on their quantity selected
  78.   */
  79. public double getTotal()
  80. {
  81. double sum = 0.0;
  82.  
  83. for (ItemOrder temp_list : my_order_list)
  84. {
  85. sum += temp_list.getPrice();
  86. }
  87.  
  88. if (my_discount)
  89. {
  90. sum *= DISCOUNT;
  91. }
  92.  
  93. return sum;
  94. }
  95. }

java Syntax (Toggle Plain Text)
  1. /**
  2.  * When a valid number is entered to purchase an item a new ItemOrder object is
  3.  * created to hold the item being selected and the quantity being purchased.
  4.  *
  5.  * @author christopher martin
  6.  * @version 1.0
  7.  */
  8. public class ItemOrder
  9. {
  10. /**
  11.   * The reference to an <code>Item</code> object.
  12.   */
  13. private Item my_item;
  14.  
  15. /**
  16.   * The number of items being purchased.
  17.   */
  18. private int my_quanity;
  19.  
  20. /**
  21.   * Constructs <code>ItemOrder</code> object with <code>Item</code> reference
  22.   * and the amount of items being purchased.
  23.   *
  24.   * @param the_item Reference to an <code>Item</code> object.
  25.   * @param the_quantity The amount of items being purchased.
  26.   */
  27. public ItemOrder(final Item the_item, final int the_quantity)
  28. {
  29. my_item = the_item;
  30. my_quanity = the_quantity;
  31. }
  32.  
  33. /**
  34.   * Returns the total cost of the items being purchased including
  35.   * bulk discount.
  36.   *
  37.   * @return price for item including bulk discount if it applies.
  38.   */
  39.  
  40. public double getPrice()
  41. {
  42. return my_item.priceFor(my_quanity);
  43. }
  44.  
  45. /**
  46.   *
  47.   * @return Reference to current <code>Item</code>.
  48.   */
  49. public Item getItem()
  50. {
  51. return my_item;
  52. }
  53. }

Thank you.
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC