Image

Imageomegatetris wrote in Imagejava_dev 😡annoyed

I'm in an intro programming class that uses Java to teach. I've created a class (paper.class) that takes two variables, sets the longer as the length and the shorter as the width, and then returns them in other methods. They also want me to make a test harness which will test these for every combination of dimensions from .5 to 20 (increments of .25). I can do it for one combination and while one changes and the other remains constant, but I can't figure out how to put in another loop properly to go through the full range of combinations. The problem seems to be in resetting the length when the width advances. I've been trying to do this for six hours.




public class PaperHarness {
  
    public static void main(String[] args) {
        
        // Initializes the success/failure counters
        int paperSuccesses = 0;
        int paperFailures = 0;
        // Variables for loops and starting values for tests
        double currentPaperLength = .5;
        double currentPaperWidth = .5;
        
        while (currentPaperWidth < 3) {
            
            while (currentPaperLength < 3) {
                Paper a = new Paper(currentPaperLength, currentPaperWidth);
                if (currentPaperLength != a.getLength()) {
                    System.out.println("Error measuring paper length at length " + currentPaperLength + " and width " + currentPaperWidth);
                    paperFailures++;
                    currentPaperLength = currentPaperLength + .25;
                }
                else {
                    if (currentPaperWidth != a.getWidth()) {
                        System.out.println("Error measuring paper width at length " + currentPaperLength + " and width " + currentPaperWidth);
                        paperFailures++;
                        currentPaperLength = currentPaperLength + .25;
                    }
                    else {
                        paperSuccesses++;
                        currentPaperLength = currentPaperLength + .25;
                        
                    }
                }
            }
            currentPaperWidth = currentPaperWidth + .25;
            System.out.println("Width is now " + currentPaperWidth);
            currentPaperLength = 0.5;
        }
        
        System.out.println("Paper tests succeeded " + paperSuccesses + " time(s) and failed " + paperFailures + " time(s).");
}





The "lt" things are less-than signs, I don't know why they didn't show up properly within the xmp tags. I'm sure the problem with my code is trivial... I'm not very good at making loops anyway.