
Educators: Earn a free Gold upgrade by joining the PBwiki Back To School Challenge.

Questions? Join PBwiki's weekly office hours today at 1 PM Eastern and get live answers.
Professor Glass' comments
IMPORTANT: Everyone will be required to eventually have their code meet these specifications. Others will be using your code and you will need to use others. You will not see the souce but have to match the specifications listed here and be able to use the code in your programs. Therefore, if you think these defintions are lacking, incomplete or not clear, change these specifications. - Dr. Glass
Think of this.
using only the functions on this page, outline / write to access the data (other than needing additional I/O)
I read the comments and some very good points were raised.
Question is, how do toy think it should be handled?
but how about on output? I call MyNumber.toString(4); there should be an exception, no? We do not handle base 4.
We decided that two different exceptions should be thrown. One for invalid number and one for an unsupported base.
The following people will have the following responsibilites. Attach your code (see Attach File button) next to your name (attaching makes it a link). You have 3 days (4//8, 4/9 and 4/10) to meet and to get this done. There is nothing wrong in adapting the code from your first assignments.
Dan: Base_number()
SoftEng constructors.java
Camron:
toString.java
RoyRubio: Everything else in the class other than the constructors and ToString() methods.
ViJay: Collecting it all and making a package
Armando: A main() that tests all methods including catching the exceptions.
Sunho: Re-do assignment 1 using this new package.
| CLASS VARIABLES | |||
| private int num | Changed by setNumber(int) and setNumber(char[], int). String output (and conversion) with toString(int) and integer output using getNumber(). |
||
| CONSTRUCTORS | |||
| Base_Number() |
Instantiates the class and set the num to 0. |
||
| Base_Number(char[] charArray, int base) throws Exception |
Invokes setNumber() to set class variable. charArray is the input and base is the current base of charArray. |
||
| private boolean isValid(char[] charArray, int base) throws Exception |
Checks validity of charArray according to base as well as base itself using supportedBase(). Example: "FE" base 16 is valid, "78" base 8 is invalid. May throw two exceptions: invalid base or invalid number. |
||
| private boolean supportedBase(int base) | Checks validity of base (currently 2, 8, 10, or 16 are valid). | ||
|
public void setNumber(int n) throws Exception |
Sets class variable num via an integer. | ||
| public void setNumber(char[] charArray, int base) throws Exception |
Sets class variable num via a string. Uses Horner's method to convert between bases. Example: AA base 16 --> base 10 = 10*16^1 + 10*16^0 = 170 Validates data using isValid() and therefore may throw one of two exceptions. |
||
| OUTPUT | |||
| public int getNumber() |
Useful for mathematical operations. | ||
| public String toString() | Output defaults to base 10. | ||
|
public String toString(int base) throws Exception |
Converts the number to the desired base and returns a string. Validates base using supportedBase() and throws an exception if unsupported. |
||
Page Information
|
Wiki Information |
Recent PBwiki Blog Posts |