• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Modulus Counter

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76872
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
…and welcome to the Ranch
 
Rancher
Posts: 1059
27
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic