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: Briefly answer the following questions.
Note: These topics are covered in the Textbook

  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: + , - , / , *

  1. Code, debug, comment, and print the source code for each program. Programs must contain your name, date, a program message, and code comments. Points will be deducted on programs that are not well coded and commented and pages that are unstapled.
  2. Execute programs three times with different input.
  3. Print the output from all executions.


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. Assume all wage earners using this app will work at least 40 hours per week.



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



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



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: The Math class contains max and min functions.

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:
      Weight in pounds: 95.5
      Height in inches: 50
      BMI is 26.8573

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:
      Enter the Road Trip Miles: 900.5
      Enter the Miles per gallon: 25.5
      Enter the price per gallon: 3.55
      The road trip driving cost is $125.36

If you are like most people, you 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:
Enter the number of pennies, nickels, dimes, and quarters saved at the end of Week 2. Enter after each number:
Enter the number of pennies, nickels, dimes, and quarters saved at the end of Week 3. Enter after each number:
Enter the number of pennies, nickels, dimes, and quarters saved at the end of Week 4. Enter after each number:

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