![]() |
CS 111 - Introduction to Computer Science
Homework #3 |
NOTE: Homework that does not compile or is not submitted according to instructions may receive no credit.
1. Division: Create a program Division.java that has the user enter two integers using the Scanner class, which are then used to compute both the floating point and integer division results as follows (user input underlined):
Please enter integer a: 9 Please enter integer b: 4 Floating point division: a/b = 2.250000 Integer division: a/b = 2 remainder 1
2. Alma Mater Mad-Libs: Create a program, again using the Scanner class, MadLibs.java that asks for parts of speech and fills them into the first verse of the Gettysburg Alma Mater as follows (user input underlined to commemorate annual off-campus fertilization day):
Plural noun: odors Plural noun: dorms Verb: breathe Verb: collapse As softly the evening odors, Are veiling the campus dorms, We breathe, a band of good fellows, To collapse in the twilight hours.
(Note that the user input is inserted at specific positions in the output.)
3. Five Digits: Exercise 2.30. Call your program FiveDigits.java.
4. Cast, Round, Floor, Ceiling: Create a program DoubleToInt.java that uses the Scanner method nextDouble to read a double value x from the user, and then report each of the following values and whether each value is ">", "<", or "==" to x.
Example transcript (user input underlined):
Please enter a double value: -.9 (int) -0.900000 == 0 > -0.900000 (int) Math.round(-0.900000) == -1 < -0.900000 (int) Math.floor(-0.900000) == -1 < -0.900000 (int) Math.ceil(-0.900000) == 0 > -0.900000