CS46A Fall 18

7A

The Dow Jones Industrial Average (DJIA) is a stock market index that shows how the prices of 30 large, publicly-owned companies change over time. The value of the DJIA can be positive, negative or 0 at the end of a given day.

Write an application (a program that has a main methods) called DJIA to read a collection of doubles, each representing a positive, negative, or 0 change in the price for the day.. The input will terminate when the user enters a value that can not be converted to a double.

Use this for the first promptSystem.out.print("Enter the change for the day or Q to quit: ");

I made a mistake in the second prompt. If I changed the code, it would mess up people who have already submitted.

So you need to use this as the second prompt: System.out.print("Enter net income or Q to quit: "); (changed Oct 12)

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

Do the following:

Only print the numbers if at least 1 value was entered. Otherwise print "No values entered"

You will read the inputs one at a time and do all the processing as you go. No arrays for this

The outputs should be on separate lines and in this order

You will need to initialize the maximum to the first input. You will temporarily set it to 0 when you declare it (to keep the compiler happy) but then initialize it to the first input in the loop. You can use a boolean variable as a flag to determine if this is the first input as discussed in the videos.

No Javadoc required when there is only a main method.

For the draft, read the numbers and print them, one to a line. You will use a while loop. Quit when the input can not be converted to a double. (That means hasNextDouble returns false.) Use the prompt given above. If no numbers were entered, print "No values entered"

7A draft:
7A final:

7B

A digital image is made up of pixels. Each pixel is a tiny square of a given color. The Picture class has methods to manipulate pixels. Each pixel has x, y coordinates. You can think of the image as being rows of pixels. The x coordinate is the row and the y coordinate is the position within the row. The x coordinate varies from 0 to the width of the image, and the y coordinate varies from 0 to the height of the image. You will use nested loops to pick up each pixel in the image and then do something with it. Worked Example 6.2 gives an example of iterating through all the pixels in an image.

Your task is to write a class FramedPicture. A FramedPicture has a constructor that takes a Picture object as a parameter.

It has a method frame which returns a Picture object with the original image in a round frame around. See the output below. You should set all the pixels outside the circle to black. The center of the circle is the center of the image, and the radius is 40 percent of the width or height, whichever is smaller. Find the center by dividing the width and the height of the image by 2. Get the width and height by using methods of the Picture class so that the code will work if you use any image.

public Picture frame() - gets the image with a round frame around

You will need to import the Horstmann graphics package into your project.

Hint: If the distance of the pixel from the center of the circle is greater than the radius, set the pixel color at that x, y to Color.BLACK. Think Pythagorean Theorem

Here are the original images of billy.jpg and taran.png

cat sleepingboy sleeping

Here is the a screenshot of the output

output for 7c

Provide Javadoc

For the draft, implement the constructor and implement the frame() method to make the first row of pixels red (We are using red because it is more visible on the image than black. You will use black in the final). The y coordinate of every pixel in the first row is 0. Use Picture's getWidth method to get the width of the image.

7B draft:
7B final:

C

Write a class LetterSearcher.

It has a constructor that takes a string consisting of a single letter as a parameter. If the String contains more than one letter. Use the first character, and assign it to the instance variable.

It has methods:

Provide Javadoc

For the draft, define the instance variables, implement the constructor and the getLetter method. Implement the other methods as stubs. Provide Javadoc. Remember that when the method is a stub, it will not return the correct answer when the tester is run.

7C draft:
7C final: