Results 1 to 4 of 4
  1. #1
    llowe29 is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default OOPAnnualFuelUse

    My problem is retieving info from the aFUT arrayer in the tester class so I can print to output. I get an incompatible types error.
    here is the code.
    Java Code:
     class AnnualFuelUse
    {
        // instance variables - replace the example below with your own
        private int day, sMiles, eMiles, dist;
        private double gUsed, mpg, ppg, cost;
        /**
         * Constructor for objects of class AnnualFuelUse
         */
        public AnnualFuelUse(int dy,int sM,int eM,double gU, double pPg)
        {
            // initialise instance variables
           day = dy;
           sMiles = sM;
           eMiles = eM;
           gUsed = gU;
           dist = 0;
           ppg = pPg ;
           mpg = 0.0;
           cost = 0.0;
        }
        public void calcDistance()
        {
            dist = eMiles - sMiles;
        }
        public int getDistance()
        {
            // put your code here
            return dist;
        }
        public void calcMPG()
        {
            // put your code here
            mpg = ((dist)/(gUsed));
        }
        public double getMPG()
        {
            // put your code here
            return mpg;
        }
        public void calcCosts()
        {
            cost = (mpg * ppg);
        }
        public double getCost()
        {
            return cost;
        }
    }
    Java Code:
    public class AnnualFuelUseTester
    {
       public static void main (String[] Args)
       {
           AnnualFuelUse[] aFUT = { new AnnualFuelUse(1, 45023, 45231, 10.00, 2.95), 
                                           new AnnualFuelUse(4, 45231, 45480, 11.70, 2.99),  
                                           new AnnualFuelUse(8, 45480, 45659, 9.30, 2.99)
                                  };
           
           double [] mpg = new double[3];
           double [] cost = new double[3];
           double [] distance = new double[3]; 
           for(int i = 0; i < distance.length; i++)
              {
               aFUT[i].calcDistance();
               distance[i] = aFUT[i].getDistance();
              }
           for(int i = 0; i < mpg.length; i++)
              {
               aFUT[i].calcMPG();
               mpg[i] = aFUT[i].getMPG();
              }
           for( int i = 0; i < cost.length; i++) 
             { 
              aFUT[i].calcCosts();
              cost[i] = aFUT[i].getCost(); 
             }
           double max = Double.MIN_VALUE;
           double min = Double.MAX_VALUE;
           for(int i = 0; i < 3; i++)
               {
               if( distance[i]> max)
                   max = distance[i];
               }
           for(int i = 0; i < 3; i++)
               {
                if( distance[i]< min)
                    min = distance[i];
               }
           double max1 = Double.MIN_VALUE;
           double min1 = Double.MAX_VALUE;
           for(int i = 0; i < 3; i++)
              { 
               if( mpg[i]> max1)
                   max1 = mpg[i];
              }
           for(int i = 0; i < 3; i++)
               {
               if( mpg[i] < min1)
                   min1 = mpg[i] ;
               }
           double max2 = Double.MIN_VALUE;
           double min2 = Double.MAX_VALUE;
           for(int i = 0; i < 3; i++)
              { 
               if( cost[i]> max2)
                   max2 = cost[i];
              }
           for(int i = 0; i < 3; i++)
               {
               if( cost[i] < min2)
                   min2 = cost[i] ;
               }
           double mpgS = 0;
           double costS = 0;
           double distanceS = 0;
           for(int i = 0; i < 3; i++)
               {
                mpgS += mpg[i];
                costS += cost[i];
                distanceS += distance[i];
               }
           double mpgA =  mpgS/3;   
           double costA =  costS/3;
           double distanceA = ((double)distanceS)/3;
           System.out.println("Fill Up  Days  Start Miles  End Miles  Distance  Gallons Used  MPG  Price  Cost ");
           int [] sMi = new int[3];
           int [] eMi = new int[3];
           double [] galU = new double[3];
           double [] pri = new double[3];
           int [] fillup = {1,2,3};
           int [] day = new int[3];
          for(int i = 0; i < 3; i++)
              day[i] = aFUT[0];
              sMi[i] = aFUT[i];
              eMi[i] = aFUT[i];
             galU[i] = aFUT[i];
              pri[i] = aFUT[i];
              
          for(int i = 0; i < 3; i++)
             {
              System.out.printf("%4s%7s%11d%11d%10d%13.2f%8d%6.2f%6.2f%n",fillup[i], day[i] , sMi[i], eMi[i], distance[i], galU[i], mpg[i],
                                 pri[i], cost[i]);     
             }
       }
    }

  2. #2
    llowe29 is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Re: OOPAnnualFuelUse

    help help please someone
    I am starting to wonder would I have to use getter methods.
    Last edited by llowe29; 08-02-2013 at 08:36 PM.

  3. #3
    llowe29 is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Re: OOPAnnualFuelUse

    Help please.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,953
    Rep Power
    19

    Default Re: OOPAnnualFuelUse

    What is the full error text and highlight the line it occurs on.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •