Description
Question 1. (question1.java) Write a Java application that declares the following variables:
A String to hold your name
An integer to hold your expected year of graduation.
A double to hold your wishful starting salary for your first post-Laurentian job.
Do not collect any input from the user, hard code all of the values above using literals. Your program
displays the information as follows:
C:\Desktop\cosc1046\a1> java question1
My name is Aaron Langille.
I expect to graduate in 2016.
I hope to make $100453.0 per year when I do.
***Note: C:\Desktop\cosc1046\a1> java question1 is not part of the output. It shows
what command I am running to get the output to display. This will appear in many questions
throughout the term.
Question 2. (question2.java) They say “A dollar doesn’t go as far as it
used to…” but they rarely mention that it depends on where you take that
dollar. Beside is a table of made-up conversion rates. Write a program that
uses variables and literals to print out the value of a converted amount of
money for various countries. Use the last three digits of your student
number as the value to convert. For example, my student number ends with
964 so the output of my program would be:
C:\Desktop\cosc1046\a1> java question2
$964.00 CAD buys:
USD:732.64
JPY:91011.23999999999
CNY:4559.72
INR:46763.64
EUR:694.0799999999999
The output above is pretty messy, especially considering it’s showing money to too many digits. If
you are done with time to spare, see if you can format your output as follows. Hint: Look up printf()
in chapter 3:
C:\Desktop\cosc1046\a1> java question2
$964.00 CAD buys:
USD: 732.64
JPY: 91011.23
CNY: 4559.72
INR: 46763.64
EUR: 694.07
$1 Canadian (CAD) Buys:
0.76 US Dollars (USD)
94.41 Japanese Yen (JPY)
4.73 Chinese Yuan (CNY)
48.51 Indian Rupees (INR)
0.72 Euros (EUR)
Question 3. Create a single Java application that evaluates the following mathematical expressions.
Use literals in your expressions and use variables to store the result. Then print the values stored in
those variables. Practice using comments to clearly mark each part of the question.
a) The product (multiplication) of the first 10 positive integers. Store your result as an int
value. Do not use doubles or floats in your solution.
b) The product (multiplication) of the first 17 positive integers. Store your result as an int
value. Do not use doubles or floats in your solution.
c) 𝑧 ൌ 5𝑥ଶ 𝑦ଶሺ ଵ
ଵା௫మሻ
భ
మ , for x = 7.5 and y = -9
d) 𝑤ൌቀଵ
ቁ ∗ 𝑎 where a = 0.000000001 (take note of your result here).
Sample output from my solution is shown below. Note that I have hidden the output from
two parts so as not to give away the surprises. Your solution should show the proper result.
C:\Desktop\cosc1046\a1> java question3
a)3628800
b) (Hidden)
c)291.95526132737245
d) (Hidden)