Closed zhengster closed 2 years ago
@Mick609 @shivin9 please take a look and help @zhenster with the coursemology exercise.
@zhenster can you share how you are writing the print statement?
Sure - here are my print statements. (The helper methods extractPrices() and calculateTotal() do not return any new line characters; all the newline characters are from the "System.out.println" calls).
public static void main(String[] args) {
String line;
Scanner in = new Scanner(System.in);
System.out.print("Your expenses while overseas?");
String expenses = extractPrices(in.nextLine());
System.out.println("Expenses in overseas currency: " + expenses);
System.out.println("Total in local currency: " + calculateTotal(expenses));
}
Thanks for your help!
Try changing ...println -> ...print
. It seems that there is no \n
in the expected output.
If I try changing from println to print, then the formatting is fixed for the second input but is incorrect for the first. I suppose I could hard-code it so that the formatting is dependent on the input, but I think that might be frowned upon. 😂 Perhaps there is an issue with the test cases themselves?
You need to remove the space at the end of "Expenses in overseas currency: " and avoid println for both. My code looks like yours but with those two changes it manages to pass both test cases.
edit: "Total in local currency: " should retain the space at the end though.
That worked, thank you!
I'm trying to match the formatting of my code output to the problem description. As seen from the description, there seems to be a line break after every line printed in the output (i.e. new lines to begin "Your expenses while overseas," "Expenses in overseas currency," and "Total in local currency"). However, this is not reflected in the Coursemology expected output. For the second input, the expected output does not have a new line to begin the "Total in local currency" line. So, which format should we be adhering to: Coursemology's or the CS2113 website's? Also, I'm not sure why my result for the first input is being marked as incorrect... Thanks!