Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- readme.txt -- for number-display-ss
- THE TASK
- The spreadsheet displays numbers at full resolution, but this means a
- number with more than 8 or 9 digits is not fully visible in the text
- box. Modify the spreadsheet program so that numbers are displayed in cells
- with at most 8 characters. Use scientific notation and rounding as necessary.
- Hint: The 'g' conversion in the Java Formatter class might be helpful.
- REED'S NOTES:
- 1) Full Resolution: Translation?
- 2) *MORE THAN* 8 or 9 digits is *NOT* fully visible
- 3) *MODIFIY*...numbers...in cells...at *MOST* 8 characters
- 4) Scientific Notation: way of writing numbers that are too big or,
- too small to be conveniently written in decimal form.
- 5) Formatter: An interpreter for printf-style format strings.
- This class provides support for layout justification and alignment,
- common formats for numeric, string, and date/time data,
- and locale-specific output. Common Java types such as byte,
- BigDecimal, and Calendar are supported. Limited formatting
- customization for arbitrary user types is provided through
- the Formattable interface.
- Even if rounding is needed to display a number in a cell, all
- computation should use the full precision of every formula and value.
- Since the displayed values will be truncated, you will need a new
- instance variable in the Cell class to hold the full-precision value
- of the cell in case a formula references it. When a cell holds a
- formula, it is displayed in the formula bar. If the cell does not hold
- a formula, the full-precision value of the cell should be displayed
- and editable in the formula bar, even if the spreadsheet table shows a
- truncated version of the value.
- REED'S NOTES:
- 1) full precision: Translation?
- 2) *NEED* new *INSTANCE VARIABLE* in *Cell class*
- to hold the *full-precision value* of
- cell in case a formula *references it*:
- EX: Translation?
- 3) Cell holds formula -> full-precision value -> displayed -> formula bar
- EX: Translation?
- 4) Cell *NOT* holds formula -> full-precision value
- -> displayed & editable -> formula bar -> even if -> table shows
- -> truncated version value.
- EX: Translation?
- If a number is entered with 8 or fewer characters, it should not be
- reformatted; for example, if the user enters 123, the spreadsheet should not
- change the display to 123.0000.
- REED'S NOTES:
- 1) number -> 8 or fewer -> *NOT* reformatted
- Spreadsheet cells can also display text that cannot be parsed as a number.
- Nonnumber data should appear in cells without modification, even though
- not all characters will be visible at once.
- REED'S NOTES:
- 1) Nonnumber data -> appear -> in cells -> without modification
- Video demonstrations of a solution for this task are available.
- 1. During the exam: as number-display-solution-demo.html in the "Solution Demonstration Videos"
- folder on the desktop in the exam delivery environment.
- 2. During exam preparation, outside the exam environment.
- https://s3-us-west-2.amazonaws.com/proxor-video/video/number-display-solution-demo-transcoded.mp4
- REED'S NOTES:
- ***SCIENTIFIC NOTATION***
- 1) can display numbers in scientific notation using java.text package.
- Specifically DecimalFormat class in java.text package.
- EX:
- import java.text.*;
- import java.math.*;
- public class TestScientific {
- public static void main(String args[]) {
- new TestScientific().doit();
- }
- public void doit() {
- NumberFormat formatter = new DecimalFormat();
- int maxinteger = Integer.MAX_VALUE;
- System.out.println(maxinteger); // 2147483647
- formatter = new DecimalFormat("0.######E0");
- System.out.println(formatter.format(maxinteger)); // 2,147484E9
- formatter = new DecimalFormat("0.#####E0");
- System.out.println(formatter.format(maxinteger)); // 2.14748E9
- int mininteger = Integer.MIN_VALUE;
- System.out.println(mininteger); // -2147483648
- formatter = new DecimalFormat("0.######E0");
- System.out.println(formatter.format(mininteger)); // -2.147484E9
- formatter = new DecimalFormat("0.#####E0");
- System.out.println(formatter.format(mininteger)); // -2.14748E9
- double d = 0.12345;
- formatter = new DecimalFormat("0.#####E0");
- System.out.println(formatter.format(d)); // 1.2345E-1
- formatter = new DecimalFormat("000000E0");
- System.out.println(formatter.format(d)); // 12345E-6
- }
- }
- REED'S NOTES:
- ***'g' conversion***
- Conversions are divided into the following categories:
- GENERAL - may be applied to any argument type
- CHARACTER - may be applied to basic types which represent Unicode characters:
- char, Character, byte, Byte, short, and Short.
- This conversion may also be applied to the types int and Integer when Character.isValidCodePoint(int) returns true
- NUMERIC:
- INTEGRAL - may be applied to Java integral types: byte, Byte, short, Short, int and Integer, long, Long, and BigInteger
- FLOATING POINT - may be applied to Java floating-point types: float, Float, double, Double, and BigDecimal
- DATE/TIME - may be applied to Java types which are capable of encoding a date or time: long, Long, Calendar, and Date.
- PERCENT - produces a literal '%' ('\u0025')
- LINE SEPARATOR - produces the platform-specific line separator
- The following table summarizes the supported conversions.
- Conversions denoted by an upper-case character (i.e. 'B', 'H', 'S', 'C', 'X', 'E', 'G', 'A', and 'T')
- are the same as those for the corresponding lower-case conversion characters except that
- the result is converted to upper case according to the rules of the prevailing Locale.
- The result is equivalent to the following invocation of String.toUpperCase()
- out.toUpperCase()
- CONVERSION | ARGUMENT | CATEGORY DESCRIPTION
- 'b', 'B'| general | If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true".
- 'h', 'H'| general | If the argument arg is null, then the result is "null". Otherwise, the result is obtained by invoking Integer.toHexString(arg.hashCode()).
- 's', 'S' | general | If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invoking arg.toString().
- 'c', 'C' | character | The result is a Unicode character
- 'd' | integral | The result is formatted as a decimal integer
- 'o' | integral | The result is formatted as an octal integer
- 'x', 'X' | integral | The result is formatted as a hexadecimal integer
- 'e', 'E' | floating point | The result is formatted as a decimal number in computerized scientific notation
- 'f' | floating point | The result is formatted as a decimal number
- ***'g', 'G' | floating point | The result is formatted using computerized scientific notation or decimal format, depending on the precision and the value after rounding.***
- 'a', 'A' | floating point | The result is formatted as a hexadecimal floating-point number with a significand and an exponent
- 't', 'T' | date/time | Prefix for date and time conversion characters. See Date/Time Conversions.
- '%' | percent | The result is a literal '%' ('\u0025')
- 'n' | line separator | The result is the platform-specific line separator
- Any characters not explicitly defined as conversions are illegal and are reserved for future extensions.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement