CS110 Java Programming Assignment 1


Remember: Assigned work is to be an individual endeavor. Group or shared assignments will receive 0 points. Discussion about assignments is encouraged, but actual work must be independent.

Instructor: Trish Cornez


Part 1: topics covered in th textbook.

Briefly answer the following questions.

  1. What type of memory is usually volatile?
  2. What exactly is a byte and a bit and how are they used by a computer?
  3. What is main memory and secondary storage used for? Describe the difference between the two.
  4. What is RAM?
  5. What is a compiler?
  6. What does a Java compiler generate?
  7. What is a Java Virtual Machine?
  8. Define the term variable in a programming language.
  9. Define the term syntax in a programming language.



Part 2: Naming Variables        Assignment Statements         Using: + , - , / , *

  Remember...
  1. Code, debug, comment, and format the source code for each program.
  2. Programs must contain your name, date, a program message, and code comments.
  3. Points will be deducted on programs that are not well coded.
  4. Test run each program with the input shown in the sample execution.


PROGRAM 1:

Wages are paid at a standard hourly rate for 40 hours per week and at time and one half for overtime.
Write a Java program that calculates and displays the weekly pay, given the standard wage amount and the number of hours of overtime as inputs.
Important: Assume all wage earners using this app will work at least 40 hours per week.

Note:
Sample Execution:






PROGRAM 2:

Write a program that computes the cost per square inch of a pizza pie.
Input for the program should consist of the price (a real number) and the diameter in inches (a real number) of a full pizza pie.
Output should consist of the computed area of the pizza pie and the cost per square inch, in dollars and cents.

Note:
Sample Execution:






PROGRAM 3:

Write a Java program that asks the user to enter the price of a car (real), the down payment (real) and the number of years for the loan (integer). Calculate and output the monthly payment (real) of that car. Assume the sales tax rate is 7% and an interest rate is 9%. Use constant declarations for these rates.

Use the following formulae to perform the calculations:
tax amount = price of car * sales tax rate
total cost of car = price of car + tax amount
borrowed amount = total cost of car - down payment
interest amount = borrowed amount * interest rate
loan amount = borrowed amount + interest amount
monthly payment = loan amount / number of months of loan


Note:
Sample Execution:






PROGRAM 4:

Write a program that prompts the user for two integers and then displays the
sum, the difference, the product, the average, the absolute value of the difference, the larger of the two,
and the smaller of the two.

Hint: Use the Math class, which contains absolute value,and max and min functions.

Sample Execution:






PROGRAM 5:

Body Mass Index (BMI) is a measure of health on weight.
It can be calculated by taking your weight in kilograms and dividing,
by the square of your height in meters.

Write a program that prompts the user to enter a weight in pounds and your height in inches and displays the BMI.

TIP: One pound is 0.45359237 kilograms and one inch is 0.0254 meters.

Sample Execution:






PROGRAM 6:

Write a Road Trip Cost App that prompts the user to enter the distance driven during the road trip, the fuel efficiency of the car in miles per gallon, and the price per gallon. Assume the price per gallon will remain the same for the duration of the road trip. Display the driving cost of the road trip.

Sample Execution:






PROGRAM 7:

Many people collect a fair amount of change in your pocket. A painless savings plan is to dump all the loose change into a jar at the end of the week. However, we'd like some idea of the mount of money we'll have saved in a year so we can start thinking about what we want to buy.

In the this exercise you will write a Java probram to estimate the yearly savings based on the amount of change saved at the end of four weeks.
NOTE: It is important in this program that you analyze and limit your memory allocations - variable declarations. Efficiency can often mean recycling variables. Also, this program will require the use of constants.

The amount of change saved at the end of each week will be recorded as four numbers: the number of pennies, nickels, dimes, and quarters.
Here is an example of the input and output behavior of the program:

Enter the number of pennies, nickels, dimes, and quarters saved at the end of Week 1. Enter after each number:
8
2
5
3
Enter the number of pennies, nickels, dimes, and quarters saved at the end of Week 2. Enter after each number:
4
3
3
5
Enter the number of pennies, nickels, dimes, and quarters saved at the end of Week 3. Enter after each number:
8
5
6
3
Enter the number of pennies, nickels, dimes, and quarters saved at the end of Week 4. Enter after each number:
5
2
7
6

Over four weeks you have collected 25 Pennies, 12 Nickel(s), 21 Dime(s), and 17 Quarter(s).
This comes to $7 .20
Your weekly average is $1.80.
Your estimated yearly savings is $93.60