CS49J

Remember not to create packages. Use the default package

7A

Write an application called  InputProcessing. In the main method you will use a loop to read a collection of doubles. Stop reading when the input can not be converted to a double. Use this exact prompt: System.out.print("Enter a double or Q to quit: "); Copy and paste it. That is what I did when I coded the model solution.

Note: you will actually quit on any string that can not be converted to a double.

Do the following things:

You will only read the inputs one time and do all the processing as you go. No arrays yet.

The outputs should be on separate lines and in this order

the integers (or nothing)
the minimum number
the average of all the numbers or 0 if there are no positive numbers

If there were no inputs at all, just print "no input" and nothing else

Hint: To find the minimum number, . You can should initialize a variable to the first input. Use a boolean flag first initializes to true. If first is true (this is the first time through the loop), initialize the minimum to the first input and set first to false. After that when you read a number, you can use the find minimum algorithm.

Codecheck URL

7B

Create a class RandomStar which models a star burst of random lines radiating in all directions from a given point. The constructor takes the x, y coordinates of the center of the star, the maximum distance of the x and y coordinates of the radiating lines from the center of the RandomStar, and the number of lines to draw.

The draw method takes the graphical context as a parameter. It draws the specified number of lines. Each line has one end point at the center of the RandomStar. The other end has x and y coordinates each of which are less than the maximum distance specified from the center.

Your output will look like this

screenshot 7b

Modified Feb 26

Here is the starter flle for RandomStar. Use this Random object created with a seed so that your code will pase Codecheck

public class RandomStar
{
   private Random gen;

   
   public RandomStar(int x, int y, int maxDistance, int numberOfLines)
   {
      gen = new Random(987654321);
      //... your code

   }
   
}

Codecheck URL

7C

In this problem you will model a tile floor. The tile floor consists of some number of rows of (filled) colored squares. Each row contains some number of squares. Each square has a side of 10 pixels and is separated from its neighbors by 3 pixels. Each square is a random color: either red, green, blue, black, and cyan. Complete the class TileFloor. Use the constants defined for you in the starter code. You must use nested loops. Draw the rows and then the columns to match Codecheck output.

For the colors, use the Color constants in the Color class. (Color.RED etc)

The TileFloor will have two constructors

The TileFloor will have these methods

There is trick you can use to determine which color to return. Notice each color has been assigned an integer 0 to 4 in the constants. You can generate a random number between 0 (inclusive) and 5 (exclusive). If the random number is RED (0), return Color.RED. If the random number is GREEN (1), return Color.GREEN. Use the defined constants, not the numbers 0, 1 etc.

Provide Javadoc

TileFloorComponent and TileFloorViewer are provided in this zip folder.

Because the Random object is created with a seed, you will all get the same drawing every time. That is so Codecheck can check it.

Your output will look like this

screenshot

Codecheck URL