"******Warning! Problem detected!******"
Warning! Problem detected!
Campbell Ritchie wrote:I have heard that one before. We often see people posting poor style code who say they will sort out the style when they have finished coding, but that isn't how it works. You sort out the style and the design as you go. Otherwise you will probably leave the poor quality code uncorrected and lose marks for it.
Campbell Ritchie wrote:
Start with names, which you can read about here. That link might be old, but it is still relevant. A class name like MonitorAnimal tells me that you are looking for monitor lizards, not that you want to do any monitoring of animals. You would want to call the class AnimalMonitorer (only that is unpronounceable); monitorAnimal() might however be good name for a method. The act that you used those names in your code shows how much better they are as names for methods.
LInes 12‑13 show up a problem. You are not calling any methods there, but only creating objects. Yes, you need objects, but making them is only a part of the whole process. You need to know the difference between creating objects and calling methods on them. You would want something like animalWatcher.observeAnimal(a); where a is a variable of type Animal. So you need to decide what such a method is going to do, and then write the method to do that.
Lines 33 and 40 show you writing something you know will cause your code to ail to compile, so what's the point of that?
Tim Holloway wrote:I didn't notice, maybe someone already said it, but "this" isn't an implicit parameter. It's an implicit member variable. Or, if you prefer, it's defined as a private member of the ultimate base class, java.lang.Object, albeit one that is not formally documented. And constructed referencing the class instance it's defined in.
Angus Ferguson wrote:Please have a look at this piece of code.
You were trying to call the methods by using the instance of your classes. The instance of the class MonitorAnimal, for example, allows you to call the methods written in that class by adding a dot at the end of the instance. So, in this case, we are supposing that .method1() has been written within the MonitorAnimal class.
Angus Ferguson wrote:Instead of adding logic to the main, it is recommendable to write a run method. The code becomes much more robust and clean. You can have a look at this Main - Pain article.
Fred Kleinschmidt wrote:In your first example, you calculate avgVal on line 21 BEFORE you calculate the sumVal. That is, sumVal is still zero.
In the second example, you calculate the average AFTER you have summed up all of the values.
Modify the program to print the average (mean) as well as the sum. Hint: You don't actually have to change the loop, but rather change what you print.
Enter 8 integer values...
Junilu Lacar wrote:
Bill Platt wrote:My thinking with call it "multiple parameters" was that when the method was defined, char horizChar & char vertChar were both required parameters.
Am I still misunderstanding this?
No, you're not misunderstanding it because that actually is a method that is defined with multiple parameters. However, your subject and the fact that the printTicTacToe() method is called with two parameters has absolutely nothing to do with the question/problem you had, so it's a poor choice of words. A better subject might have been "Why am I getting a number when I print out characters?" or even "Why does this work if I add "" in front?"
Carey Brown wrote:I'm a stickler for asthetics. I prefer this spaced output.
Junilu Lacar wrote:By the way, the subject you used for this thread indicates a little bit of misunderstanding on your part at worst and poor choice of words at best.
In the System.out.println() statement in question, you are only passing in one argument/parameter. You've used a multi-term expression which gets evaluated down to a single value which is then passed to the println() method.
Junilu Lacar wrote:Since you're already familiar with how to use a Scanner, why don't you just use that? See the JavaDocs for Scanner, you can create one that reads from a file. https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html