$34.99
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))
- 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 java program to ask for a prompt input given a letter from a to z. Display the entered letter’s ASCII number and whether it is a multiple of 2, 3, 5, and 7 or it is none of them.
Use both if/else statement and switch statement in one program to solve this problem.
Assume a perfect user will give a proper input. Here are a few sample outputs to illustrate the expected behavior of your program. Note: user input is highlighted in grey.
Please enter a letter from a to z: e The ASCII number of e is odd number 101.
It is none of 2, 3, 5, and 7.
Please enter a letter from a to z: x The ASCII number of x is even number 120.
It is multiple of 2.
It is multiple of 3.
It is multiple of 5.
Please enter a letter from a to z: a The ASCII number of a is odd number 97. It is none of 2, 3, 5, and 7.
Question 2
There is a promotion activity in the grocery store. Here are the details on the flyer:
• If you buy items under $250, you will receive 10% off in total and get double points.
• If you buy items between $250-500 (both included), you will receive 15% off in total and get double points.
• If you buy items over $500, you will receive 20% off in total and get triple points.
Notes*:
• All seafood is not included in the total discount price.
• Point calculation:
o The double points = 2*total price (seafood included) o triple points = 3*total price (seafood included).
o The point will be an integer which is rounded up. (Hint you can use Math.round())
Here is a list of items’ prices:
Item No. Item Name Price per item
1 Fruit $26.99
2 Cheese $22.99
3 Dairy $13.99
4 Meat $56.99
5 Seafood $38.99
Assume a perfect user will give correct inputs. Write a program that determines the total price and the points the customer will receive.
Here are a few sample outputs to illustrate the expected behavior of your program.
Note: user input is highlighted in grey.
---------------------------------------------------------
Grocery Shop Price Calculator
---------------------------------------------------------
Please enter the quantities for each item in the list? 1 2 0 1 1
Do you have a membership? (Y/N) Y
The total price is $155.954. You will receive 312 points.
Thanks for shopping! See you next time!
--------------------------------------------------------- Grocery Shop Price Calculator
---------------------------------------------------------
Please enter the quantities for each item in the list? 5 3 1 1 0 Do you have a membership? (Y/N) N
The total price is $219.92.
Thanks for shopping! See you next time!
--------------------------------------------------------- Grocery Shop Price Calculator
---------------------------------------------------------
Please enter the quantities for each item in the list? 0 0 0 0 0
Do you have a membership? (Y/N) Y
The total price is $0.0. You will receive 0 points.
Thanks for shopping! See you next time!
Question 3 (Mini Translator)
In this question, you are asked to write a simple java program to understand natural language.
The user will enter the input following the format:
Name came to City, Country in Year.
For example:
Robin came to Montreal, Canada in 2009.
Assume a perfect user will follow the exactly above formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format:
Name stay in City for X year(s). City is in Country.
For example
Robin stay in Montreal for 11 years. Montreal is in Canada.
Here is an example of the output to illustrate the expected behavior of your program. The grey highlights are your input to the program and the yellow highlights are the program output.
--------------------------------------------------------- Language Translator Program
--------------------------------------------------------- Please enter the input sentence (press q to exit):
Robin came to Montreal, Canada in 2009.
Robin stays in Montreal for 11 years. Montreal is in Canada.
Please enter the input sentence (press q to exit):
Lucy came to Berlin, Germany in 2000.
Lucy stay in Berlin for 20 years. Berlin is in Germany.
Please enter the numbers along operation (press q to exit):
q
Thanks for using translator program.
Submitting Assignment 2
- Zip the source code (the .java file only please) of this assignment.
- Naming convention for zip file: Create one zip file, containing the source files for your assignment using the following naming convention:
➢ The zip file should be called a#_studentID, where # is the number of the assignment and studentID is your student ID number.
For example, for the first assignment, student 123456 would submit a zip file named a1_123456.zip
- Submit your zip file on moodle or econcordia course webpage.
Evaluation Criteria for Assignment 1 (20 points)
Source Code
Comments for all 3 questions (3 pts.)
Description of variables and constants 1 pt.
Description of the algorithm 1 pt.
Programming Style for all 3 questions (3 pts.)
Use of significant names for identifiers 1 pt.
Indentation and readability 1 pt.
Welcome Banner/Closing message 1 pt.
Question 1 (4 pts.)
Prompting user/reading data 1 pt.
Proper use of if/else and switch statement 2 pt.
Display results 1 pt.
Question 2 (4 pts.)
Read in items 1 pts.
Determine the total price 1.5 pt.
Determine the points 1.5 pt.
Question 3 (6 pts.)
Analysing input string 2 pt.
Obtain the key words 2 pts.
Display results 2 pts.
TOTAL 20 pts.