Starting from:

$30

Project: Using Java API Classes

Project: Using Java API Classes Page 1 of 5
Page 1 of 5
Deliverables
Your project files should be submitted to Web-CAT by the due date and time specified. In order to
avoid a late penalty for the project, you must submit your completed code files to Web-CAT by 11:59
p.m. on the due date. If you are unable to submit via Web-CAT, you should e-mail your project Java
files in a zip file to your TA before the deadline.
Files to submit to Web-CAT:
• Solver.java
• Event.java
Specifications
Overview: You will write two programs this week. The first will solve for the result of a specified
expression, and the second will read data for an event and then interpret and print the formatted event
information.
• Solver.java
Requirements: Solve for the result of the expression in the formula below for a value x of type
double which is read in from the keyboard, and save the result in a variable of the type double.
You must use the pow(), sqrt(), and abs()methods of the Math class to perform the
calculation. You may use a single assignment statement with a single expression, or you may
break the expression into appropriate multiple assignment statements. The latter may easier to
debug if you are not getting the correct result.
������ = )|���� + ��� + ��� + �� + �|
(�� + �)
Next, determine the number of characters (mostly digits) to the left and to the right of the decimal
point in the unformatted result. [Hint: You should consider converting the type double result into
a String using the static method Double.toString(result) and storing it into a String
variable. Then, on this String variable invoke the indexOf(".") method from the String class
to find the position of the period (i.e., decimal point) and the length() method to find the
length of the String. Knowing the location of the decimal point and the length, you should be
able to determine the number of digits on each side of the decimal point.]
Finally, the result should be printed using the class java.text.DecimalFormat so that to the right of
the decimal there are at most four digits and to the left of the decimal each group of three digits is
separated by a comma in the traditional way. Also, there should also be at least one digit on each
side of the decimal (e.g., 0 should be printed as 0.0). Hint: Use the pattern "#,##0.0####"
when you create your DecimalFormat object. However, make sure you know what this pattern
means and how to modify and use it in the future.
Project: Using Java API Classes Page 2 of 5
Page 2 of 5
Design: Several examples of input/output for the Solver program are shown below.
Line # Program output
1
2
3
4
5
Enter a value for x: 0
Result: 0.5
# of characters to left of decimal point: 1
# of characters to right of decimal point: 1
Formatted Result: 0.5
Line # Program output
1
2
3
4
5
Enter a value for x: 1.0
Result: 1.0
# of characters to left of decimal point: 1
# of characters to right of decimal point: 1
Formatted Result: 1.0
Line # Program output
1
2
3
4
5
Enter a value for x: -123.456
Result: -207.41347000884227
# of characters to left of decimal point: 4
# of characters to right of decimal point: 14
Formatted Result: -207.41347
Line # Program output
1
2
3
4
5
Enter a value for x: 123456789.0
Result: 2.047299208293137E8
# of characters to left of decimal point: 1
# of characters to right of decimal point: 17
Formatted Result: 204,729,920.82931
When the characters to the right of the decimal in the unformatted result end with E followed
by one or more digits (e.g., E11 indicates an exponent of 11), the ‘E’ should be included in
the count of the characters to the right of the decimal point.
Code: In order to receive full credit for this assignment, you must use the appropriate Java API
classes and method to do the calculation and formatting. It is recommended as a practice that you
do not modify the input value once it is stored.
Test: You will be responsible for testing your program, and it is important to not rely only on the
examples above. Assume that the amount entered can be any positive or negative floating-point
number. 
Project: Using Java API Classes Page 3 of 5
Page 3 of 5
• Event.java
Requirements: The purpose of this program is to accept coded event information as input that
includes the date, time, price, discount, section, row, seat, followed by the description of the
event. Note that the five digits for price and two digits for discount have an implied decimal
point. The program should then print the event information including the actual cost, which is the
price with discount applied. The last line of the event information should contain a random "prize
number" between 1 and 9999 inclusive that should always be printed as seven digits (e.g., 1
should be printed as 0001). The coded input is formatted as follows:
 0214202019301250015011012The Lion King
date seat description
 row (goes through last character on line)
 section
 time
 discount [15 has an implied decimal point for 0.15 (or 15%)]
 price [12500 has an implied decimal point before the last two digits
 for 125.00]
Whitespace before or after the coded information should be disregarded (e.g., if the user enters
spaces or tabs before or after the coded information, these should be disregarded). Your program
will need to print the event description, date, time, section, row, seat number, price, discount, and
cost, and a random prize number in the range 1 to 9999 as shown in the examples below. If the
user enters a code that does not have at least 26 characters, then an error message should be
printed. [The 26th character of the code is part of the event description.]
Design: Several examples of input/output for the program are shown below.
Line # Program output
1
2
3
4
Enter your event code: War Eagle
Invalid Event Code.
Event code must have at least 26 characters.
Note that the event code entered below results in the indicated output except for the prize number
which is random. When more than one item is shown on the same line (e.g., event, date, and time
on line 3), there are three spaces between them (do not use the tab escape sequence \t).
Line # Program output
1
2
3
4
5
6
Enter your event code: 0214202019301250015011012The Lion King
Event: The Lion King Date: 02/14/2020 Time: 19:30
Section: 01 Row: 10 Seat: 12
Price: $125.00 Discount: 15% Cost: $106.25
Prize Number: 3629
Project: Using Java API Classes Page 4 of 5
Page 4 of 5
Note that the event code entered below includes a 50% discount.
Line # Program output
1
2
3
4
5
6
Enter your event code: 0214202019301250050011012The Lion King
Event: The Lion King Date: 02/14/2020 Time: 19:30
Section: 01 Row: 10 Seat: 12
Price: $125.00 Discount: 50% Cost: $62.50
Prize Number: 2534
Note that the event code below has 10 leading spaces (be sure you are trimming the input code).
It also includes a 75% discount.
Line # Program output
1
2
3
4
5
6
Enter your event code: 0214202019301250075011012The Lion King
Event: The Lion King Date: 02/14/2020 Time: 19:30
Section: 01 Row: 10 Seat: 12
Price: $125.00 Discount: 75% Cost: $31.25
Prize Number: 8494
Code: In order to receive full credit for this assignment, you must use the appropriate Java API
classes and methods to trim the input string, to extract the substrings, conversion of substrings of
digits to numeric values as appropriate, and formatting. These include the String methods trim,
and substring, as well as wrapper class methods such Double.parseDouble which can be used to
convert a String of digits into a numeric value for price and discount. The dollar amounts should
be formatted so that both small and large amounts are displayed properly, and the prize number
should be formatted so that seven digits are displayed including leading zeroes, if needed, as
shown in the examples above. It is recommended as a practice that you not modify input values
once they are stored.
Test: You are responsible for testing your program, and it is important to not rely only on the
examples above. Remember, when entering standard input in the Run I/O window, you can use
the up-arrow on the keyboard to get the previous values you have entered. This will avoid having
to retype the event code each time you run your program.
Grading
Web-CAT Submission: You must submit both “completed” programs to Web-CAT at the same time.
Prior to submitting, be sure that your programs are working correctly and that they have passed
Checkstyle. If you do not submit both programs at once, Web-CAT will not be able to compile and
run its test files with your programs which means the submission will receive zero points for
correctness. I recommend that you create a jGRASP project and add the two files. Then you will be able
to submit the project to Web-CAT from jGRASP. Activity 1 (pages 5 and 6) describes how to create a
jGRASP project containing both of your files.
Project: Using Java API Classes Page 5 of 5
Page 5 of 5
Hints
Event.java
1. The event code should be read in all at once using the Scanner’s nextLine method and stored
in a variable of type String. Then the individual values should be extracted using the
substring method. The String value for price and discount should be converted to type double
(using Double.parseDouble) so that it can be used to calculate cost. When printing the values
for price, discount, cost, and prize number, they should be formatted properly by creating an
appropriate DecimalFormat object (see patterns below) and calling its format method.
To format price and cost, use the pattern "$#,##0.00" when you create your
DecimalFormat object.
To format discount, use the pattern "0%" when you create your DecimalFormat object.
For prize number, use the pattern "0000" when you create your DecimalFormat object.
2. Since all items in the event code other than the price and discount will not be used in
arithmetic expressions, they can and should be left as type String.
3. The time and date should have leading zeros as appropriate. Therefore, these can be printed
as String values by concatenating their components with ":" and "/" as needed.
Grading
Web-CAT Submission: You must submit both “completed” programs to Web-CAT at the same time.
Prior to submitting, be sure that your programs are working correctly and that they have passed
Checkstyle. If you do not submit both programs at once, Web-CAT will not be able to compile and
run its test files with your programs which means the submission will receive zero points for
correctness. I recommend that you create a jGRASP project and add the two files. Then you will be able
to submit the project to Web-CAT from jGRASP. Activity 1 (pages 5 and 6) describes how to create a
jGRASP project containing both of your files.

More products