• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Customer Order project

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on a school project and am looking for a push in right direction or a note on what I should maybe re-read to get that light bulb to go off.

I have created a Gadget class as follows:


The assignment says this of the Gadget class: It contains an item number, description, and price for a gadget; a constructor that sets all the fields; and a get methods to retrieve the field value.

I think I captured this class ok and should be fine. the next class is Order and this is the one I am having issues with. . Here is the Order description:

"It contains an order number, customer name, and address(assume you need just a street address, not city, state, and zip code); a list of item numbers ordered (up to four); the total price of all items ordered; and a shipping and handling fee for the order. Include a constructor to set the field values and get methods to retrieve the field values.

Here is what I have, but I am sure what is in the constructor is wrong and I have changed this file many times so this is just where it sits for now:


So I think the part that is messing me up is the "a list of item numbers ordered (up to four)", I don't think I get what it is asking for (4 separate int's or something else)

I am working on a 3rd file called GadgetOrderTaker which the book describes as:

Is an interactive application that takes four customer orders. The class contains an array of the four Gadget objects offered. The application prompts each user for a name and street address and assigns a unique order number to each customer, starting with 101. The application asks each user to enter an item number and quantity wanted. When the user enters 999 for the item number, the order is complete, and the next customer can enter data. Each customer can order up to four item numbers. When a customers order is complete (the customer has entered 999 for an item number, or has ordered four different items), calculate the shipping and handling charges. After all four customer have placed Orders, display each Order's data, including the order number, the name and address of the customer, and the list of items ordered, including the item number, description, and the price of each order, the total price for the order, and the shipping and handling charge. The GadgetOrderTaker class handles all thrown Exceptions by displaying an explanatory message and ending the application.

So I have this so far for my GadgetOrderTaker file, I think I have the "The class contains an array of the four Gadget objects offered" correct, but after that I am a bit lost again. I just can't seem to figure out how these 3 files interact properly with each other.



So I know this is big and I want to say I am not looking for my work to be done, but maybe just some hint or push in the right direction to tell me what these files should use or look like? I don't even think I am asking the right question, but I know when I read these I don't get it and need some help. For now I am going to get me a good strong coffee and start to review my textbook for something to help me out.

Cheers and thanks for any help
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I can answer all your questions, but...

A "list of item numbers ordered (up to four)" to me sounds like you'd want an array of size four. you'll need methods to add or delete items, and to make sure you don't try and add a fifth.

Alternatively, you could just have four integers called something like "orderId1", "orderID2", etc. you could have specific methods for adding or deleting each of the four, plus a method for getting each. Using an array could be simpler, and make your life easier if next week you need to update it to have 8 orders (or 12, or 2000).

My PERSONAL opinion would be you should NOT have a variable holding the price of all items. If you have a list of the items, you should calculate the total when you need it. If you have a variable, you need to do a lot more updating each and every time an item is added or deleted, and you're data can become out of sync if that gets messed up.

Another tip would be to not store prices as floats. you are dooming your code to weird rounding issues. Money should be stored as an atomic unit, which (for the U.S.) is pennies. Then you can re-format it as needed when you want to print/display it.
 
john-paul York
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:I'm not sure I can answer all your questions, but...

A "list of item numbers ordered (up to four)" to me sounds like you'd want an array of size four. you'll need methods to add or delete items, and to make sure you don't try and add a fifth.

Alternatively, you could just have four integers called something like "orderId1", "orderID2", etc. you could have specific methods for adding or deleting each of the four, plus a method for getting each. Using an array could be simpler, and make your life easier if next week you need to update it to have 8 orders (or 12, or 2000).

My PERSONAL opinion would be you should NOT have a variable holding the price of all items. If you have a list of the items, you should calculate the total when you need it. If you have a variable, you need to do a lot more updating each and every time an item is added or deleted, and you're data can become out of sync if that gets messed up.

Another tip would be to not store prices as floats. you are dooming your code to weird rounding issues. Money should be stored as an atomic unit, which (for the U.S.) is pennies. Then you can re-format it as needed when you want to print/display it.



Thanks for the info Fred, unfortunately I have to have a variable to hold the total price as the project says it needs it. I agree with the array size four for the list, but when I thought of that it made me think of more questions...such as do I create a array of size four in the Order constructor then? that sounded incorrect to me, but the project says "Include a constructor to set the field values" so I am think I need to set the array somehow and for some reason....the array of item numbers would have to be based on input from the user, so how would that work? I am re reading the array, "methods, classes, and objects" chapters as I think they might help me out in this situation....
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you know your array needs to hold four items, I'd declare it as a member variable...


then your constructor would be something like


(note - i'm working on a loaner pc, which does not have the JDK installed, so I can't test/verify my example)

Obviously you'd need to adjust it to pass in the other params, but this might give you a few ideas.
 
john-paul York
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:If you know your array needs to hold four items, I'd declare it as a member variable...


then your constructor would be something like


(note - i'm working on a loaner pc, which does not have the JDK installed, so I can't test/verify my example)

Obviously you'd need to adjust it to pass in the other params, but this might give you a few ideas.



Once again thanks a bunch Fred, while working on it today I have changed my GadgetOrderTaker file to the following:


the reason I came up with this is that now everytime I create a Order object it would then fill it with a item number and matching quantity. I am testing with just one object right now and am working on a good way to automatically create another object that I can then fill again with the same info. Once I am able to create 4 seperate Order objects with upto 4 items with quantity I am thinking I can start to build around them with regards to calculating total price/S&H/etc.

I post this because if you see an issue maybe I might be heading int that would be great....thanks again for the continued input
 
Good night. Drive safely. Here's a tiny ad for the road:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic