I am ready to submit an assignment for my programming fundamentals class (intro class to Java 1) and the use of methods is extra credit for each assignment, so I have completed the assignment but was needing help converting the code to use methods. The instructor says no less than 6 methods should be used (which is where I get lost) and each calculation needs to be in its own method. Anyways, any some help would be appreciated... (the class uses only psudocode)
Question: Create the logic for a program that continuously prompts the user for a number of dollars until the user enters 0. Pass each entered amount to a conversion method that displays a breakdown of the passed amount into the fewest bills; in other words, the method calculates the number of 20s, 10s, 5s, and 1s needed.
My current (psudo)Code:
start
Declarations
num dollars
dollars = inputDollarAmt()
while dollars not equal to 0
dollarConversion(dollars)
dollars = inputDollarAmt()
endwhile
stop
num inputDollarAmt()
Declarations
num dollars
num QUIT = 0
output “Enter a dollar amount or ”, QUIT, “ to quit”
input dollars
return dollars
void dollarConversion(num dolls)
Declarations
num twenties
num tens
num fives
num ones
twenties = dolls / 20
dolls = dolls % 20
tens = dolls / 10
dolls = dolls % 10
fives = dolls / 5
dolls = dolls % 5
ones = dolls
output “You will need: ”, twenties, “ 20s, ”, tens, “ 10s, ”, fives, “ 5s, and ”, ones, “ 1s”
return
Question
ghostprodigy333
I am ready to submit an assignment for my programming fundamentals class (intro class to Java 1) and the use of methods is extra credit for each assignment, so I have completed the assignment but was needing help converting the code to use methods. The instructor says no less than 6 methods should be used (which is where I get lost) and each calculation needs to be in its own method. Anyways, any some help would be appreciated... (the class uses only psudocode)
Question: Create the logic for a program that continuously prompts the user for a number of dollars until the user enters 0. Pass each entered amount to a conversion method that displays a breakdown of the passed amount into the fewest bills; in other words, the method calculates the number of 20s, 10s, 5s, and 1s needed.
My current (psudo)Code:
Link to comment
https://www.neowin.net/forum/topic/1315002-converting-to-methods/Share on other sites
3 answers to this question
Recommended Posts