1

So this is for an assignment (which I've already completed), I just left this part out because it seemed like a pain in the ass while I was working on the pattern logic.

The assignment asks that you print this menu graphic to help the user decide which pattern to pick. Is there an easy way to do it or do I just need to get a ton of printf/println statements in there? Seems like a very awkward thing to code. Here's an example:

Menu

EDIT: This is just for the graphical menu. I know I have to use loops for the actual patterns (which I've already done). The assignment is essentially finished, just missing this menu. I wasn't sure how best to print out this graphic horizontally without awkwardly formatting it by hand.

  • 2
    Don't use "a ton of printf/println statements" ... Use loops. – Aziz Nov 11 '12 at 20:46
  • You might find [my blog post](http://nurkiewicz.blogspot.no/2012/05/oslo-coderetreat-summer-2012-in-scala.html) useful. – Tomasz Nurkiewicz Nov 11 '12 at 20:47
  • Well, I was thinking of just calling my pattern methods, but then I'm not sure how I would have them line up horizontally like that rather than vertically. – TheFatIndian Nov 11 '12 at 20:50

2 Answers2

1

Text UI has been implemented so many times. Instead of spending some time trying to develop yet another text-based selection/navigation components try to use available solutions:

Fully featured text UI -- Lanterna

enter image description here

Shell-like approach -- JLine

enter image description here

There is another interesting answer, which provides two other, but not so good options.

Community
  • 1
  • 1
Renat Gilmanov
  • 17,735
  • 5
  • 39
  • 56
0

I think it depends on whether you're going to be assessed on it.

My engineering head tells me that if you're not going to be assessed on it, getting the formatting correct is going to be fiddly and I would just reduce it down to 5 or so println()s, the implementation of which is nothing more than typing.

There's nothing to be ashamed of in such circumstances by choosing what appears to be a trivial exercise. Of course if part 2 of your assessment asks you to extend this to 6 lines (or similar) then a more extensible solution would be appropriate.

I note (following your edit) that you have pattern methods to generate the above. In that case you may wish to modify their inputs/outputs appropriately to facilitate the above. e.g. perhaps they could take in an array of 'n' lines, and append the pattern to those lines, line by line. You'd also need some justification method to pad those lines for the next pattern generator.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • The assignment itself is designed to test our knowledge of loops. So after the user picks the pattern, he or she then has to pick the number of lines the pattern will have (at which point my program calls the appropriate methods which contain loops to print the patterns). I was just confused about how best to print a menu like that (horizontally). – TheFatIndian Nov 11 '12 at 20:53