lundi 29 juin 2015

I can't figure out why my program isn't looping

I am trying to make this file loop. But I keep getting an error on at the last if statement (Marked by an arrow). The program is supposed to read in a file with the first line being the name of the customer. On the second line, the first number is the amount of trees to be removed(150 per tree), the second number is tree trimming to be done(50 an hour). The third line are all the stumps to be removed and their diameter(one number is one stump and also it's diameter). Thanks for the help.

This is the file that is supposed to be read in (http://ift.tt/1Jtso6r).

public class Prog_5 {

    public static void main(String[] args) throws FileNotFoundException {
        String name = "Joe";
        double trees = 0;
        double treeTrimming = 0;
        double stumpInches = 0;
        double stumpTotal = 0;
        double total = 0;
        double totalRev = 0;

        Scanner in = new Scanner(System.in);
        System.out.print("Input file: ");
        String inputFile = in.nextLine();

        System.out.print("Output file: ");
        String outputFile = in.nextLine();
        in.close();

        File input = new File(inputFile);
        in = new Scanner(input);
        PrintWriter output = new PrintWriter(outputFile);

        while(in.hasNext()){

        name = in.nextLine();
        output.println("Customer: " + name);
        System.out.println("Customer: " + name);

        trees = in.nextDouble();
        trees *= 150;
        output.println("Tree Removal: $" + trees);
        System.out.println("Tree Removal: $" + trees);

        treeTrimming = in.nextDouble();
        treeTrimming *= 50;
        output.println("Tree Trimming: $" + treeTrimming);
        System.out.println("Tree Trimming: $" + treeTrimming);

        while (in.hasNextDouble()) {
            stumpInches = in.nextDouble();
            if (stumpInches != -1) {
                stumpTotal = stumpTotal + 30;
                if (stumpInches > 12) {
                    stumpInches -= 12;
                    stumpInches *= 2;
                }
                stumpTotal += stumpInches;
            }

        }
        output.println("Stump Removal: $" + stumpTotal);
        System.out.println("Stump Removal: $" + stumpTotal);

        total = (trees + treeTrimming + stumpTotal);
        output.println("Total: $" + total);
        System.out.println("Total: $" + total);

        totalRev += total;
        stumpTotal = 0;
        trees = 0;
        treeTrimming = 0;

        if(in.hasNext());
            in.next();
        }

        output.close();

    }

}

Aucun commentaire:

Enregistrer un commentaire