Assignment 17
Due Monday, November 27 at 9:20am on Canvas

Assignment 17.1: My Salary (10 pts)

• Open up Eclipse and create a new Java project called Salary.
• Copy and paste the starter code below into the file.
• NOTE: Do not change the starter code! All you need to do is add to it.
import java.util.Scanner;

public class Salary {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int hours;
double hourly_wage;
double weekly_salary = 0;
double monthly_salary = 0;
double yearly_salary = 0;
System.out.println("This program will calculate your weekly, monthly "
+ "and yearly salary!");
hourly_wage = input.nextDouble();
System.out.print("Please enter the number of hours you work each week: ");
hours = input.nextInt();

//call methods below
weekly_salary = //method call goes here
monthly_salary = //method call goes here
yearly_salary = //method call goes here

System.out.printf("You make \$%.2f per week\n", weekly_salary);
System.out.printf("You make \$%.2f per month\n", monthly_salary);
System.out.printf("You make \$%.2f per year\n", yearly_salary);

}

}

• Now write three methods as follows and place them above main:
• weeklySalary()
Takes in an integer argument for the number of hours worked each week
Takes in a double argument for the hourly wage
Returns a double for the weekly salary
• monthlySalary()
Takes in an integer argument for the number of hours worked each week
Takes in a double argument for the hourly wage
Returns a double for the monthly salary
• yearlySalary()
Takes in an integer argument for the number of hours worked each week
Takes in a double argument for the hourly wage
Returns a double for the yearly salary
Assume that you work 50 weeks a year (2 weeks vacation)
• Add a method call and store the result as the appropriate variable.
weekly_salary = //method call goes here
monthly_salary = //method call goes here
yearly_salary = //method call goes here
• Now, run your code and verify that it prints the correct values for each salary type.
• Your output should look identical to the following (except user input will vary):

Assignment 17.2: Vowels Again

• Write a method with the following signature:
`public static int countVowels(string str) `
• `The method returns a count of the letters in the `string` parameter that are vowels (A, E, I, O, U, a, e, i, o, u)`
• Hint: You've done this same thing on your previous assignment, just not with a method.
• For this assignment we are going to "outsource" the work of counting vowels to a method named countVowels.

Part 1:

• Copy and paste the starter code into a class named Vowels:

int countVowels(string s)
{

}

public static void main(String[] args)

{
String sentence;
int numVowels;
//Prompt user to enter a sentence

//call the countVowels method, passing it the sentence as a parameter
//& storing result as numVowels

//print out the number of vowels in the sentence

System.out.println("There are " + numVowels + " in your sentence.");

}

• Your program should first prompt the user to enter a sentence.
• Then, you should pass the sentence variable into your method and store the return value in your numVowels variable.
• Test out your code with various sentences.
• The program should now work like this:

Enter a sentence: I love cookies a lot!

There are 9 vowels in your sentence.

Part 2:

• Add a while loop to your code to repeatedly prompt the user to enter a sentence or q to quit.
• The program should accept q, Q, quit, or Quit as signals to exit the loop.
• When you are finished, your program should work like this:

Enter a sentence or q to quit: I love cookies a lot!

There are 9 vowels in your sentence.

Enter a sentence or q to quit: I wouldn't mind a piece of cake, either.

There are 14 vowels in your sentence.

Enter a sentence or q to quit: Q

Goodbye!

• When you are certain it is working properly submit to Canvas.

Assignment 17.3: Getting Methodical

• Copy and paste the starter code into a new file called Methodical.java
• Write the required methods as described by the comments (i.e. you fill in the body of the method).
• Then, run the code when you are finished to see if you wrote the methods correctly.
• Check the test results and make any alterations to your methods as necessary.
• When all of the tests pass, upload your code to Canvas.

/*
* @author
* CIS 36A
*
*/

public class Methodical {
/*
* Given two int values, returns their sum.
* Unless the two values are the same, then return double their sum.
* sumDouble(1, 2) → 3
* sumDouble(3, 2) → 5
* sumDouble(2, 2) → 8
*/

public static int sumDouble(int a, int b){
return 0;
}

/*
* Given 2 ints, a and b, return true if one of them is 10
* or if their sum is 10.
* makes10(9, 10) → true
* makes10(9, 9) → false
* makes10(1, 9) → true
*/

public static boolean makes10(int a, int b) {
return false;
}
/*
* We have two monkeys, a and b, and the parameters
* aSmile and bSmile indicate if each is smiling.
* We are in trouble if they are both smiling
* or if neither of them is smiling.
* Return true if we are in trouble.
* monkeyTrouble(true, true) → true
* monkeyTrouble(false, false) → true
* monkeyTrouble(true, false) → false
*/

public static boolean monkeyTrouble(boolean aSmile, boolean bSmile) {
return false;
}

/*Return true if the given non-negative number is a multiple of 3
* or a multiple of 5. Use the % "modulus" operator
* or35(3) → true
* or35(10) → true
* or35(8) → false
* */

public static boolean or35(int a) {
return false;
}

/*
* Given a string, return a new string where "not " has been added to the front.
* However, if the string already begins with "not", return the string unchanged.
* notString("candy") → "not candy"
* notString("x") → "not x"
*/

public static String notString(String str) {
return "";
}

/*
* Given a string, return a new string where the first and last chars have been exchanged
* frontBack("code") → "eodc"
* frontBack("a") → "a"
* frontBack("ab") → "ba"
*/

public static String frontBack(String str) {
return "";
}

/*
* We'll say that a number is "teen" if it is in the range 13..19 inclusive.
* Given 3 int values, return true if 1 or more of them is/are teen.
* hasTeen(13, 20, 10) → true
* hasTeen(20, 19, 10) → true
* hasTeen(20, 10, 13) → true
*/

public static boolean hasTeen(int num1, int num2, int num3) {
return false;
}

public static void main(String[] args)
{
int result;
String value;
System.out.println("***Testing sumDouble***\n");
result = sumDouble(1, 2);
System.out.println("Should print 3: " + result);
result = sumDouble(3, 2);
System.out.println("Should print 5: " + result);
result = sumDouble(2, 2);
System.out.println("Should print 8: " + result +"\n");

System.out.println("***Testing makes10***\n");
System.out.println("Should be true: " + answer);
System.out.println("Should be false: " + answer);
System.out.println("Should be true: " + answer + "\n");

System.out.println("***Testing monkeyTrouble***\n");
System.out.println("Should be true: " + answer);
System.out.println("Should be true: " + answer);
System.out.println("Should be false: " + answer + "\n");

System.out.println("***Testing or35***\n");
System.out.println("Should be true: " + answer);
System.out.println("Should be true: " + answer);
System.out.println("Should be false: " + answer + "\n");

System.out.println("***Testing notString***\n");
value = notString("candy");
System.out.println("Should be not candy: " + value);
value = notString("x");
System.out.println("Should be not x: " + value);
System.out.println("Should be not bad: " + value + "\n");

System.out.println("***Testing frontBack***\n");
value = frontBack("code");
System.out.println("Should be eodc: " + value);
value = frontBack("a");
System.out.println("Should be a: " + value);
value = frontBack("ab");
System.out.println("Should be ba: " + value + "\n");

System.out.println("***Testing hasTeen***\n");