Professional Documents
Culture Documents
ZYBooks -- CMP-167: Programming Methods I by following the link for each problem.
Problem definitions for this homework assignment are found on the pages that follow below.
Text that is underlined represents values that are calculated by the program.
Homework 2-1
secondResult = The product of secondInt and thirdInt divided by the sum of secondInt and firstInt
firstInt, secondInt, and thirdInt represent the three integers entered by the user.
Enter firstInt:
Enter secondInt:
Enter thirdInt:
Homework 2-2
Write a program that asks the user to enter a distance measured in inches.
The program must then determine and output the equivalent number of yards, feet, and inches.
Note:
3 feet = 1 yard
12 inches = 1 foot
Use plurals "yards" , “feet”, and "inches" for all outputs (even where it is grammatically incorrect).
The prompt to the user to enter the number of inches must be:
Homework 2-3
Write a program that prompts the user for a double value representing a radius.
The program must then use the radius to determine and output the following:
circleCircumference = 2πr
circleArea = πr2
sphereArea = 4πr2
sphereVolume = (4/3)πr3
Note:
Recall that floating point arithmetic rounds differently for different formulations of a calculation.
Enter radius:
Homework 2-4
Write a program that prompts the user for the coordinates of two points in a Cartesian Plane.
The program must then compute and output the distance between those points.
Note:
In a cartesian plane the distance between two points, P1 = (x1, y1) and P2 = (x2, y2), is given by the formula
( x2 - x 1 ) 2 + ( y 2 - y 1 ) 2
dist = √
The prompt to the user must be:
Coordinates for P1
Enter x1:
Enter y1:
Coordinates for P2
Enter x2:
Enter y2:
Homework 2-5
Write a Java program that asks the user to enter four words.
The program should then analyze each of the four words so that it can report the length of each word as well
as the positions of the five vowels within each word.
For a sample run where the user enters the words: she smiles third frisbee
the console screen must look as follows:
Enter 4 words:
she smiles third frisbee
Word 1 = "she" Length = 3 position of vowels: 'a' = -1, 'e' = 2, 'i' = -1, 'o' = -1, 'u' = -1
Word 2 = "smiles" Length = 6 position of vowels: 'a' = -1, 'e' = 4, 'i' = 2, 'o' = -1, 'u' = -1
Word 3 = "third" Length = 5 position of vowels: 'a' = -1, 'e' = -1, 'i' = 2, 'o' = -1, 'u' = -1
Word 4 = "frisbee" Length = 7 position of vowels: 'a' = -1, 'e' = 5, 'i' = 2, 'o' = -1, 'u' = -1
For a sample run where the user enters the words: shoe shoe chime wallabees
the console screen must look as follows:
Enter 4 words:
shoe shoe chime wallabees
Word 1 = "shoe" Length = 4 position of vowels: 'a' = -1, 'e' = 3, 'i' = -1, 'o' = 2, 'u' = -1
Word 2 = "shoe" Length = 4 position of vowels: 'a' = -1, 'e' = 3, 'i' = -1, 'o' = 2, 'u' = -1
Word 3 = "chime" Length = 5 position of vowels: 'a' = -1, 'e' = 4, 'i' = 2, 'o' = -1, 'u' = -1
Word 4 = "wallabees" Length = 9 position of vowels: 'a' = 1, 'e' = 6, 'i' = -1, 'o' = -1, 'u' = -1
Note:
For multiple instances of a vowel, only the index of the first occurrence will be indicated.
An index of -1 indicates that the vowel does not occur in the word.
Homework 2-6
You just returned from a trip. The countries you visited were Jamaica, The Dominican Republic, and Cuba.
You arrived back in the United States with some foreign currency from these countries.
Write a Java program that prompts the user for an amount of each of these foreign currencies.
The program should convert these combined amounts to the total equivalent number of US Dollars.
The program should then output the result.
Hint:
Be very careful with formatting your output. The number should look like it represents money.