Starting from:

$25

COMP248- Project 2 Solved

Purpose: 
 
The purpose of this assignment is to help you learn Java identifiers, assignments, input/output, selection and flow of control statements: if, if/else, switch. 
CEAB/CIPS Attributes:            Design/Problem analysis/Communication Skills



 

General Guidelines When Writing Programs: 

-       Include the following comments at the top of your source codes

// -------------------------------------------------------

// Assignment (include number)

// Written by: (include your name(s) and student id(s))

// For COMP 248 Section (your section) – Fall 2017 // --------------------------------------------------------

-       In a comment, give a general explanation of what your program does. As the programming questions get more complex, the explanations will get lengthier.

-       Include comments in your program describing the main steps in your program. Focus in your comments rather on the why than the how.

-       Display a welcome message.

-       Display clear prompts for users when you are expecting the user to enter data from the keyboard.

-       All output should be displayed with clear messages and in an easy to read format.

-       End your program with a closing message so that the user knows that the program has terminated.

Question 1
Write a program that given a number from 1 to 7 outputs what day of the week it corresponds to (1 = Monday, 7 = Sunday) and whether it is a weekday or weekend. You may assume an integer as input but if the input is not from 1 to 7, you should output that it’s not a valid day.  Write two versions of this program:

Version 1: Use an if/else statement

Version 2: Use a Switch statement (instead of an if/else)

 

Here are a few sample outputs to illustrate the expected behavior of your program. Note: user input is highlighted in grey.

Please enter the day of the week as a number (1-7): 7 It's Sunday! It's the weekend!
Please enter the day of the week as a number (1-7): 5 It's Friday! It's a weekday!
Please enter the day of the week as a number (1-7): 9 That's not a valid day!
Question 2
Write a program that determines the penalty for a driver who is speeding on highway 401. The program should ask the user how fast the driver was going. 

If the driver is driving

•       less than 10km over the speed limit (100km), the fine is $65.

•       10-19km over the speed limit, the fine is $120 and the driver gets 2 demerit points.

•       20-39km over the speed limit, the fine is $240 and 5 demerit points. 

•       40-59km the fine is $360 and the driver gets 7 demerit points.

•       160km or over, the driver loses his license on the spot and is given a fine of $520. 

 

After determining that the driver was speeding and if they have not yet lost their license, ask the user how many demerit points the driver originally had. When a driver has 12 demerit points they lose their license. Determine if the driver should lose their license given how fast they were driving. Output how many demerit points the driver has after the current infraction.  

 

Here are a few sample outputs to illustrate the expected behavior of your program. Note: user input is highlighted in grey.

---------------------------------------------------------

            SpeedyFines Calculator

---------------------------------------------------------

 

How fast was the driver going? 90 The driver was not speeding.
 
---------------------------------------------------------             SpeedyFines Calculator

--------------------------------------------------------- 

How fast was the driver going? 113

The fine is $120 and the driver gets 2 demerit points!

How many demerit points did the driver have prior to being stopped? 8

The driver now has 10 demerit points.

 
---------------------------------------------------------             SpeedyFines Calculator

--------------------------------------------------------- 

How fast was the driver going? 137

The fine is $240 and the driver gets 5 demerit points!

How many demerit points did the driver have prior to being stopped? 0

The driver now has 5 demerit points.

 
 
 
 
 
---------------------------------------------------------             SpeedyFines Calculator

---------------------------------------------------------

How fast was the driver going? 165

The fine is $520 and the driver loses his license. 
---------------------------------------------------------             SpeedyFines Calculator

--------------------------------------------------------- 

How fast was the driver going? 147

The fine is $360 and the driver gets 7 demerit points!

How many demerit points did the driver have prior to being stopped? 6

The driver has 13 demerit points and loses his license.
Question 3
FoodieDelivery is a food delivery service that delivers meals from a number of restaurants around Montreal. They’ve decided to come up with a subscription program with the following details: 

 

•       The “PayPerDelivery” subscription allows you to pay per use, each delivery costs $3.00. 

•       The “OccassionalFoodie” subscription costs $15/month and allows you to order food 6 times a month with each additional delivery costing $2. 

•       The “MontrealFoodie” subscription costs $30/month and allows you to order food 3 times a week (12 times a month) with each additional delivery costing $1.50. 

 

Write a program that helps a customer decide which subscription is best for them based on the number of food orders they make per month. The program should ask the user to enter the number of times they typically order food in a month. Calculate the cost of each subscription type and determine the best financial option for the user based on his input and price of the subscription plus extra deliveries. In each of the cases, compute the savings from the other subscriptions. Note, if the value of the next subscription is equal to that of the lower subscription, recommend the higher subscription (e.g. for 5 deliveries both PayPerDelivery and OccassionalFoodie the cost is $15.00 and you should recommend the OccassionalFoodie (see output 2)). 

*You can leave more than 2 decimal places for the prices and you should not compute taxes.

 

Here are a few sample outputs to illustrate the expected behavior of your program. Note: user input is highlighted in grey.

---------------------------------------------------------             FoodieDelivery Subscription Calculator

--------------------------------------------------------- 

Please enter the number of times a month you use food delivery services: 3 

The cost of Pay per delivery would be: $9.00/month 

 

**We recommend getting the Pay per delivery.**

 

Thank you for using FoodieDelivery Subscription Calculator. Good Eats :-)!
 

---------------------------------------------------------             FoodieDelivery Subscription Calculator

--------------------------------------------------------- 

Please enter the number of times a month you use food delivery services: 5 

The cost of pay per delivery would be: $15.00/month 

Based on your food deliveries, the cost of the OccasionalFoodie subscription would be:

$15.00/month

 

You would save $ 0.00 from PayPerDelivery and $ 15.00 from MontrealFoodie.

**We recommend getting the OccasionalFoodie subscription.** 

Thank you for using FoodieDelivery Subscription Calculator. Good Eats :-)!
 
 
---------------------------------------------------------             FoodieDelivery Subscription Calculator

--------------------------------------------------------- 

Please enter the number of times a month you use food delivery services: 13 

The cost of pay per delivery would be: $39.00/month 

Based on your food deliveries, the cost of the OccasionalFoodie subscription would be:

$29.00/month

 

**We recommend getting the OccasionalFoodie subscription.** You would save $ 10.00 from PayPerDelivery.

 

Thank you for using FoodieDelivery Subscription Calculator. Good Eats :-)!
 
---------------------------------------------------------             FoodieDelivery Subscription Calculator

--------------------------------------------------------- 

Please enter the number of times a month you use food delivery services: 20 

The cost of pay per delivery would be: $60.00/month 

The cost of pay OccassionalFoodie would be: $43.00/month 

Based on your food ordering, the cost of the MontrealFoodie subscription would be:

$42.00/month

 

You would save $1.00 from the OccasionalFoodie subscription and $17.00 from PayPerDelivery.

**We recommend getting the MontrealFoodie subscription.** 

Thank you for using FoodieDelivery Subscription Calculator. Good Eats :-)! 

More products