2 Replies - 462 Views - Last Post: 11 May 2011 - 09:36 AM Rate Topic: -----

#1 Raven 1129  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 11-April 11

Else Without If Error

Posted 11 May 2011 - 08:29 AM

This is the error code I am getting and I dont understand why. BikeTripAnalyzer.java:36: 'else' without 'if'
else


import java.util.Scanner;

//This program is used to evaluate 2 different bike trips

public class BikeTripAnalyzer

{
	//instance variable

	private double trip = 0;
	private double trip2 = 0;
	private int distanceTraveled = 0;

	//Constructor

		public BikeTripAnalyzer (int initTrip, int initTrip2)
		{
		trip = initTrip;
		trip2 = initTrip2;

		}
			Scanner in = new Scanner (System.in);

		public void displayDistance (boolean status);

		{
		if  (status);

		{
			trip++;
		}
		else
			{
			trip2++;
	}
}
		public void displayDistanceTraveled ();
		{
			if ( trip < 10 )
				System.out.println ( " Very relaxing bike trip. " );
			else if ( trip <= 50)
				System.out.println ( " Relaxing bike trip. " );
			else if ( trip <= 80)
				System.out.println ( " Good bike trip. " );
			else if ( trip <= 150)
				System.out.println ( " Tiring bike trip.  " );
			else if ( trip <= 275)
				System.out.println ( " Professional bike trip. " );
			else if ( trip>= 275)
				System.out.println ( " Insane bike trip. " );
}
		}

This post has been edited by macosxnerd101: 11 May 2011 - 09:18 AM
Reason for edit:: Title renamed to be more descriptive


Is This A Good Question/Topic? 0
  • +

Replies To: Else Without If Error

#2 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Else Without If Error

Posted 11 May 2011 - 08:39 AM

here:
if  (status);

you have unnecessary semi colon.
remove them.
Was This Post Helpful? 1
  • +
  • -

#3 sakshamkum  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 19
  • View blog
  • Posts: 232
  • Joined: 09-June 09

Re: Else Without If Error

Posted 11 May 2011 - 09:36 AM

the semi-colon causes your if to terminate before it could run any condition.
your block causes problem after that statement.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1