so i'm doing a problem for programming fundamentals 1 where they're teaching methods in java using a pretty simple problem that validates a credit card number using the sum of even and odd digits (this is slightly more complicated than what i'm describing but it functions in my code so i don't care)/the size of the card/the prefix of the card. the book dictates what function headers you're supposed to use, and i'm confused why the headers for the prefix are set up in this way:
public static boolean prefixMatched(long number, int d)
public static long getPrefix(long number, int k)
valid prefixes are 37, 4, 5, and 6. i wrote the program making k a constant equal to 2, and always spitting out a 2 digit number (even though the book assumes k can change, there's never any input for it. i wrote the code to make the prefix spit out properly if k changed anyway). if you do it like i described, you get a 2 digit number, and can either check if it's 37 or lop the last number off to see if it's 4, 5, or 6, so i used prefixMatched to determine if the result of getPrefix is one of the valid prefixes, confused as to why it passes down the original card number. i e-mailed the teacher about it, and she said that prefixMatched checks if d is a valid prefix of the card number - so if the card number is 4160xxxxxxxxxxxxxxx and your prefix is 41, it spits out true, but if the prefix were 40, it's false. why is this even needed if getPrefix generates the prefix? is it just a defensive coding thing?
update: teacher e-mailed me back and said it's suboptimal and supposed to teach you things - i assume that you can call the size function and getPrefix inside prefixMatched to test whether or not the prefix exists or w/e.