Difference between revisions of "Cash Receipt"

From CompSciWiki
Jump to: navigation, search
Line 3: Line 3:
 
|ProblemName=Cash Receipt
 
|ProblemName=Cash Receipt
  
|Problem=Today your manager wants you to write a complete Java program that can be used by a cashier to generate customer receipts for her convenience store which sells only three items.<br><br>First: The three items are brush sets, paint sets and primer. Use constants to store the cost of each of the three items and the tax rate.<br>  
+
|Problem=You are a self employed junior programmer. You've just started your own business and today, you've gotten your first job from a manager at a small arts and crafts store. The manager wants you to write a complete Java program that can be used by any cashier within her company to generate customer receipts for her convenience store which currently sells only three items.<br><br>First: The three items are brush sets, paint sets and primer. Since the prices of these materials will not change for a long time, you should use constants to store the cost of each of the three items and the tax rate.<br>  
<br>Then, since the program is going to be used by multiple cashiers, use JOptionPane to prompt the user to enter:<br>1) the cashier’s name<br>2) the quantity of each item.<br><br>The program will calculate and output:<br>  1) the subtotal<br>  2) tax<br>  3) total.<br><br>
+
<br>Then, since the program is going to be used by multiple cashiers, use JOptionPane to prompt the user to enter:<br>1) The current cashier’s name<br>2) the quantity of each item.<br><br>The program will calculate and output:<br>  1) the subtotal<br>  2) tax<br>  3) total.<br><br>
After the program calculates and prints out the receipt up to the total amount owed.<br>1) prompt the cashier to enter a payment amount, <br>2) calculate any change needed to be given back to the customer and <br>3) round the change given to the nearest nickel.<br><br>
+
As each item is entered, the program prints out the input given on a new line each time. After the quantity of the last item is entered, the program calculates a subtotal and prints it, then it prints out the tax value, and then calculates the subtotal plus tax as a final total and prints that value.<br><br>Now the program waits for the cashier to enter in a payment given amount. So now:<br>1) Prompt the cashier to enter a payment amount, <br>2) calculate and print any change needed to be given back to the customer (if they overpaid) and <br>3) round the change given to the nearest nickel and print that value.<br>4)Finally print out "Change given by: <cashier's name>"<br><br>
Calculate and output: <br>1) The change due (to the nearest penny)<br> 2) The change due (to the nearest nickel)<br> 3) the name of the cashier.<br><br>
+
 
'''<u>Some details:'''</u><br>
 
'''<u>Some details:'''</u><br>
 
'''Constants:''' Store the cost of each item as a constant. Also, store the tax rate (7%) as a constant.<br>  
 
'''Constants:''' Store the cost of each item as a constant. Also, store the tax rate (7%) as a constant.<br>  
 
'''Input:'''  Prompt the user to enter his/her name. Then use JOptionPane to input the quantity of each item. Finally use JOptionPane to input the amount of change given.<br>  
 
'''Input:'''  Prompt the user to enter his/her name. Then use JOptionPane to input the quantity of each item. Finally use JOptionPane to input the amount of change given.<br>  
'''Calculate and Output:''' <br>1) the subtotal (the cost of the items without tax)<br> 2) tax<br> 3) total (of product plus taxes).<br> Also output the name of your store at the top of the receipt. When finding the change, use Math.ceil to round up so the customer gets the full change, and possibly more. For example, if the change due is 4.637, round to 4.64 using pennies and 4.65 using nickels.  <br>  
+
'''Calculate and Output:''' <br>1) the subtotal (the cost of the items without tax)<br> 2) tax<br> 3) total (of product plus taxes).<br> Also output the name of your store at the top of the receipt. When finding the change, use [http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Math.html Math.ceil] to round up so the customer gets the full change, and possibly more. For example, if the change due is 4.637, round to 4.64 using pennies and 4.65 using nickels.  <br>  
 
'''Use Math.round() to round all output to two decimal spots.'''<br>
 
'''Use Math.round() to round all output to two decimal spots.'''<br>
If your input values were 2 brush sets ($8 each), 3 paint sets ($40 each), and 4 cans of primer ($18.75 each), your output should look like:  
+
If your input values were 2 brush sets ($8 each), 3 paint sets ($40 each), and 4 cans of primer ($18.75 each), and your cashier's name is Joni, your output should look like:  
  
 
<pre>
 
<pre>
 
Welcome to ArtSupply.
 
Welcome to ArtSupply.
  
Cashier: Sarah
+
Cashier: Joni
 
+
 
2 brush sets at $ 8.0
 
2 brush sets at $ 8.0
 
 
3 paint sets at $ 40.0
 
3 paint sets at $ 40.0
 
 
4 primer at $ 18.75
 
4 primer at $ 18.75
 
 
Product Total: $211.0
 
Product Total: $211.0
 
 
Tax: $ 14.77
 
Tax: $ 14.77
 
 
Total = $ 225.77
 
Total = $ 225.77
 
 
Money received: $ 250.0
 
Money received: $ 250.0
 
 
Change due: $ 24.23
 
Change due: $ 24.23
 
 
Change rounded up to nearest nickel: $ 24.25
 
Change rounded up to nearest nickel: $ 24.25
 +
Change given by: Joni
 
</pre>
 
</pre>
  
  
'''Your employer wants you to use proper programming practices which happen to be exactly the same as the standards in Comp 1010.'''
+
'''The store manager wants you to use proper programming practices which happen to be exactly the same as the standards in Comp 1010.'''
  
  
  
 
|Solution=
 
|Solution=
There are some mental pre-steps you need to take before you start writing code. After, you need to set up your variables you know you need (part zero), then code the problem in two more parts (part one and part two).
+
There are some mental pre-steps you need to take before you start writing code. After, you need to set up the variables you know you need (part zero) and initialize them, then code the problem in two parts (part one and part two).
  
  
 
==Break the problem down==
 
==Break the problem down==
While this problem is a bit more lengthy than others, the first rule of Computer Science is to break the program into pieces. Ultimately we want to get the whole program done, but we need to break it into parts we can work on and do it bit by bit. This means reading the problem and figuring out what you need to do logically step by step.
+
While this problem is a bit more lengthy than others, the first rule of Computer Science is to break the program into pieces. Ultimately we want to get the whole program done, but we need to break it into parts we can work on and do it bit by bit. This means reading the problem and figuring out what you need to do logically step by step. Generally, in the problem description above, you will have to make up the "some details" section yourself as in future courses, it will not be provided.
  
 
==Declare your variables==
 
==Declare your variables==
Based on the problem description, we know we will need to use constants and use [http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html JOptionPane]. [http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html JOptionPane] means storing text in [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html strings]. We're also dealing with [http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html integers] and decimal value numbers ([http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Double.html doubles]).
+
Based on the problem description, we know we will need to use constants and use [http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html JOptionPane]. [http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html JOptionPane] means storing text in [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html strings]. We're also dealing with [http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html integers] and decimal value numbers which are ([http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Double.html doubles]).
  
 
==Keep your code organized==
 
==Keep your code organized==
The [http://courses.cs.umanitoba.ca/index.asp?sec=3394&too=30&eve=1&ppa=5178 COMP 1010 Coding Standards] give the foundation required to complete the code organization task for this case study. You need to make sure your code is properly indented, variable names are properly named and initialized to zero or empty string constants which are "", and comments are included in your code.
+
The [http://courses.cs.umanitoba.ca/index.asp?sec=3394&too=30&eve=1&ppa=5178 COMP 1010 Coding Standards] give the foundation required to complete the code organization task for this case study. You need to make sure your code is properly indented, variable names are properly named (as in: ''double change'', as opposed to: ''double a'') and all variables are initialized to zero or empty string constants which are "". Also, comments should always be included in your code.
  
 
==Get it done==
 
==Get it done==
Some programs will take longer than one sitting to get done. You must realize and accept that some programs can be done quickly, and some take a very long time, and that no matter what you code, you will always have to deal with bugs. Start on the programs early enough and don't procrastinate.
+
Some programs will take longer than one sitting to get done. You must realize and accept that some programs can be done quickly, and other programs can take a very long time. No matter what you code, you will always have to deal with bugs. Start on your programs early enough and don't procrastinate. Leaving a program to the last minute especially further on in the Computer Science degree will cost you mentally and hurt your marks.
  
 
==Part zero, starting out==
 
==Part zero, starting out==
Line 91: Line 82:
 
</pre>
 
</pre>
  
After, you want to continue on by prompting the user to enter in 3 numbers using [http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html JOptionPane]. Each time the user enters a number you want to convert the entered value to an integer. This can be done using
+
After, you want to print out the string value and move the cursor to a new line. You can do this by using the System.out.println("<text>") function. Continue on by prompting the user to enter in 3 numbers using [http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html JOptionPane]. Each time the user enters a number you want to convert the entered value to an integer and then print the numbers. This can be done using
 
<pre>
 
<pre>
 
IntegerVariable = Integer.parseInt(StringVariable);
 
IntegerVariable = Integer.parseInt(StringVariable);
 
</pre>
 
</pre>
 +
 +
To print the numbers, you use System.out.println(<variable name>)
  
 
We can also assume that the user is entering a number and therefore we do not need to do any error checking.
 
We can also assume that the user is entering a number and therefore we do not need to do any error checking.
  
'''Note for extended development:''' to error check this code, you can take the input text and store it into a string. Then you can use a piece of code called a [http://www.exampledepot.com/egs/Java%20Language/TryCatch.html try catch block].
+
'''Note for extended development:''' to error check this code, you can take the input text and store it into a string. Then you can use a piece of code called a [http://www.exampledepot.com/egs/Java%20Language/TryCatch.html try catch block] along with a [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/NumberFormatException.html NumberFormatException].
 +
 
 +
After these inputs are entered, you need to do some math. Proceed by calculating the subtotal, tax and the total amount using simple math equations. After the values are calculated, print out in order per line the subtotal, the tax, the total amount.
  
After these inputs are entered, you need to do some math. Proceed by calculating the subtotal, tax and the total amount using simple math equations. After the values are calculated, print out in order per line the Cashier's name, the number of brushes bought, the number of paint cans bought, the number of primer bought, the subtotal, the tax, the total amount.
+
'''You are now about half way done this program!'''
  
 
==Part two==
 
==Part two==
Now the cashier is waiting for you to pay. Assuming you're not a thief, you will hand the cashier an amount greater than or equal to the total amount owing. Again you do not need to error check to make sure you give the cashier a proper amount.
+
Now the cashier is waiting for the customer to pay. Assuming the customer isn't not a thief, they would hand the cashier an amount greater than or equal to the total amount owing. Being the programmer that you are, you know you need to code your program to allow for this transaction to occur. Again you do not need to error check to make sure the customer give the cashier a proper amount (meaning that the customer did not shortchange the cashier).
  
 
'''Note for extended development:''' You can check to make sure that the amount of change you give to the cashier is greater than the total owing by using an [http://download.oracle.com/javase/tutorial/java/nutsandbolts/if.html if statement].
 
'''Note for extended development:''' You can check to make sure that the amount of change you give to the cashier is greater than the total owing by using an [http://download.oracle.com/javase/tutorial/java/nutsandbolts/if.html if statement].
Line 109: Line 104:
 
Again use [http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html JOptionPane] to prompt for an amount given, and then convert it to a double (no error checking again is needed, however once again you can use a [http://www.exampledepot.com/egs/Java%20Language/TryCatch.html try catch block] for further development). To convert to a double, you can use:
 
Again use [http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html JOptionPane] to prompt for an amount given, and then convert it to a double (no error checking again is needed, however once again you can use a [http://www.exampledepot.com/egs/Java%20Language/TryCatch.html try catch block] for further development). To convert to a double, you can use:
 
<pre>
 
<pre>
DOubleVariable = Double.parseDouble(StringVariable);
+
DoubleVariable = Double.parseDouble(StringVariable);
 
</pre>
 
</pre>
  
Print out the money recieved, then subtract the total owed from the amount of change given. Then calculate any change the cashier needs to give back to the customer and print it out (even if it is $0.00). Finally round the amount of change given back to the nearest nickel and print that value.
+
Print out the money received, then subtract the total owed from the amount of change given. Then calculate any change the cashier needs to give back to the customer and print it out (even if it is $0.00). Finally round the amount of change given back to the nearest nickel and print that value.
  
 
Your code is now complete!
 
Your code is now complete!
  
'''Final note for extended knowledge:''' If you get a value in your output that is longer than expected, ie: for calculating change, instead of $0.07 being printed, you get a number like: 0.069999999... there is no bug in your code causing this. You can fix it by multiplying your number by 100, rounding it, and then dividing it by 100. If you want more information on why extra numbers appear, please take [https://aurora.umanitoba.ca/banprod/bwckctlg.p_disp_course_detail?cat_term_in=201090&subj_code_in=COMP&crse_numb_in=2190 Comp 2190]
+
'''Final note for extended knowledge:''' If you get a value in your output that is longer than expected, ie: for calculating change, instead of $0.07 being printed, you get a number like: 0.069999999... there is no bug in your code causing this. You can fix it by multiplying your number by 100, rounding it, and then dividing it by 100. If you want more information on why extra numbers appear, please take [https://aurora.umanitoba.ca/banprod/bwckctlg.p_disp_course_detail?cat_term_in=201090&subj_code_in=COMP&crse_numb_in=2190 COMP 2190]
 +
 
 +
==Post-programming instructions==
 +
Now you may want to close your program, submit it and be happy that you're done! Unfortunately, reality doesn't work that way. You are only about half done with your program. The other half is coders need to make sure their program works, and is done properly. Below are a few steps you need to take when you feel you have finished your program.
  
 
==Look it over==
 
==Look it over==
After your program is working, check for efficiency. This will come into play later on in the degree, but you should practice doing it now. Below are some methods to help you become more efficient.
+
After your program is working, check for efficiency. This will come into play later on in the Computer Science degree, but you should practice doing it now. The next two sections are some methods to help you become more efficient.
  
 
==Fix the Errors in the Code==
 
==Fix the Errors in the Code==
Line 128: Line 126:
  
 
==Try and break your program==
 
==Try and break your program==
In this question, breaking your code would be easy to do as unless you implement the error checking procedures. You could easily break your code by entering in a letter instead of a number and trying to convert a string into an integer or double. However, if you do implement the error checking procedures in this program, and for your future programs, the best way to make sure you have complete and fantastic code is if you can not make your program explode no matter what you do. The number one reason individuals are penalized for their code is because a random situation arises, even though it's highly unlikely to happen (but they do), and the programmer has not added the necessary code to handle the exception.
+
In this question, breaking your code would be easy to do unless you implement the error checking procedures. You could easily break your code by entering in a letter instead of a number and trying to convert that string into an integer or double. However, if you do implement the error checking procedures in this program, and for your future programs, the best way to make sure you have complete and fantastic code is if you can not make your program explode no matter what you do. The number one reason individuals are penalized for their code is because a random situation arises, even though it's highly unlikely to happen (but they do), and the programmer has not added the necessary code to handle the exception.
  
==Parting statements==
+
==The feeling of hopelessness==
 +
There will be times that arise when you've gone too far down one path and your code is too far gone to fix properly. Understand that at times completely restarting the whole program over is a quicker and more sane option than attempting to fix it properly. In other cases, backing up part way is more efficient. Make sure you save working versions of your program along the way. Lastly within this section, back up your code! If your computer dies and you loose your file, that's your responsibility!
  
 +
==Parting statements==
 
Remember that this is not the only "correct" way to do this program. There can be many different ways to accomplish this program and it can be further developed to handle error checking from any aspect. Remember to code efficiently, accurately, and properly. This means: no more excess code than needed, know what you're trying to code and break it down as needed to accomplish parts of it at a time rather than the whole thing in one sitting, and comment and indent your code appropriately. Always remember to test your program as much as you possibly can, and practice, practice, practice! The more you code, the better you will become at it.
 
Remember that this is not the only "correct" way to do this program. There can be many different ways to accomplish this program and it can be further developed to handle error checking from any aspect. Remember to code efficiently, accurately, and properly. This means: no more excess code than needed, know what you're trying to code and break it down as needed to accomplish parts of it at a time rather than the whole thing in one sitting, and comment and indent your code appropriately. Always remember to test your program as much as you possibly can, and practice, practice, practice! The more you code, the better you will become at it.
  

Revision as of 12:44, 31 March 2011

Back to the Case Studies homepage

Problem

You are a self employed junior programmer. You've just started your own business and today, you've gotten your first job from a manager at a small arts and crafts store. The manager wants you to write a complete Java program that can be used by any cashier within her company to generate customer receipts for her convenience store which currently sells only three items.

First: The three items are brush sets, paint sets and primer. Since the prices of these materials will not change for a long time, you should use constants to store the cost of each of the three items and the tax rate.

Then, since the program is going to be used by multiple cashiers, use JOptionPane to prompt the user to enter:
1) The current cashier’s name
2) the quantity of each item.

The program will calculate and output:
1) the subtotal
2) tax
3) total.

As each item is entered, the program prints out the input given on a new line each time. After the quantity of the last item is entered, the program calculates a subtotal and prints it, then it prints out the tax value, and then calculates the subtotal plus tax as a final total and prints that value.

Now the program waits for the cashier to enter in a payment given amount. So now:
1) Prompt the cashier to enter a payment amount,
2) calculate and print any change needed to be given back to the customer (if they overpaid) and
3) round the change given to the nearest nickel and print that value.
4)Finally print out "Change given by: <cashier's name>"

Some details:
Constants: Store the cost of each item as a constant. Also, store the tax rate (7%) as a constant.
Input: Prompt the user to enter his/her name. Then use JOptionPane to input the quantity of each item. Finally use JOptionPane to input the amount of change given.
Calculate and Output:
1) the subtotal (the cost of the items without tax)
2) tax
3) total (of product plus taxes).
Also output the name of your store at the top of the receipt. When finding the change, use Math.ceil to round up so the customer gets the full change, and possibly more. For example, if the change due is 4.637, round to 4.64 using pennies and 4.65 using nickels.
Use Math.round() to round all output to two decimal spots.
If your input values were 2 brush sets ($8 each), 3 paint sets ($40 each), and 4 cans of primer ($18.75 each), and your cashier's name is Joni, your output should look like:

Welcome to ArtSupply.

Cashier: Joni
2 brush sets at $ 8.0
3 paint sets at $ 40.0
4 primer at $ 18.75
Product Total: $211.0
Tax: $ 14.77
Total = $ 225.77
Money received: $ 250.0
Change due: $ 24.23
Change rounded up to nearest nickel: $ 24.25
Change given by: Joni


The store manager wants you to use proper programming practices which happen to be exactly the same as the standards in Comp 1010.

 

SideSectionTitle

SideSection goes here.

Solution

There are some mental pre-steps you need to take before you start writing code. After, you need to set up the variables you know you need (part zero) and initialize them, then code the problem in two parts (part one and part two).


Break the problem down

While this problem is a bit more lengthy than others, the first rule of Computer Science is to break the program into pieces. Ultimately we want to get the whole program done, but we need to break it into parts we can work on and do it bit by bit. This means reading the problem and figuring out what you need to do logically step by step. Generally, in the problem description above, you will have to make up the "some details" section yourself as in future courses, it will not be provided.

Declare your variables

Based on the problem description, we know we will need to use constants and use JOptionPane. JOptionPane means storing text in strings. We're also dealing with integers and decimal value numbers which are (doubles).

Keep your code organized

The COMP 1010 Coding Standards give the foundation required to complete the code organization task for this case study. You need to make sure your code is properly indented, variable names are properly named (as in: double change, as opposed to: double a) and all variables are initialized to zero or empty string constants which are "". Also, comments should always be included in your code.

Get it done

Some programs will take longer than one sitting to get done. You must realize and accept that some programs can be done quickly, and other programs can take a very long time. No matter what you code, you will always have to deal with bugs. Start on your programs early enough and don't procrastinate. Leaving a program to the last minute especially further on in the Computer Science degree will cost you mentally and hurt your marks.

Part zero, starting out

You will need to have two string variables. You also need three integer variables, six double variables and four double constants.

The String variables are to:
Handle all input strings
Store the cashier's name

The integer variables are to store the number of ______ bought:
Brushes
Paint sets
Primer

The double variables are to store:
The tax
The sub total of the bill
The total of the bill (with tax)
The total payment given
The total change returned
The total change given to the nearest nickel

The double constant variables are to store: The tax rate
The cost of the brushes
The cost of the paint
The cost of the primer

Part one, continue with some code

Now that you've completed the first task of setting up variables (and remembering to initialize them all to either 0 or empty string constants which are ""), the next task you want to do is prompt the user to enter their name. To do this, you need to use JOptionPane. Then you want to store the text entered in a string. This can be simply done by:

StringVariable = JOptionPane.showInputDialog

After, you want to print out the string value and move the cursor to a new line. You can do this by using the System.out.println("<text>") function. Continue on by prompting the user to enter in 3 numbers using JOptionPane. Each time the user enters a number you want to convert the entered value to an integer and then print the numbers. This can be done using

IntegerVariable = Integer.parseInt(StringVariable);

To print the numbers, you use System.out.println(<variable name>)

We can also assume that the user is entering a number and therefore we do not need to do any error checking.

Note for extended development: to error check this code, you can take the input text and store it into a string. Then you can use a piece of code called a try catch block along with a NumberFormatException.

After these inputs are entered, you need to do some math. Proceed by calculating the subtotal, tax and the total amount using simple math equations. After the values are calculated, print out in order per line the subtotal, the tax, the total amount.

You are now about half way done this program!

Part two

Now the cashier is waiting for the customer to pay. Assuming the customer isn't not a thief, they would hand the cashier an amount greater than or equal to the total amount owing. Being the programmer that you are, you know you need to code your program to allow for this transaction to occur. Again you do not need to error check to make sure the customer give the cashier a proper amount (meaning that the customer did not shortchange the cashier).

Note for extended development: You can check to make sure that the amount of change you give to the cashier is greater than the total owing by using an if statement.

Again use JOptionPane to prompt for an amount given, and then convert it to a double (no error checking again is needed, however once again you can use a try catch block for further development). To convert to a double, you can use:

DoubleVariable = Double.parseDouble(StringVariable);

Print out the money received, then subtract the total owed from the amount of change given. Then calculate any change the cashier needs to give back to the customer and print it out (even if it is $0.00). Finally round the amount of change given back to the nearest nickel and print that value.

Your code is now complete!

Final note for extended knowledge: If you get a value in your output that is longer than expected, ie: for calculating change, instead of $0.07 being printed, you get a number like: 0.069999999... there is no bug in your code causing this. You can fix it by multiplying your number by 100, rounding it, and then dividing it by 100. If you want more information on why extra numbers appear, please take COMP 2190

Post-programming instructions

Now you may want to close your program, submit it and be happy that you're done! Unfortunately, reality doesn't work that way. You are only about half done with your program. The other half is coders need to make sure their program works, and is done properly. Below are a few steps you need to take when you feel you have finished your program.

Look it over

After your program is working, check for efficiency. This will come into play later on in the Computer Science degree, but you should practice doing it now. The next two sections are some methods to help you become more efficient.

Fix the Errors in the Code

If you have any bugs in your program, check them over and fix them!

Optimize the Code by Removing Unnecessary Variables

At the top of the main method, you should have a number of variables. If you have any extra than what the above solution suggests, see if you can get rid of any extras you don't need.

Try and break your program

In this question, breaking your code would be easy to do unless you implement the error checking procedures. You could easily break your code by entering in a letter instead of a number and trying to convert that string into an integer or double. However, if you do implement the error checking procedures in this program, and for your future programs, the best way to make sure you have complete and fantastic code is if you can not make your program explode no matter what you do. The number one reason individuals are penalized for their code is because a random situation arises, even though it's highly unlikely to happen (but they do), and the programmer has not added the necessary code to handle the exception.

The feeling of hopelessness

There will be times that arise when you've gone too far down one path and your code is too far gone to fix properly. Understand that at times completely restarting the whole program over is a quicker and more sane option than attempting to fix it properly. In other cases, backing up part way is more efficient. Make sure you save working versions of your program along the way. Lastly within this section, back up your code! If your computer dies and you loose your file, that's your responsibility!

Parting statements

Remember that this is not the only "correct" way to do this program. There can be many different ways to accomplish this program and it can be further developed to handle error checking from any aspect. Remember to code efficiently, accurately, and properly. This means: no more excess code than needed, know what you're trying to code and break it down as needed to accomplish parts of it at a time rather than the whole thing in one sitting, and comment and indent your code appropriately. Always remember to test your program as much as you possibly can, and practice, practice, practice! The more you code, the better you will become at it.

Code

Solution Code

Back to the Case Studies homepage