java program structure and error check
Part 1a:
In most of the Lab2Part1c code I have looked at, students have basically followed this pattern:
Calculate all the digits into mill, thou, etc.
Print the digits and pluses following the instructions.
This means that you need a whole BUNCH of digit variables to be declared at the top because you are doing all the calculations before you do any printing.
However, in Lab3Part1 you have to take out the BUNCH of variables and reduce down to just a single digit variable.In order to do this, you will need to reuse the digit variable over and over.However, if you tried to do all the digits with just one variable and then print that variable for every digit at the end, that would just put the last digit in.So, to make this work, you need to interleave the digit and remainder statements in between each pair of plus and digit printing statements.Note that you need to have the digit calculation and the remainder calculation using the same denominator to meet the other requirements so you’ll need a pattern like:
Calculate the current exponent
Find the current digit
Find the remainder
Decide if the plus should be printed
Decide if the digit should be printed
Calculate the next exponent
Find the next digit
Find the next remainder
Decide if the plus should be printed
Decide if the digit should be printed
…
All of this code is already in your Lab2Part1c but you are rearranging it except for using the exponent.I would recommend rearranging the code FIRST without any other changes and make sure it works in the rearranged format.Once that works, then start making the variable changes that are needed.
Reusing the same variable.
As an example of program output, if the user entered 908070600, your program should output:
908070600 = (9 * 10e8) +(8 * 10e6) +(7 * 10e4) +(6 * 10e2)
Part 1b:
Once Lab3Part1a works, Part 1b requires input error checking and adding more code to print more digits (from 7 digit numbers to 9 digit numbers).The printing code goes with the other printing code.
Where should the input error checking go and what should happen if an input error occurs?
Generally, input error checking goes as close to the input instructions as possible.Since you have two kinds of error checking to do, input data type and input range, think about which error would occur first and put that error checking code first.Then put the other error checking code immediately after that.Remember that you should check for the error and then handle the error and the error handling mechanism should be done.This means that you should NOT put a catch or an else around all the rest of your code.You should handle the error and then continue with the code.
