• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about for loop  RSS feed

 
Ray Friedrich
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this program makes a user input how many shipments should be shipped which is (s)
then reads the array of 4 and I want to know how can I put this system.out
System.out.print("L: ")
System.out.print("M: ")
System.out.print("S: ")

s is the number of shipping loop. sorry if this is already in the boards. thank you for your kind consideration.






like this:

Capture.PNG
[Thumbnail for Capture.PNG]
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray Friedrich wrote:this program makes a user input how many shipments should be shipped...

Welcome to JavaRanch, Ray.

A few things:
1. When posting code, please UseCodeTags (←click). I've added them for you this time - see how much better it looks?
Also: avoid long lines, especially when you have comments, because they make your thread difficult to read.

2. Try to avoid using cryptic names. You've had to explain that 'bName' == company name, whereas if you'd called it 'companyName' it would be self-explanatory.

3. I presume you want to print a different 'size' ("XL", "L" etc) when you go through you loop. How about storing those strings in an array? (sizeString?)

HIH

Winston
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

Even though you see it in many books, you should not use \n unless somebody says they want LF. Brief explanation and a suggestion about what to use instead here. I suspect you do not actually want a new line there; the user will have pushed enter after the previous input.
 
Ray Friedrich
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry mods, I edited it and if there is something else that needs to be edit let me know,
so how do I do the sizeString? thank you.



like this?
if yes how can I make the user ask this questions?
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray Friedrich wrote:


Your code can be shortened to:

I don't understand your question:
Ray Friedrich wrote:so how do I do the sizeString?



And please do not ask questions inside code tag .
 
Ray Friedrich
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok I edited it thank you for telling me, so how can I ask those 4 questions inside a for loop which depends on the number of shipments?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds as though you want a Shipment class, which encapsulates the size and the number of items. You can iterate the array printing the sizes and asking for the amount. Consider whether you want a setSize method (I think no) and a setAmount method (I think yes).
Find out about using an enum for the sizes.

Please check the naming conventions; I think the as_ bit should be removed from the name of your array. Don't double‑space your code; use single blank lines to separate it into sections.
 
Ray Friedrich
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello guys, I am almost done with my assignment and would like to know if its ok if I post the whole code here because I dont know how to calculate the sum of the arrray that was converted using arithmetic equation.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, of course it is, as long as your teachers have no problem with posting code publicly.
 
Ray Friedrich
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes he doesnt care as long as we pass


the program wants to calculate the total for XL , the total for Large, total for Medium and total for Small
and I posted the last part of the requirements. thanks sirs and mams
total.PNG
[Thumbnail for total.PNG]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!