Question: CPS 180 - Lab Assignment #2 Due: 05/24/17 Points: 40 Part I (20 Points): Purpose: The purpose of this exercise is to become familiar with
CPS 180 - Lab Assignment #2
Due: 05/24/17 Points: 40
Part I (20 Points):
Purpose: The purpose of this exercise is to become familiar with Java basic syntax, program structure, and problem solving. In addition, you should learn how to submit a program using the file submit capability of Blackboard.
Exercise: Write a Java program that calculates the cost of gas for a road trip. Your program will need to collect the following pieces of information from the user.
First name
Miles per gallon (mpg) of the car
Number of miles planned to drive
Current price per gallon of gas
After collecting the users information and the performing the calculations your program should display the results in a format similar to:
Sample Run (users inputs are shown in bold):
Please enter your First Name: Ralph
Please enter the MPG of your car: 20
Please enter the miles to be traveled: 160
What is the price per gallon of gas: 2.00
Hello, Ralph! Thank you for providing your information!
Car MPG: 20
Miles to Drive: 160
Price per gallon of gas: $2.00
Your trip will cost: $16.00
Program File Suggestions:
Call your application CalculateTrip.java
Call your output file HW3output.txt
Part II (20 Points):
Purpose: To become familiar with Java language basics (variable declaration, numeric expression, assignment statement, input using Scanner, and formatting output).
Problem Description: Write a program to accept inputs from a user including yourName, numberShares shares (only whole shares allowed) purchased of some stock (for example the Microsoft stock symbol is MSFT) at the price of buyPrice per share and paid the stockbroker $15 buyTransactionFee. Two weeks later, the person sold the numberShares shares at sellPrice per share and paid another $10 for the sellTransactionFee.
Create the necessary input, process and output variables, choosing appropriate data types, and write a Java program to accept input, calculate and display the following:
dollar amount paid for the shares
dollar amount of the shares sold
total transaction fee paid to the broker (including both buy and sell) Use constants/final
amount of profit (or loss) made after selling the shares.
Input: yourName, numberShares, buyPrice, sellPrice
Sample Run (users inputs are shown in bold):
Whats your name? Joseph
What stock are you purchasing? MSFT
How many shares bought? 250
Buy price? 28.31
Sale price? 30.79
Using Java to get the Inputs above, Calculate and generate the following formatted Output:
Statement of MSFT Transactions for Joseph
Number of shares purchased: 250
Amount of purchase: $7077.50
Amount of sale: $7697.50
Transaction fees paid: $25.00
Net profit: $595.00
Submit four files zipped up to Blackboard:
Your programs source (Called CalculateTrip.java) on Blackboard. Do not submit the .class file or other project files. Programs must be submitted with a working java program (i.e. debugged without syntax errors, and compile-able).
Your source program that is a file with .java extension, e.g. StockTransaction.java.
The files containing the output produced by your programs. Provide at least 3 sample runs. Save the output to a Word document or text file.
e.g. Lab2Part1-Output.txt and Lab2Part1-Output.txt
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
