Assignments Java Chapter 2



Assignments Java Chapter 2

• Notes on sections 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9

• Multiple choice p. 111-113 #1-10

• True/False p. 113 #1-8

• Short Answer p. 114-116 #4-7

• Short Answer p. 114-116 #8-12

• Key Concepts p. 109 (all except last 3)

• Self Review Questions p. 110-111 #1-18 (answers on p. 118-120)

#1 – Use the TempConverter class given on page 77. Modify it by removing the constants and doing the math all on one line. Both temperature variables should be ints. Add on code to convert from F to C. Instead of hardcoding the value to convert, use Keyboard input. Therefore that program will do two conversions with Keyboard input for both. Round answers to the nearest whole number (see page 79 for help with rounding). Formula is:

#2 – Write an application that reads in values from the user representing a time in hours, minutes, and seconds. Then print the same time in seconds. For example, 1 hour 28 minutes 42 seconds is equal to 5322 seconds. Then make the problems work in reverse. That is, read in from the user, a value representing a number of seconds then print the same amount of time in hours, minutes and seconds. For example 9999 seconds is equal to 2 hours 46 minutes 39 seconds. Combine these together in a class called TimeConverter that has only 4 integers.

#3 – Write an application that reads the (x,y) coordinates for two points. Compute the distance between the two points. The x and y coordinates will be integers and the distance will be a double. Name the class DistanceFormula. Rounding is not needed. Use the Math.pow() and Math.sqrt() members of the Math class. Here is the distance formula:

[pic]

#4 – Write an application that reads the radius of a sphere and prints its volume and surface area. Make a class called SphereCalculations. The radius should be a double. Use the DecimalFormat class to print the output to 4 decimal places. Use the Math.pow() and Math.PI members of the Math class. Here are the formulas:

[pic] [pic]

#5 – Name this class MoneyChanger. Write an application that determines the value of the coins in a jar and prints the total in dollars and cents. Read integer values that represent the number of quarters, dimes, nickels, and pennies. Use a DecimalFormat to print the output as currency.

For the second half of this application, reverse the problem. In this reversal, read the amount of money in as a double (i.e. 4.67). Then convert that money and store it in an int variable (i.e. 467). Then display the coins that would make up that money. These coins should be the least number of coins. For example, 2 quarters 4 dimes 3 nickels 7 pennies is $1.12 in the initial problem and 1.12 is 4 quarters 1 dimes 0 nickels 2 pennies in the reversal.

#6 – Name this class PhoneNumber. Write an application creates and prints a random phone number of the form xxx-xxx-xxxx. Include the dashes in the output. Do not let the first three digits contain an 8 or 9, and make sure the second set of three digits is not greater than 742. Hint: Some digits have to be generated independently while some digits relate together. Make sure zeroes print when needed by using the DecimalFormat class. Do the problem once using the Random class to generate the random numbers then duplicate the application again using the Math class to generate the random numbers. Your final code will produce 2 random phone numbers, one by each method.

#7 – Name this class Buffox. Concatenate a String that has the following characters: First letter is an uppercase consonant, second letter is a lowercase vowel, third and fourth letters are the same double-able lowercase consonant, fifth letter is an o, sixth letter is either x, r, or n. Print the String at the end. Choose the character by randomly picking a number in range based on the length of the String parameter and isolate that character using the charAt method. Keep the number of variables down, probably no more than two Strings, one int, and one char.

-----------------------

100ºC=212ºF

32ºF=0ºC

46ºC = 115ºF

72ºF = 22ºC

[pic]

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download