Results 1 to 2 of 2
  1. #1
    mrsbeans is offline Member
    Join Date
    Mar 2015
    Posts
    1
    Rep Power
    0

    Default Graph using *'s & graphIt countIt methods help

    I am new to java and I have a homework problem I have been stuck on.
    The question is:
    Write a graph class that has methods countIt and graphIt. CountIt should use five counters (c0 c1 c2 c3 c4) to count the number of 0ís 1ís 2ís 3ís 4ís it is passed. Use a switch statement to determine which counter increment. Graphit should display the final counts in the form of a bar graph, with one bar for each count. Each bar should consist of a horizontal line of consecutive asterisks. If the largest count is greater than 50, scale the size of the bars so that the largest bar has 50 asterisks. Write a program that uses your Graph class. It should generate one million random integers all of which are 0, 1, 2, 3, 4. For each integer, your program should call countIt in a graph object. After all the integers have been counted< your program should call graphIt.


    I keep wanting to use Arrays, but the problem requires you to do it without them. I saw a post on here with the same question but using arrays, and it is making it harder to imagine doing the problem without arrays. I've been thinking about it for a week and I cant figure out how to scale down all the count values where the largest is 50 *'s. If anyone has suggestions, or can put me on the right track, that would greatly appreciated.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Graph using *'s & graphIt countIt methods help

    Okay, try this. Do it with arrays but don't use any loops or indices. So say you have an array of ints, named intArray. When you want to use the first value, use intArray[0]. When you want to use the second value, use intArray[1]. After you get done writing the code, replace all array element accesses with variables, (i.e. use c0 for intArray[0], c1 for intArray[1]).

    Scaling is related to ratios. So if you had 100,1000,10000 for values you could scale those to 1, 10, 100 by dividing each by 100. That should be enough of a hint.

    For additional help you will need to submit your attempt at writing the code.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 2
    Last Post: 07-12-2012, 11:04 PM
  2. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  3. Replies: 16
    Last Post: 03-21-2012, 09:41 AM
  4. Replies: 1
    Last Post: 10-23-2011, 12:37 PM
  5. Replies: 1
    Last Post: 10-05-2011, 12:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •