nus-cs2113-AY2223S2 / forum

10 stars 0 forks source link

Coursemology Week 4 Qn 3 #16

Open avielcx opened 1 year ago

avielcx commented 1 year ago

Hi Prof

I have the same output as the sample test case on my terminal but it stills shows wrong answer on coursemology. Appreciate your help.

irving11119 commented 1 year ago

Did you update the Circle and Rectangle classes? The code for the two classes in coursemology are not by default the code provided for them in the question.

avielcx commented 1 year ago

@irving11119 yea, I copied and pasted from the notes. It passed the verify test case and failed the other.

tangphi commented 1 year ago

I think I have the same problem where it is failing the Main.main(args), but passing the Main.main(args)(Verify)

woowenjun99 commented 1 year ago

Is it possible to send the code here as some of us did not encounter this issue, and thus difficult to debug

tangphi commented 1 year ago

public class Main { //TODO add your methods here

private static Shape[] shapes = new Shape[100];

private static int shapeCount = 0;

public static void addShape(Shape s){
    shapes[shapeCount] = s;
    shapeCount++;
}

public static void printAreas() {
    for (int i = 0; i < shapeCount; i++) {
        System.out.println(shapes[i].area() + "\n");
    }
}

public static void main(String[] args) {
    addShape(new Circle(5));
    addShape(new Rectangle(3, 4));
    addShape(new Circle(10));
    printAreas();
    addShape(new Rectangle(4, 4));
    printAreas();
}

}

woowenjun99 commented 1 year ago

Try removing additional \n in the println in printArea?

joulev commented 1 year ago

Off topic but @tangphi FYI you can format code using code fences ``` like this

```java
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}
```

giving the output

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}
tangphi commented 1 year ago

Thanks deleting the \n worked!