• Post Reply Bookmark Topic Watch Topic
  • New Topic

Modulus Counter  RSS feed

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am taking a java class and one of our assignments is to create a modulus counter class that is tested by a Driver class. I was just curious if anyone had any ideas on how to start. Ive been doing some research but have yet to find anything. Thank you.
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you describe what a "modulus counter class" is?
 
Jackson Daniels
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Modify the Counter class such that is becomes a "modulus" counter. (You may leave the name of the class unchanged.) When a modulus counter is created, the maximum value of the count is specified. The counter should never be able to reach this maximum value. Instead, it should wrap around to 0. (E.g., If m is the modulus, incrementing the counter would give: 0, 1, 2, ..., m-1, 0, 1, 2, ..., m-1, 0, 1, 2, ... In other words, instead of reaching m, it goes back to 0.) Test your counter at this point and continue when you are satisfied that you've implemented it correctly."

Basically (I think) the functions is supposed to print like:

0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the modulus were 6, I would agree. Do you know about the modulus operator in Java?

Write down how you might use this to create a counter. Then (and I assume you know how to create a Class) try writing some code and post it here.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
…and welcome to the Ranch
 
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack Daniels wrote:
"...

Basically (I think) the functions is supposed to print like:

0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5

You are correct, if you lookup the modulus function and what it does, it should be fairly obvious what to do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!