Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description This lab is based on the material studied in week 2 and 3, including the exercises done in class. This assignment is to be

Description
This lab is based on the material studied in week 2 and 3, including the exercises done in class.
This assignment is to be done individually; you are not allowed to work on this assignment with anyone.
See also the Academic Integrity Policy and the Assignment and Exam Policies
Question 1
You are to write a program that allows the user to calculate the cost of a set of items in inventory. The user will
enter the item name, the cost of the item, and the quantity of the item on hand. After entering these values, the
user will then be able to see a summary of the total value of that item.
Sample program interaction (prompts in black, user input in blue) with output at the end in green. These colours
are here for demonstration only; your program does not need to display in colour):
Enter product name: McDonalds Happy Meal
Enter product cost: 19.95
Enter quantity on hand: 3
Total value of Happy Meal: $59.85
The final total displayed in the output must be formatted with a dollar sign and exactly two digits after
the decimal.
Your program must use variables of the appropriate type.
All input and output must be done on the console (e.g. using Scanner for input and
println()/printf()/print() for output.
Question 2
A Mad-Lib is a game where the user is prompted to enter various values, and those values are used to make up a
story or poem. You can view a web-based example here (this was written with HTML and PHP).
Make up your own Mad-Lib in Java. Prompt the user for the values you want them to enter (your Mad-Lib must
have a minimum of 4 user-entered values) using console input (i.e. Scanner class). These inputs should be stored
in variables. Display the final Mad-Lib on the console.
Sample program interaction (prompts in black, user input in blue) with output at the end in green:
Enter each of the following things:
An animal: cat A colour: purple
Something purple: a bruised toe
A verb (imperative): code
Your Mad-Lib:
----------- Mary had a little cat;
It's fleece as purple as a bruised toe,
And everywhere that Mary went, The cat was sure to code.
Question 3
You are to write a program that calculates the slope and midpoint of a line PQ, the coordinates of which will be
input by the user.
A point consists of an x-value and a y-value, and you have two points, so you'll need to prompt the user to enter
the x-value and y-value for point P and the x-value and y-value for point Q. You'll need to store these input
values inside variables that are declared with appropriate identifiers and data types. Your prompts to the user
should be clear, concise, and use proper spelling/grammar.
Once the user enters coordinates for the two points, it will then calculate the slope of the line connected by PQ,
and the mid point of the line connected by PQ.
Your program should display the two points P and Q before it displays the slope and the mid-point.
Below is an example that shows the format of your program's interaction with the user and its output (black text
is used for the prompts created by the program; blue text is used for the user's inputs; green text is the program's
actual outputs.
Recording Point P: Enter X-Value: 2.0
Enter Y-Value: 1.0
Recording Point Q:
Enter X-Value: 5.5 Enter Y-Value: 7.5
A Line connected by P(2.0, 1.0) and Q(5.5, 7.5)
- Has a slope of 1.86 - Has a mid-point of (3.8, 4.3)
Your output and must appear exactly as shown above:
The points P and Q must be displayed exactly as above, including spacing.
The coordinates of the points P and Q must be formatted to one decimal place.
The slope of the line PQ must be displayed exactly as above, including String literals and spacing.
The slope of line PQ must be formatted to two decimal places.
The mid-point of the line PQ must be displayed exactly as above, including String literals and spacing.
The coordinates of the mid-point of line PQ must be formatted to one decimal place.
Note that this is a console program (no dialogs/GUI).
Your program must use variables of the appropriate type and with self-documenting names.
You must include appropriate documentation in your code.
Useful Formulae
The slope of the line is calculated for a line AB with two points A(x1, y1) and B(x2, y2) as:
2 1
2 1
The mid-point of a line AB with two points A(x1, y1) and B(x2, y2) is:
1 + 2
2 ,
1 + 2
2
Submission
All submissions are expected to abide by the Submission Standards and all code is expected to abide by the
Coding Standards for this Course. Before the deadline specified on Slate.
You are to submit 3 files for each questions:
Your Java source code for your program.
A text or word processed document containing all of your source code.
Screenshot a screenshot of your code & console display (.jpg file)
1. Source Code File:
Submit only the source code file (.java) for your program. DO NOT submit anything else or you will
lose marks. DO NOT submit .class files, DO NOT submit your editor's backup files (e.g. .java~
or .bak), etc.
DO NOT compress your files by using ZIP or RAR
The name of your file should be YourfirstnameYourlastnameAssignment#Q#.java, For example,
JohnSmithAssignment1Q1.java.
2. Document of Source:
You must also copy and paste all of your source code into a plain text file (e.g. .TXT), or Word document
(e.g. .DOC/.DOCX). Submit this document in addition to your source code java file. This is used for SLATE's
originality checker.
Submit your assignment to where you download this instruction in SLATE, that is
Slate/Assessment/Assignment/Assignment 1, click [add a file].
IMPORTANT: Failure to follow any of the instructions above will result in penalties or a grade of 0.
Evaluation
Your submission will be evaluated based on the following criteria:
Efficient Code: Program uses variables where and only when necessary; program doesn't define
variables that are never used, nor does it use too many variables for unnecessary tasks; program logic is
written concisely and is not cluttered with unnecessary tasks.
Functionality: program functions according to specifications - input and output is done on the console
using the techniques discussed in class; variables are used to store user inputs until they are needed for
output.
Programming Style: proper indentation and spacing, use of comments/documentation; all identifiers are
descriptive and valid; varibles are defined with appropriate types and converted when required.
Other: all instructions regarding submissions and program specifications have been followed;
submission was completed and submitted as requested in a timely fashion; techniques discussed in class
have been use

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions