6A
The Java Sub Shop has only two types of meat for their subs: pastrami and chicken. They sell a 6 inch and a 12 inch version of each. The prices are in the table below. Customers can order extra meat which adds $1.50 to the price regardless of size. Write the class SubSandwich.
| 6 inch | 12 inch | |
| chicken | $5.50 | $8.95 |
| pastrami | $6.95 | $9.50 |
An int is used to represent the type of meat. 0 is chicken and 1 is pastrami. Define and use the constants below to avoid errors. This is a technique that is often used
SubSandwich has a constructor that takes three parameters.
public SubSandwich(int theType, int theSize, boolean extraMeat)If the type is other than chicken or pastrami, set the type to pastrami. (That is, if the type is not CHICKEN or PASTRAMI, set it to PASTRAMI. Do not test for 0 and 1 but rather use the constants)
If size is a number other than 6 or 12, set it to 12.
It also has methods
public int getSize() - gets the size of the subpublic void setSize(int newSize) - sets a new size for the sub. Remember the size must be either 6 or 12.public boolean isExtraMeat() - returns true if there is extra meat, otherwise false.public String getType() - gets the type of SubSandwich as a string: either "chicken" or "pastrami"public double getCost() - gets the cost of this SubSandwichUse proper if structure and do not duplicate code in the branches
Provide Javadoc
For the draft, provide the instance variables, implement the constructor and getSize, isExtraMeat, and getType methods. Provide stub for getCost and setSize so that your class will compile with the tester. Provide all the Javadoc
6B
Complete the class LoopyFun that contains the methods specified below. There is no constructor or instance variables.
public int getPermutationCount(int n) takes an integer parameter and returns the number of unique ways we could form a line of that many people. If the integer were 3, there are 6 unique ways 3 people could form a line. You can calculate the number like this 1 * 2 * 3. You must use a loop to get credit. If n is less than or equal to 0, there are 0 permutations.public double sumSeries(int n) Calculates the sum of the following series for n terms. n must be positive. If it is not, return 0. Use a looppublic int product(int n) Asks the user for n integers and returns the product of the integers. If n is 5, you will prompt the user 5 times to enter a number. You must use a loop to get credit. Use prompts that look like these in the loop: Provide Javadoc for the methods
Note that there are 2 testers for the final version
For the draft, implement getPermutationCount and provide its Javadoc
6C
Complete the class LoopyText which has a constructor that takes a String of text. Implement the following methods.
public String getText() returns the text public String getUpperCase() gets a String consisting of the uppercase letters in the text. You are provided with a helper method, isUpperCase()which takes a String consisting of one characterpublic int getECount() gets the number of e's in the String, either upper or lower case. Do not change the instance variablepublic String initials() that returns a string consisting of the first character of every word in the string. If the string is the empty string, return the empty String. indexOf (" ", fromIndex) to control the loop and to determine where a new word starts. Remember indexOf returns -1 if the space is not in the search stringProvide Javadoc
For the draft, provide the instance variable, constructor, getText() and getUpperCase() methods along with the necessary Javadoc