Win a copy of Head First Android this week in the Android forum!

Will Pritchard

Greenhorn
+ Follow
since Sep 16, 2015
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Will Pritchard

Woah! Let's not get violent and shoot tutors. I was not given the code, but I did follow what my tutor was doing. Sorry.

So, I removed the statics and redundancy and sure enough! It works! Okay, now, how would I load everything from the user into either an array or arrayList? Should I put that in main? I was thinking doing a return ToString in a display method and then saving that to an array or arrayList. Would that work?

Oh, and about the interestCalc method and interestRate... local variables are not allowed in that class. =( also, my interestRate variable is a double. Is that correct? I thought dividing a number by 100 would give a percentage. How can I fix that?
6 years ago

Winston Gutkowski wrote:

Will Pritchard wrote:Hey forum! I'm not sure if it is allowed to post a homework assignment or not...


. . .
Hope it helps.

Winston



Just changed them to a non-static variables and the other subclasses freaked out. I guess that is why they are static. Also, Carrie and Campbell, thanks for the advice! I'll try to put the arrays in the actual class itself, and I'll make sure to update the interest rate.
6 years ago
Hey Winston! Replying to you on my phone, so for some reason, I cannot quote. Thank you for the cow! I'm glad I accidentally made a good post! My professor said it is okay to put data into an array vs. arrayList, but I'm still not positive how to add values from different classes to an array/arrayList in a Main. Perhaps I missed it in the "main is a pain" link you provided. So, should I do an <array>.add(value, value, value) in main?
6 years ago
I'll remove static at once. Also, I should have asked WHERE do I create it. My bad!
6 years ago
Hey forum! I'm not sure if it is allowed to post a homework assignment or not, but I do need some help. I pretty have the program made except I have no idea how to save user input/values to an array in a main class/method that gets information from one superclass and two subclasses. Is there anyone that can help me out with this, please? Here is the description from the assignment:

To demonstrate polymorphism, create an arrayList of Account type that can handle Checking and Savings accounts (this is the Bank). Prompt for name, account number (or assign account number in main) and add at least one checking object and one savings object to the bank array.
Now use a loop to process all accounts USING THE Bank array.

Here is what I've programmed so far:
Main - I was just experimenting to see if it would even grab values from my abstract class. I just need to figure out how to put values into a Checking and Savings array.



I used "Account" instead of bank. Why? I don't even know that.



Checking:


Savings


Signed,
William
6 years ago

Bear Bibeault wrote:What kind of errors are you talking about? If you mean data entry errors then those are not the type that you'd handle with exceptions, but with normal program control flow.

Basically, integer input errors. Let's say the method asks for an integer such as, "Type in a number: " and the user accidentally hits, "5t." An error would then throw and then clear the data to have the user try again.

Campbell Ritchie wrote:Welcome to the Ranch! Have you studied the methods of the well‑known Scanner class? If you use them correctly you can avoid using Exceptions at all.



I have not actually. Thanks for that info! I'll see what I can use.
6 years ago
Hello forum! My name is Will and I'm super new to Java. I'm trying to create a program that won't let a user enter in a letter or double value in a do-while loop that is focused on gathering integer data. I want to make it so if an error occurs, there will be a catch, clear, and then have the user retry entering in data. How do I setup a try-catch statement that will stop errors, clear them, and have the user enter in new data?
6 years ago