Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+17 votes

Why we need to use string for getInterger method ?

asked in CSC211_Winter2018 by (8 points)

3 Answers

+11 votes

What is program 3? Is it for Practiceit

answered by (8 points)
+3

it is the program due tomorrow. The one which we have to compare two saving scenarios and print a nicely formatted chart showing the amount deposited and total amount in
the account at the end of each year.
Thank you

+3

You mean the lab.

+3

Yeah, so why do we need to put string for the getInterger method?

+11 votes

First, this is the programming assignment for Mueller's class (not a lab).

When you write the getInteger method, you are writing a general purpose method that will only be call once in this program, but we might use in another program.

The parameter which is a String is to allow the user to pass the prompt for the input to the method. That way if we were to use the method again with a different prompt, we would just change the actual parameter passed to the method, rather than the code within the method itself.

The idea is that in the main method you will call the getInteger method and store it's return value in a statement like this (though your variable names may be different).

int numYears = getInteger(console, "Number of years: ");

Similarly, you will write a getDouble method which you will call four times. One of those calls might look something like this:

double annualRate1 = getDouble(console, "Yearly interest rate: ");

answered by (8k points)
+2 votes

you pass in a string

answered by (8 points)
...