Skip to main content

Homework 1: Variables & I/O

Due: 2024-09-16 23:59:00EDT

In this assignment you will be working with variables, and reading in user data.

Note, in the examples, * indicates user input.

1. Groceries

Write a program called Groceries.java that computes the cost of groceries per week. Each person buys a different amount of groceries per week. You will ask a user to input

  1. how many times they bought groceries that week
  2. an estimate of how much each trip to the store costs

The program will then print out how much thaat person spends on groceries each week.

$ javac Groceries.java
$ java Groceries
How many times do you go to the grocery store each week? *2*
How much do you spend on each trip? *50.25*
This week you spent $100.50 on groceries.

Requirements:

2. Timer

Write a program, Timer.java that computes the time when the user will finish all of their tasks. The program should ask the user for the following information:

  1. The current time
  2. How many tasks they need to complete
  3. How long a task takes (we can assume that each task takes the same amount of time).

Here is an example

$ javac Tasks.java 
$ java Tasks
Enter the current hour: *23*
Enter the number of tasks: *1*
Enter the number of hours a task takes: *5*

You will finish at 4:00 o'clock.

$ javac Tasks.java 
$ java Tasks
Enter the current hour: *9*
Enter the number of tasks: *3*
Enter the number of hours a task takes: *2*

You will finish at 15:00 o'clock.

You can assume that all times are integers that represent the time on a 24-hr “military” clock. For example, 7 PM is 19:00, or 19, in this representation.

Requirements:

3. Taylor time!

Write a program, called Taylor.java, which will ask a prompt the user for the following information:

  1. a noun
  2. a drink
  3. a verb
  4. a noun
  5. a noun
  6. an adjective
  7. a gerund

and then prints out the following song:

$ javac Taylor.java
$ java Taylor
Please input a noun: *problem*
Please input a drink: *gatorade*
Please input an verb: *look*
Please input a noun: *moon*
Please input a noun: *sun*
Please input an adjective: *tiring*
Please input a gerund: *cheering*

It's me, hi, I'm the problem, it's me
At gatorade time, everybody agrees
I'll look directly at the moon but never in the sun
It must be tiring always cheering for the anti-hero

README.txt

In a text file called README.txt answer the following questions:

  1. How much time did you spend on the homework
  2. What did you learn from this homework
  3. optional: What did you struggle with during this homework
  4. optional: any other feedback you would like to share

Dont forget: make sure to fill in the header in all of your java files.

Submitting

Submit the following files to the assignment called HW01 on Gradescope:

  1. Taylor.java
  2. Timer.java
  3. Groceries.java
  4. README.txt

Make sure to name these files exactly what we specify here. Otherwise, our autograders might not work and we might have to take points off.