# Asterisk Graph

Printable View

• January 4th, 2013, 07:03 PM
ThatBeast
Asterisk Graph
Hi There,

I have a question that I can't seem to solve on my own.

I'm supposed to create a graph using asterisks' that follows the month of October for a store. The point is that using random numbers between 10000-40000 it is supposed to make a graph using 1 asterisk for every 1000 in the random number. Here is were it gets harder. On Sunday the store is closed. On Monday the store always earns over 30000. On Tue the store always earns over 20000. And Saturdays the store always earns less than 15000. Here is what I have so far.
Code :

```import java.util.*; import java.math.*; import java.util.Random; class ChartingSales { public static void main(String args[]) { System.out.println("Day\tDaily\tSales Graph"); RegDay(); }     static void RegDay() { Random rand = new Random(); int Reg = rand.nextInt(40000-10000) + 10000; int Mon = rand.nextInt(40000-30000) + 30000; int Tue = rand.nextInt(40000-20000) + 20000; int Sat = rand.nextInt(15000-10000) + 10000; int i = 0; while(i < 31) { i++; if(i == 1 || i == 8 || i == 15 || i == 22 || i == 29) { System.out.println(""); }   else if(i == 2 || i == 9 || i == 16 || i == 23 || i == 30) { System.out.println(i+"\t"+Mon+"\t"); for(int j = 0; j<Mon;j=j+1000); { System.out.print("*"); } } else if(i == 3 || i == 10 || i == 17 || i == 24 || i == 31) { System.out.println(i+"\t"+Tue+"\t"); for(int j = 0; j<Tue;j=j+1000); { System.out.print("*"); } } else if(i == 6 || i == 13 || i == 20 || i == 27) { System.out.println(i+"\t"+Sat+"\t"); for(int j = 0; j<Sat;j=j+1000); { System.out.print("*"); } } else { System.out.println(i+"\t"+Reg+"\t"); for(int j = 0; j<Reg;j=j+1000); { System.out.print("*"); } } } } }```

The output code should look like this(Since random numbers are used the numbers will vary.):
Day Daily Sales Graph
2 37081 *************************************
3 28355 ****************************
4 39158 ***************************************
5 24904 ************************
6 28879 ****************************
7 13348 *************

9 38791 **************************************
10 32564 ********************************
11 23867 ***********************
12 18154 ******************
13 25830 ***********************
14 14092 **************

16 36861 ************************************
17 26207 ************************
18 10921 **********
19 16573 ****************
20 33423 *********************************
21 12766 ************

23 33770 *********************************
24 28823 **************************
25 38883 **************************************
26 20959 ******************
27 16262 ****************
28 13269 *************

30 33557 *********************************
31 22579 **********************

Help would be amazing!!!
• January 4th, 2013, 07:21 PM
Norm
Re: Asterisk Graph
What does the program's output look like now? Please post the program's current output and add some comments saying what is wrong with it.

Quote:

Since random numbers are used the numbers will vary.)
The random number series can be made the same for each new execution by using a seed arg to the Random(12345) constructor.

The code needs to be properly formatted using indentations of 3-4 spaces to show nested logic. Too many statements start in almost the same column making the code hard to read and understand.
• January 4th, 2013, 08:11 PM
ThatBeast
Re: Asterisk Graph
The current output looks like this:

Day Daily Sales Graph

2 37944
*3 36443
*4 23057
*5 23057
*6 12651
*7 23057
*
9 37944
*10 36443
*11 23057
*12 23057
*13 12651
*14 23057
*
16 37944
*17 36443
*18 23057
*19 23057
*20 12651
*21 23057
*
23 37944
*24 36443
*25 23057
*26 23057
*27 12651
*28 23057
*
30 37944
*31 36443
*

As you can see the Asterisks don't align where they are supposed to be and for some reason they aren't being displayed enough times. Another problem I have is to get the numbers random for every day. I created a variable to store the random numbers but I need new numbers for each day.
• January 4th, 2013, 08:22 PM
Norm
Re: Asterisk Graph
Quote:

30 37944
*31 36443
*
It looks like there is a newline output after the DailySales number and before the *. Check the calls to the printing methods to see where the newline is coming from.
Also why is the day number printed on the same line following the *? Shouldn't it be at the start of a line?

Quote:

they aren't being displayed enough times.
They are all displayed ONLY ONE TIME. No lines have more than one *.
Try debugging the code by printing out the value of the loop control variable (j) inside one of the loops to see how its value is changing and why the code in the loop doesn't execute more than once.

Suggestion: make a method that prints *s on a line and pass it the number of *s to print instead of having so many separate loops to print the *s