Assignment 2
Basic Java – 40 course points
Students will take arguments from the command line and will make simple conditional calculations and print the result.
General Guidelines
Write 3 programs and submit on Autolab.
- We provide a zip file (find it under Assignment2 on Autolab) containing
Welcome.java
,Multiples.java
andAmusementPark.java
. - For each problem UPDATE and SUBMIT the corresponding file only writing where it indicates.
Observe the following rules:
- DO NOT add any import statements
- DO NOT add the project statement
- DO NOT change the class name
- DO NOT change the headers of ANY of the given functions
- DO NOT add any new class fields
- DO NOT use
System.exit()
- ONLY print the result as specified by each problem. Observe the examples’ output, display only what the problem is asking for.
- DO NOT print other messages, follow the examples for each problem.
- ONLY print the result as specified by each problem. Observe the examples’ output and display only what the problem is asking for.
- DO NOT print other messages; follow the examples for each problem.
1. Welcome (10 points)
This assignment will teach students basic print statements.
Task
- UPDATE and SUBMIT
Welcome.java
in AutoLab.
Programming
Write a program in Welcome.java
that displays the phrase : Welcome to CS111.
Note: the autograder is case sensitive.
Executing and Debugging
-
First navigate to the src directory/folder
-
- to compile:
javac Welcome.java
- to execute:
java Welcome
- Output should be:
Welcome to CS111.
- to compile:
-
2. Multiples (15 points)
This assignment will teach students how to do basic computations using arguments from the command line as input.
Task
- UPDATE and SUBMIT
Multiples.java
in AutoLab.
Programming
You will write an algorithm without conditionals that takes in 2 integer numbers (num1 and num2) and displays:
- true if:
- the first number is 0
OR - the second number is 0
OR - the first number, num1, is a multiple of the second number, num2
- Hint: num1 is a multiple of num2 if num1 = num2 * y where y is any integer value
- the first number is 0
- false otherwise
Pre-condition: Inputs are positive, integer numbers, and there will always be exactly two input numbers.
Hint: use boolean variables instead of conditionals. The order of the tests matter. The modulus operator performs a division and as you know dividing by zero causes an error.
Example:
Inputs | Expected Output |
[5, 6] | false |
[8, 4] | true |
[8, 0] | true |
Executing and Debugging
First navigate to the src directory/folder
- to compile:
javac Multiples.java
- to execute:
java Multiples 5 6
- Output should be:
false
- to compile:
Created by: Apoorva Goel
3. Amusement Park (15 points)
This assignment will teach students how to do make conditional computations using arguments from the command line.
Task
- UPDATE and SUBMIT
AmusementPark.java
in AutoLab.
Programming
Write an algorithm that reads:
- familySize: number of family members,
- numUnderFive: number of children under the age of 5 in the family,
- numSeniors: number of seniors (65+) in the family, and
- isWeekend: a boolean that is true if it is the weekend or false otherwise
The algorithm is expected to calculate and display the total cost for this family to visit an amusement park. Admission to the park is charged as follows:
- Free for children 5 years old and younger
- $20 per person for adults 65 years old and above
- $35 per person for everyone else
- The park offers a family discount rate of 10% on the total admission fee for any family of 5 or more members
- On weekends there is a parking fee of $25, but parking is free on weekdays. Assume the value entered for this input is either true (it’s a weekend) or false (it’s not a weekend).
(the parking fee is not included in the discount)
Pre-Conditions:
- The inputs (number of family members, number of children under the 5 years old, and number of seniors) are positive integer numbers.
- The input isWeekend is a boolean.
Executing and Debugging
First navigate to the src directory/folder
- to compile:
javac AmusementPark.java
- to execute:
java AmusementPark 5 3 6 true
- Output should be:
error
- to compile:
Created by: Apoorva Goel
Submitting Guidelines
VSCode Extensions
You can install the VSCode extension pack for Java. Take a look at this tutorial.
We suggest:
Importing VSCode Project
- Download Assignment2.zip from Autolab Attachments.
- Unzip the file into a unique folder named Assignment2.
- Open VSCode
- Import the folder to a workspace through File > Open Folder
Before submission
Collaboration policy. Read our collaboration policy here.
Submitting the assignment. Submit Welcome.java
, Multiples.java
and AmusementPark.java
separately via Autolab. To do this, click the Assignments link from the course website; click the Submit link for that assignment.
Getting help
If anything is unclear, don’t hesitate to drop by office hours or post a question on Piazza.
- Find instructors office hours here
- Find tutors office hours in Canvas -> Tutoring, RU CATS
- Find head TAs office hours here
- POST on Piazza in Canvas -> Piazza
- In addition to office hours we have the CSL (Coding and Social Lounge), a community space staffed with lab assistants which are undergraduate students further along the CS major to answer questions.
- Refer to our Programming Assignments FAQ for instructions regarding our assignments and policies.
Submitting
Write 3 programs and submit on Autolab.
- We provide a zip file (find it under Assignment2 on Autolab) containing
Welcome.java
,Multiples.java
andAmusementPark.java.
- For each problem UPDATE and SUBMIT the corresponding file.