Post date: Jan 17, 2019 7:52:31 AM
/!\ Quiz 1 is during the 1st class next week (Week 4)
Console Input and Output
2.1 Screen Output
2.2 Console Input Using the Scanner Class
Recommended Self-Test Exercises:
p 93: Ex. 4.
p 99: Ex. 5, 6, and 7.
p 118: Ex. 12, 13, and 15.
Recommended Programming Projects:
p 127: Ex. 3 and 4.
Lab Exercises:
Write a program that reads 2 integer numbers from the keyboard and display the the result of the addition, subtraction, multiplication, and division of the first number with the second number.
Read length and width of a rectangle from the user and display the area of the rectangle.
Write a Java program that reads a First name, Middle name and Last name and displays only the Last name and the First name on the screen.
You must use nextLine() to read the full name and then use substring() and indexOf() in order to display only the last name and the first name in that order. Make sure to display the first name and last name with all capital letters.
Write a Java program that reads the radius of a circle and then displays the diameter ( 2 r ) , the circumference ( 2 π r ) and the area ( π r2 ) of the circle.
Write a Java program that reads a temperature in Celsius and convert it to Fahrenheit. Also, ask the user to enter a temperature in Fahrenheit and convert it to Celsius.
(°C × 9/5) + 32 = °F
(°F − 32) x 5/9 = °C
Write a Java program that reads a distance in Km and convert it to miles and read a distance in miles and converts it to Km.
1 kilometer is equal to 0.621371 miles
1 mile is equal to 1.609344 kilometers
Use nextLine() to read three strings/numbers from the user and print them in reverse order.
An automobile is used for commuting purposes. Write a program that takes as input the distance of the commute in km, the automobile’s fuel consumption rate in liters per 100 km, and the price of a liter of gas. The program should then output the cost of the commute.
Write a program that determines the change to be dispensed from a vending machine. An item in the machine can cost between 25 halalas and 1 riyal, in 25-halalas increments (25, 50, 75, or 100), and the machine accepts only a single riyal bill to pay for the item. For example, a possible sample dialog might be the following:
Enter price of item
(from 25 halalas to a riyal, in 25-halalas increments):
25
You bought an item for 25 halalas and gave me a riyal, so your change is:
a 25 halalas coin, and
a 50 halalas coin.
Write a program that inputs the name, quantity, and price of three items. The name may contain spaces. Output a bill with a tax rate of 5%. All prices should be output to two decimal places. The bill should be formatted in columns with 30 characters for the name, 10 characters for the quantity, 10 characters for the price, and 10 characters for the total. Sample input and output is shown as follows:
Input name of item 1: lollipops
Input quantity of item 1: 10
Input price of item 1: 0.50
Input name of item 2: diet soda
Input quantity of item 2: 3
Input price of item 2: 2.50
Input name of item 3: chocolate bar
Input quantity of item 3: 20
Input price of item 3: 0.75
Your bill:
Item Quantity Price Total
lollipops 10 0.50 5.00
diet soda 3 2.50 7.50
chocolate bar 20 0.75 15.00
Subtotal 27.50
5% sales tax 1.37
Total 28.87
See the Programming Projects section at the end of the chapter for more interesting exercises