辅导案例-CIS 180

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
CIS 180 Homework 3
Concepts that will be used:
- Loops
- Arrays
Astro Numerals(125 pts total)
Overall Picture:
When dealing with money balances, floating-point numbers are never used, precisely because they are
not accurate 100% of the time. How can they be when you’re trying to map an infinite number of
numbers to a finite space (32 bits for float, 64 bits for double)? The solution is to use integer data types
as they are always 100% accurate*.
*100% accurate for the range it can handle. Byte can handle ranges from -128 to 127. Short from
-32767 to 32767. Long being the largest range, it can handle between ~ -9 quintillion to +9 quintillion.
But what about values beyond that? It could happen, one day…
The good news is, the Java SDK provides us with a class called BigDecimal that scales the amount of
memory needed to handle the integer values we throw at it (regardless of the size). The bad news is,
I’m telling you flat out, you cannot use it for the assignment. Instead you’re going to finished up my
class called AstroNumeral.
AstroNumeral will use a single dimension array of integers, with a length of 22. The idea here is we can
handle integer, specifically whole dollar amounts, up to 999 vigintillion
(https://en.wikipedia.org/wiki/Names_of_large_numbers). Every index in the array will represent 3
digits of the number. For example, consider the value 123,456,789. The array will hold the following
values:
numeral[0] = 789
numeral [1] = 456
numeral [2] = 123
numeral [3] = 0

numeral [22] = 0
As you can see from the class diagram below, there are two classes. The TestAstro class contains the
main method. The AstroNumeral class contains 2 constructors, 3 public methods, and 2 private
methods. The code will run as is, and you will see that it fails every test. You need to implement some of
the methods in order for those methods to pass the test. You are NOT allowed to change code I have
already provided for you.


1. Constructor AstroNumeral ()
This method is finished, merely comment it (2 points)
2. Constructor AstroNumeral (String s)
This method is finished, merely comment it (2 points)
3. Method resetToZero()
This method is finished, merely comment it (2 points)
4. Method add(f: AstroNumeral)
This method you will have to write. It will create a new instance of AstroNumeral, and
perform the operation of such that the effect is: sum = this.numeral + f.numeral; Just
remember that you will need a loop to perform this along with some logic. Don’t forget
to return the instance called sum. (30 points for code + 10 for comments = 40 points)
5. Method subtract(f: AstroNumeral)
This method you will have to write. It will create a new instance of AstroNumeral, and
perform the operation of such that the effect is: difference = this.numeral - f.numeral;
Just remember that you will need a loop to perform this along with some logic. Don’t
forget to return the instance called difference. You may make the assumption that this.
numeral’s total value is greater than f.numeral’s. In other words, you may make the
assumption that the difference will never be negative. (30 points for code + 10 for
comments = 40 points)
6. Method toStringAsMoney()
This method is finished, merely comment it and explain how it works. (10 points)
7. Method zeroOut ()
This method you will finish, it should take the numeral array, and put zeroes in every
index position. 10 points for code 2 points for comments = 12 points)
8. Method parseStringToMoney(s:String)
This method is finished, merely comment it and explain how it works. (10 points)
9. TestAstro class and main method
This entire class is finish. Merely comment it and explain how it works. (7 points)

This is a solo project. You may not work with anyone else. You may get help from the TA’s, mentors, and
instructor. Submit your completed program source code to myCourses. Any work you create as a result
of this project is the property of the University of Massachusetts Dartmouth. This document and any
and all source code cannot be shared with anyone except: University of Massachusetts Dartmouth
faculty (including TA’s), and in a private digital portfolio (public access online is prohibited) with the
intention of applying to jobs and internships.


欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468