CSE 110 – Assignment #1

$30.00

Category:

Description

5/5 - (3 votes)

Part 1: Program#1 Compile and Run: (5 pts)
Type the following code into a file called TotalAndAverage.java. DO NOT submit this file.
After the program is entered, compile and run the application to make sure it works. Once you see it
working correctly, answer questions a)-e) below. (The comment block shown here is a good
example to base yours off of for Part 2, Program #2, namely Assignment1.java).
//***********************************************************
// Name: Your name here
// Title: TotalAndAverage.java
// Description: Calculate the total and average scores.
// Date: mm/dd/yyyy
//***********************************************************
© 2018 Yoshihiro Kobayashi
There are numerous opportunities for errors in any program, many times in places that seem too
simple to require close attention.
Questions: Introduce the following errors, one at a time, in the program TotalAndAverage.java.
Explain any error messages that the compiler produces in your own words. Don’t copy and paste
the error message. Fix the previous error each time before you introduce a new one. If no error
messages are produced, try to run the code and explain what happens. If still no errors are produced,
explain whether the output is valid or not and why.
a. Change TotalAndAverage to totalAndAverage.
b. Remove the first quotation mark in the first string literal in the first println( )statement.
c. Add three more semicolons (;) at the end of the first println( ) statement.
d. Remove the last brace in the program.
e. Change the string in the System.out.println( ) from the “Total Score is: to “\”Total Score is:
Note: The answers to the 5 questions (a through e) above should be typed in the block of
comments in the Assignemnt1.java file such as;
/*
a) It was not compiled successfully because …
b) It does not generate any compile error, but…

*/
© 2018 Yoshihiro Kobayashi
Part#2: Programming (15 pts)
Part#1 is a big hint for this main programming assignment. Write a Java program called
Assignment1.java.
Suppose…
John has $56.25.
Mary has $80.78.
Chris has $22.53.
Yoshi has $ 5.16.
The goal is to display the financial information of four people above. It is asked to calculate the
total and average amount and display them with a specific format.
Format:
First, look at the “Example Output” section blow. The first line shows the title, “Financial
Information” with double- quotations (“) (First line, 3 pts). The second line shows the column
names; NAME, Dollars, and Cents (Second line, 3 pts). From the third line, display the name,
amount of dollars and cents for each people (Third line, 3 pts). Use the “—-” as the separators.
Use the println and/or print methods with “\t” in order to set the alignments for each
column. (Alignment, 3 pts).
*) A backslash (\) is used as an escape character in string literals. It causes an “escape”
from the normal way characters are interpreted by the complier. For example, a
character set of backslash and double-quotation( \”) in string literals is recognized as a
double-quotation ” by the compiler. The backslash and letter-t (\t) and the backslash
and letter-n (\n) are used to make an indent and change the line.
Declare double-type variables and initialize the values as the money amount of each people
such as
double john_amount = 56.25;
The amount of dollars and cents must be calculated in your code.
• Using direct declaration for the dollar and cent such as int john_dollar = 56;
int john_cent = 25: is NOT accepted. You are asked to find the way to
extract two integer values, 56 and 25 from the original value 56.25.
• Using direct sting data input such as System.out.println(“John 56 25″)is
NOT accepted. ”
After the information, display the total and average (Last lines, 3 pts).
*)The example shows “???” instead of the results, but your program should display the
correct data. The amount of cents MUST NOT be exceed 99. For example, “32 dollars
© 2018 Yoshihiro Kobayashi
and 125 cents” does not make any sense (should be “33 dollars and 25 cents” instead).
Use the algorithm in the Part#1 (casting) or the division and modular operations as
explained in the textbook Ch2.2.3.
*) Once it is done, double check if your output of total and average (they are hidden
with “???” or “??” below) are same as those in calculator by yourself.
*) Don’t ask us (instructor and tutors), “Is my code 100% correct?” or “Can I get a full
score?” It is your responsibility to check your code and result by yourself. If you have a
question or problem, ask each question one by one.
Example Output:
The following is an example output.
“Financial Information”
NAME Dollars Cents
—- —- —-
John 56 25
Mary 80 78
Chris 22 53
Yoshi 5 16
————————–
Total ??? ??
Average ?? ??
/**********************************************************************************
Submit your homework by following the instructions below:
**********************************************************************************/
• Go to the course web site (my.asu.edu), and then click on the on-line Submission tab. Log in the
site using the account, which was registered at the first Lab session. Make sure you use the correct
email address for registration. This will allow you to submit assignments. Use your ASU e-mail
address.
• Submit your Assignment1.java file (not Assignment1.class file) on-line. Make sure to choose
Hw1 from drop-down box.
• Assignment1.java should have the following, in order:
• In comments, the assignment Header described in “Important Note” and demonstrated in
Program #1 including the Name, Title, Description, and Date.
• In comments, the answers to questions a-e presented in Program #1. DO NOT include the
code given in Part#1, TotalAndAverage.java.
© 2018 Yoshihiro Kobayashi
• The working Java code requested in Program #2.
• The Assignment1.java file must compile and run as you submit it. You can confirm this by
viewing your submission results.
Important Note: You may resubmit as many times as you like until the deadline, but we will only
mark your last submission. NO LATE ASSIGNMENTS WILL BE ACCEPTED.