This is an assignment in my Java course where we have to use methods to solve problems. I have most of this one done but I’m having trouble.
Assignment:
Graphs help to display data. Create a table similar to the one shown below. The numbers generated are to be created as random numbers between $10,000 and $40,000. The numbers and graph indicate the sales from a wholesaler during the month of October. Note that they are not open seven days a week. (Sunday is the day they are closed, and Sundays fall on October 1, 8, 15, 22, and 29 during the year in question. The graph is generated in that each star represents $1,000 in sales.
Your graph will not look exactly like this since random numbers will be generated differently in each program. Print the dates in columns as shown (right-justified). Also, Mondays always have sales over $30,000 and Tuesdays always have sales over $20,000. Saturdays always have sales less than $15,000.
Sample output:
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 **********************
I have most of it here:
import java.util.*;
public class Prog310t
{
public static Integer randomNumbers (int minNumber, int maxNumber)
{
Random gen = new Random();
return (gen.nextInt(maxNumber - minNumber + 1) + minNumber);
}
public static String starLine (int numberOfAsterisks)
{
String stars = "";
for (int i = 0; i < numberOfAsterisks; i++)
stars = stars + "*";
return stars;
}
public static void main (String args [])
{
int randomNumber;
System.out.println("Day\tDaily\tSales Graph");
for (int x = 2; x <= 31; x++)
{
if (x == 8 || x == 15 || x == 22 || x == 29)
{
System.out.println();
}
if (x == 2 || x == 9 || x == 16 || x == 23 || x == 30)
{
randomNumber = randomNumbers(30000, 40000);
System.out.println(x + "\t" + randomNumber + "\t" + starLine(randomNumber / 1000));
}
if (x == 3 || x == 10 || x == 17 || x == 24 || x == 31)
{
randomNumber = randomNumbers(20000, 40000);
System.out.println(x + "\t" + randomNumber + "\t" + starLine(randomNumber / 1000));
}
if (x == 7 || x == 14 || x == 21 || x == 28)
{
randomNumber = randomNumbers(10000, 15000);
System.out.println(x + "\t" + randomNumber + "\t" + starLine(randomNumber / 1000));
}
}
}
}
How would I go about making it output the other days? It only outputs the Sundays (blanks), Mondays, Tuesdays, and Saturdays. How do I make it output the other days without having to put every single day number?
Use a for loop for the days, that only allows 31 days, nested within a for loop for weeks. Check the specialty days and generate the random number based upon the day.