Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Justin Robbins wrote:@Les Morgan That's great set up! and from what I've been reading a lot of code seems to go in that order. So generally speaking, all the static and instance variables go within that area right after that first class bracket? then the constructor. Then the Main method, I understand that to be the entry point of the program, or the starting point. Are the methods generally after the main method? I may be mistaken here but I think I've seen them possibly declared right after the class bracket? Could you explain what constructors and inner classes are?
Thank you!
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Les Morgan wrote:Yes, after the class header the static variables are listed first, then the instance variables.
Java is a little more free style in it's layout than I care for--yes, I'm a control freak--so as I said the layout that I showed is mainly my style that I have come to settle upon. I have seen things laid out in a few ways, but I like to see what I'm going to use before I get there or have a logical and predefined way of looking for things.
Constructors are special methods that shape the class when it is instantiated. You can do any initialization you need here or customizations as need to the resulting object.
inner classes are classes that are defined as a whole inside another class. They inherit the environment of the parent class, as they are, in actuality, part of that parent class.
Thank you!
Nikki Smith wrote:I'm currently in Java II, but when I started in Java I the professor told us to use "buckets" to keep things organized.
The first is variables
Second is input
Third is calculations
Fourth is output
For the first few assignments we had to make comments separating each 'bucket' as best we could.
Here's an old assignment in which I used that method:
Not sure if this helps, but I suppose it could be useful if you're just starting out.
Purpose - calculate the take home pay after income tax is subtracted
Input - User is prompted to input their name, age and income
Process - The name and age are each stored in separate variables that are
returned as-is except that the name is displayed in lowercase
income * taxRate finds the income tax ammount and stores it in incomeTax
takeHomePay = income - incomeTax
Output - Users name, age, income, income tax and take home pay are displayed
simple pseudocode:
create keyboard scanner to obtain input
obtain input name, age, income
calculate incomeTax = income * taxRate;
calculate takeHomePay = income - incomeTax;
display user-defined name, age, income and post-calculation income tax amount and take home pay
detailed pseudocode:
create keyboard scanner to obtain input
prompt user for their name
obtain user name
prompt user for their age
obtain user age
prompt user for their income
obtain user income
determine incomeTax = income * taxRate;
determine takeHomePay = income - incomeTax;
display user-defined name, age, income and post-calculation income tax
amount and take home pay on separate lines
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Les Morgan wrote:Nope, that is generally not how it works.
OK... everything in Cat is part of Cat. Leg inherits furColor from Cat, but legColor is in the class Leg which is an inner class of Cat. Dog is a separate class from Cat, but contained in the same file.
Please NOTE: none of the code was run through any checks, so it may or may not be totally accurate.
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Justin Robbins wrote:Thank you so much Nikki! I copied this and put it in my Eclipse workspace for future reference. I wish my teacher would make us outline things like this. The whole idea of buckets is wonderful.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |