Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

What does n mean?

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I have to do a variation of the "FizzBuzz" code and my teacher told us to count from 1 to n. But what does n even mean? Is it a variable for any number I want? I know in FizzBuzz you need to count to 100 but since this project is different I am not sure if thats the number I need to count to. Here is the project in my teachers exact words "Write a program that prints the numbers 1 to n, 11 numbers per line. The program shall print "Coza" in place of the numbers which are multiples of 3, "Loza" for multiples of 5, "Woza" for multiples of 7, "CozaLoza" for multiples of 3 and 5, and so on. Get the value of n from the user via an input box. The output is through a message box."
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Sing wrote:So I have to do a variation of the "FizzBuzz" code and my teacher told us to count from 1 to n. But what does n even mean? Is it a variable for any number I want?



Correct. N is any value. I suggest you code it as a method with N as one of its parameter -- and a test program that passes 100 for N. Once it works, test it with many different values of N, from the test program. And finally, ask the user to input N, and call the method.

Henry
 
lowercase baba
Posts: 13075
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your teacher tells you what n is:

Get the value of n from the user via an input box.


Generally, you strive to write programs to be as flexible as possible. I could write a program that solves the fizzbuzz challenge from 1 to 100. I could then write another program that solves it for 1 to 200, and another and another...

but that's boring and a waste of time. What's cool (to a programmer) is to solve it for ANY upper limit. In this case, the code is pretty similar. Instead of a loop from 1 to 100, or 1 to 200, I can make my loop from 1 to n. As long as i set that value of n somehow, somewhere, BEFORE I enter that loop, I'm good for (almost) any number I want.

having said that...

Henry has given you AWESOME advice. write a method that takes a number as a parameter, and have your method work for 1 to that value.

You then can call that method, passing in whatever you want. At first, you would most likely want to pass in something like 10 or 20. Keep it small til you work out the bugs. Once you're confident, pass in 100 or 1000...

Once you have that method rock solid, then you can work on getting the user input. The cool thing there is that if you separate the printing piece from the "get the input" piece, you can replace them at will. The printing part doesn't care if you get the data from the command line, from a GUI, from a database, a webservice call, or what. They point is, once you somehow HAVE the value (even if it's hard-coded while you test), you can pass that into your method to print the answer.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:You then can call that method, passing in whatever you want. At first, you would most likely want to pass in something like 10 or 20. Keep it small til you work out the bugs. Once you're confident, pass in 100 or 1000...


@John: And just to add to the AWESOME advice you've been given by Henry and Fred:

The next logical stage to that for a Java Programmer would be to create a FizzBuzz object that you initialize with your n value; maybe when you create it.

And that's where the fun really starts...

It may be a little early just yet, but the real power in Java is when you can get objects to do the things you want, not just methods.

HIH

Winston
 
Marshal
Posts: 76486
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:. . . It may be a little early just yet . . .

In my opinion “too early” means in the first five minutes of learning. Once you have six minutes' experience you should be getting objects to do the work. Obviously simple object; you won't go on to complicated objects until at least ten minutes' experience
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic