Please help need quick!!! Thanks

Please help need quick!!! Thanks

hey i keep getting stupid compile errors and don't understand why. i'm supposed to use abstract to test a boat race simulation program of sorts here is my code:

RentforthBoatRace.java

public abstract class RentforthBoatRace {

    public abstract double getSum();


}

testRentforthBoatRace.java

import java.util.Scanner;

public class TestRenforthBoatRace {

    public static void main(String args[]) {

    double lowest = getLowestWeight();

        RedBoat redboat = new RedBoat(makeTeam());
        GreenBoat greenboat = new GreenBoat(makeTeam());
        YellowBoat yellowboat = new YellowBoat(makeTeam());
        BlueBoat blueboat = new BlueBoat(makeTeam());
        OrangeBoat orangeboat = new OrangeBoat(makeTeam());

    System.out.println("The winner is " + lowest);

}
    public static double[] makeTeam(){

        Scanner input = new Scanner(System.in);

        double[] team = new double[10];

        for(int i = 0; i < team.length; i++){
            team[i] = input.nextDouble();
        }

        return team;
}

    public static double getLowestWeight(double[] array) {  

        double lowest;

            array[0] = redboat.getSum();
            array[1] = greenboat.getSum();
            array[2] = yellowboat.getSum();
            array[3] = blueboat.getSum();
            array[4] = orangeboat.getSum();

            for(int i = 1; i < array.length ; i++){  
                if(array[i] < lowest){  

                    lowest = array[i]; 
                }
            }
            return lowest;
    }


}

RedBoat.java

public class RedBoat extends RentforthBoatRace {

private double[] team1 = new double[10];

public RedBoat( double[] team1){

    for(int i = 0; i < team1.length; i++) {
        this.team1[i] = team1[i];
    }

}

public double getSum(){
    double sum = 0;

    for(int i = 0; i < team1.length; i++){
        sum = sum + team1[i];
    }

    return sum;

}
}

GreenBoat.java

public class GreenBoat extends RentforthBoatRace {

private double[] team1 = new double[10];

public GreenBoat( double[] team1){

    for(int i = 0; i < team1.length; i++) {
        this.team1[i] = team1[i];
    }

}

public double getSum(){
    double sum = 0;

    for(int i = 0; i < team1.length; i++){
        sum = sum + team1[i];
    }

    return sum;

}
}

YellowBoat.java

public class YellowBoat extends RentforthBoatRace {

private double[] team1 = new double[10];

    public YellowBoat( double[] team1){

    for(int i = 0; i < team1.length; i++) {
        this.team1[i] = team1[i];
    }

}

public double getSum(){

    double sum = 0;

    for(int i = 0; i < team1.length; i++){
        sum = sum + team1[i];
    }

    return sum;

}
}

BlueBoat.java

public class BlueBoat extends RentforthBoatRace {

double totalWeight4;

private double[] team1 = new double[10];

    public BlueBoat( double[] team1){

    for(int i = 0; i < team1.length; i++) {
        this.team1[i] = team1[i];
    }

}

public double getSum(){
    double sum = 0;

    for(int i = 0; i < team1.length; i++){
        sum = sum + team1[i];
    }

    return sum;

}
}

OrangeBoat.java

public class OrangeBoat extends RentforthBoatRace {

double[] team1 = new double[10];

    public OrangeBoat( double[] team1){

    for(int i = 0; i < team1.length; i++) {
        this.team1[i] = team1[i];
    }

}

public double getSum(){
    double sum = 0;

    for(int i = 0; i < team1.length; i++){
        sum = sum + team1[i];
    }

    return sum;

    }
}

compile errors:

TestRenforthBoatRace.java:7: getLowestWeight(double[]) in TestRenforthBoatRace cannot be applied to ()
    double lowest = getLowestWeight();
                    ^
TestRenforthBoatRace.java:35: cannot find symbol
symbol  : variable redboat
location: class TestRenforthBoatRace
            array[0] = redboat.getSum();
                       ^
TestRenforthBoatRace.java:36: cannot find symbol
symbol  : variable greenboat
location: class TestRenforthBoatRace
            array[1] = greenboat.getSum();
                       ^
TestRenforthBoatRace.java:37: cannot find symbol
symbol  : variable yellowboat
location: class TestRenforthBoatRace
            array[2] = yellowboat.getSum();
                       ^
TestRenforthBoatRace.java:38: cannot find symbol
symbol  : variable blueboat
location: class TestRenforthBoatRace
            array[3] = blueboat.getSum();
                       ^
TestRenforthBoatRace.java:39: cannot find symbol
symbol  : variable orangeboat
location: class TestRenforthBoatRace
            array[4] = orangeboat.getSum();
                       ^
6 errors

any help would be appreciated guys. Thanks so much

View Answers

June 14, 2011 at 5:15 PM

Hi Wayne Tuker

The first error at line number 7 is due to getLowestWeight() function is defined with arguments you can use it like this :

 double lowest = getLowestWeight(Some array of type double);

And rest of the error is because you haven't created object for redboat,yellowboat,greenboat, blueboat and orangeboat.

You need to create object for example for class redboat you must create object like this :

RedBoat redboat = new RedBoat();

After this you can use below statement :

array[0] = redboat.getSum();

And also you need to declare array before using it..









Related Tutorials/Questions & Answers:

Ads