nus-cs2113-AY2122S2 / forum

3 stars 2 forks source link

Possible inconsistent formatting for Coursemology Week 3 Question 10 #4

Closed zhengster closed 2 years ago

zhengster commented 2 years ago

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"). image 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... image Thanks!

okkhoy commented 2 years ago

@Mick609 @shivin9 please take a look and help @zhenster with the coursemology exercise.

shivin9 commented 2 years ago

@zhenster can you share how you are writing the print statement?

zhengster commented 2 years ago

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!

shivin9 commented 2 years ago

Try changing ...println -> ...print. It seems that there is no \n in the expected output.

zhengster commented 2 years ago

If I try changing from println to print, then the formatting is fixed for the second input but is incorrect for the first. image 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?

lithream commented 2 years ago

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.

zhengster commented 2 years ago

That worked, thank you!