Jesse Just wrote:I am not to sure on how to call the items from the array individually and display them with the tax.
Then why have you written any code at all? Programming isn't (or shouldn't be) an existential process, it's a
refinement one; and in order to make it so, you need to
understand the problem before you start writing code. There's nothing wrong with writing a program in small pieces (in fact, it's a very good idea), but you need to write a piece
AND test it completely before you continue to the next one.
My advice:
StopCoding (←click). And read the advice in that page thoroughly.
Tip #1: Rename your current class
CashRegister. Class names should always start with capital letters.
Tip #2: Remove ALL your code from your
main() method. Here's a simple way to do it:
1. Rename your
main() method to
run() and remove the
static qualifier, viz:
public void run() { ...
(Note: no
static, and no parameters).
and for now just leave the code that you've already written inside it.
2. Create a
new public class in a new file called
CashRegisterTest, and give
it a
main() method, which should look
exactly as follows:
Now you have a properly written
Java class with a test driver; and this is how
all your exercise classes should start out life.
It may look like we've just moved the code from
main() to a method called
run(), but we've actually done something much more important:
Each
CashRegister is now an
object.
Tip #3: Initially write your CashRegister class (or rather, its
run() method) to handle
ONE item - and ONLY one. Then add another...then another...and when you're on your 3rd or 4th,
then start thinking about how you can turn that into a loop than handles items until you tell it to stop.
Tip #4: Break up your
run() logic into discrete functions (or, as in the case of an
Item, a class), and write those functions as methods in your CashRegister class, which you then
call from your
run() method.
HIH
Winston