Hi guys, Im a little stuck with this one. Im doing this Java programming using the book The Art & Science of Java by Eric Roberts.
Basically what this program should achieve is that the user enters in a list of integers, one line at a time, and keep going until the SENTINEL(in this case 0) is called. When the SENTINEL is called, the program "SHOULD" takes a look back at all the integers entered and displays the LARGEST of them all.
I think if you see below, I shouldn't think I'm that far off but can anyone help me out and point out what exactly that I am missing from what you can see below:
At the moment, what mine displays is the last integer entered instead of the Largest integer in the list.
Secondly, please post complete code. What is inside acm.program package? What does ConsoleProgram class do? Why FindLargest has to extend ConsoleProgram?
Now, coming to the point, before you do anything, I would advice to take pencil and paper, and write the complete flow step by step. Please do not start coding before you understand what you want to do.
Currently, your program displays last number which is not equal to SENTINEL (by the way, why SENTINEL is not final?) entered because you are storing last number entered in findLargest variable (again, this name sounds like a method name, not a variable name)
Hint : to find largest number, at some point of time, you need to compare two numbers, right? Your code is not doing it at all.
You have made the mistake of trying to write code before you worked out what it does. You should go through the specification and write down on paper what you intend to do. You will need a pencil and eraser; the latter is very important
Don’t write any code until you have completed that process.
Also check what it says about a list. If that means a java.util.List<Integer> that is what you will have to use. You will find it easier to use when you know about boxing conversions.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: The Art & Science of Java Chapter 4 Exercise 12 FindLargest.java