7A
Finish the InputWork
class to read a set of integers. Stop reading input when a non-integer is read. Use this exact prompt: System.out.print("Enter an integer 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 non-integer.
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 the order given above. If there were no inputs, just print "no input"
Hint: To find the next to the smallest, you will need two variables, min and secondMin. You can not initialize them to 0 since the numbers can be negative, so use a boolean flag first
(see Udacity videos), and if first
is true (this is the first time through the loop), initialize both min
and secondMin
to the first input and set first to false
. When you read a number, if it is smaller than min
, set secondMin
to the value of min
and assign the new input to min
. If the input is greater than min
but less than secondMin
, set secondMin
to the input.
For the draft, read the numbers and print them, one to a line. Quit on a non-integer. Use the prompt given above.
7B
Complete the TenCircle class to draw ten circles that have radius of 10, 20, ..., 100. They touch the line x = 0 at the left and the line y = 200 at the bottom. (are tangent to the line) Draw the smallest circle first. You must use a loop in your solution.
Another way to look at this is that the circles are inside a right angle consisting of the lines x = 0 and y = 200. The circles are tangent to the sides of the right angle.
Here is an image.
You will receive no credit for a solution that draws ten separate circles even if it passes Codecheck.
For the draft: just draw the first circle
7C
Write a class CharacterSearch.
It has a constructor that takes a string consisting of one character as a parameter. If the String contains more than one character. Use the first character, and assign it to the instance variable, character.
It has methods:
public int letterCount(String phrase
) Returns the number of times the letter for this class occurs in the phrase. Note B and b are different letterspublic int doubleIndex(String phrase)
Looks for the first place the letter for the class appears consecutively (right next to each other) It returns the index of the first of the pair or -1 if the letter does not appear consecutively. For example if the CharacterSearch is constructed with the letter "p" and the phase is "Apples are best" double index will return 1public String getCharacter()
gets the character for this CharacterSearch. Already coded for youFor the draft, implement the constructor and implement the methods as stubs. Provide Javadoc