• 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

Adding nested loop in order to print out a table

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My final project for my university is to enhance my code in order to have it print out the total price including the discount but before shipping charges and taxes. The rows should be items sold and the columns should be the wait of the items. I am starting to get frustrated, been at this for hours cant seem to figure it out. As a hint he says to use nested loops?

Heres my codes I have 1 main class and 1 test class



and my Main Class



Thanks for all the help ive been really struggling!


[HENRY: Fixed code tags. And did some formatting]
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings and welcome.

-- now that the greetings are done.

you should use code tags for your code --- please read the FAQs prior to posting.

you did not pose a question --- this is not a codemill ---- please read the FAQs prior to posting.

Please focus and give us a question with your understanding and we shall try to point you in the proper direction.

After you have read the FAQs, you may want to answer the following questions for us:

Where are you having difficulty?

Why are you having this difficuly?

How would you like to approch this problem?

And what do you see as going wroing with your approch?

-steve
 
Ranch Hand
Posts: 54
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

dylan terry wrote: As a hint he says to use nested loops?


I don't see where you've followed his hint first off.....
 
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
No offense, but your code is kind of a mess... You don't follow conventions, so it gets very confusing. For example, when I see "Items", Since the first letter is capitalized, I think it is a class, not a reference.

You have a class called "DataEquations", but then make a reference variable it called 'price'. A price is not an equation, or a set of equations...a price should be (at least in my mind) a number.

On line 21 of your PriceCalculator class, you have a while loop, with an...odd...condition. I'm not saying it is wrong, but it doesn't look like anything that makes any sense to me. Why have these magic numbers?

Your while statement doesn't have any curly braces, so there is only one line in it's body. So let's assume I input a value of '2'. Since 2 is not <= 0, or > 10000000 (however many 0's you have), it skips the loop body, which is only the line 24. Then lines 26-45 all run.

Now, let's assume i put in a value of "-2". This makes the condition TRUE, and now i'm stuck in an infinite loop printing "Base Price = $-84.00" (or whatever price I input) forever, since you never change anything that would affect your condition.

so...I am assuming you need some major revisions to your code here. I would guess that you are supposed to ask the user how many items to ship (that part seems to work). I would then guess that you need a loop that gets the input weight of each and every item, one at a time, an stores all those values in a collection of some kind (and Array or ArrayList would work fine).

Once you have that done, I would work on printing out the data for each element.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic