6A

The Java Ice Cream store sells, what else, ice cream cones.They sell either one scoop or two in either a plain cone or a wallfle cone. There is a table of the costs below

  waffle cone plain cone
1 scoop 2.75 2.00
2 scoops 4.50 4.25
     

Complete the class IceCreamCone. It has a constructor that takes two parameters:

It also has a methods:

In the constructor, if the cone type is a String other than "waffle cone" or "plain cone" set it to waffle cone.

If the number of scoops is less that 0, set number of scoops to 1. If the number of scoops is greater than 2, set number of scoops to 2. Otherwise set it to the value of the parameter.

Use nested if statements. And define and use these constants

For the draft, provide the Javadoc for the constructor and methods. Implement the constructor and the getScoops() method. Implement stubs for getCost() and setScoops()  so that your class will compile with the tester.

6A draft:
6A final:

6B

Implement a class LoopUtil which contains several methods to work with loops.

public int sumEven(int value) Return the sum of all the positive even numbers less than the given value. Use a for loop.

public int largestPowerLessThan(int value) gets the largest power of 2 (an integer) less than the given value (also an integer). If value is 16, you will return 3 because 23 = 8 which is less than 16 but 24 = 16 which is not less than 16. Note you return the exponent (3) not the value of the exponential expression (8) Use a while loop.

If there are no powers of 2 less than the target, return -1. Think about the values for which there will be no power of 2 that is smaller than the value. Hint. What is 20, 21?

public double average(int limit) Asks the user for limit integers and returns the average of the integers. If limit is 5, you will ask the user to enter a number 5 times. Use a prompt that looks like this in the loop:

Enter integer 1:
Enter integer 2:
...
Enter integer 5:

If limit is <= 0 return 0. (We do not want to divide by 0)

The output might look something like this is if limit is 2

Enter integer 1:
25
Enter integer 2:
4
14.5

For the draft, implement the first method.

 

6B draft:
6B final:

6C

Implement the following methods for FirstAndLast class.

A constructor that takes a single String parameter has been implemented for you.

That words will be separated by spaces, and you can assume the phase is well-behaved

A method called firstLetters that returns a string consisting of the first character of every word in the string.

A method called lastLetters that returns a string consisting of the last letter of every word in the string. The trickiest part here is that if the last character before a space is not a letter (like a , or a ?), you need to get the character before it. You can assume that there is never two consecutive non-letters

indexOf is a handy method to use here

There is a helper method isLetter included in the starter class which takes a string of one character and returns true if the character is a letter otherwise it returns false. Don't worry that the method has a modifier of static. We will cover static later. Right now just call the method with a String argument of one character. Include javadoc for the every public class, method and constructor.

There is also methods setSentence() and getSentence() to set and get a new string variable coded for you.

For the draft, implement firstLetter to return the first letter of the first word. Implement lastLetter as a stub. Include Javadoc for both methods.

6C draft:
6C final: