Error: Missing return Statement

working for hours

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 2153 Views - Last Post: 01 October 2009 - 02:47 AM Rate Topic: -----

#1 ArcDarkSmurf  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 01-October 09

Error: Missing return Statement

Posted 01 October 2009 - 12:35 AM

/**
	This class simulates a parking ticket.
	Its responsibilities are report make, model,
	color, and license number of illegally parked
	car. It also reports the amount of the fine.
	Finally reports the name and badge number
	of the officer that issued the ticket.
*/
public class BenParkingTicket
{
	private BenParkedCar parkedCar;
	private BenPoliceOfficer officer;
	private BenParkingMeter minutesPurchased;
	private static int fineAmount;
	private final int ONE_HOUR = 60;
	
	public BenParkingTicket(BenParkedCar parkedCar, BenPoliceOfficer officer, int fineAmount)
	{
		this.parkedCar = parkedCar;
		this.officer = officer;
		this.fineAmount = fineAmount;
	}
		
	public int getFineAmount()
	{
		int fine = 0;
		
		if (parkedCar.getMinutesParked() <= minutesPurchased.getMinPurchased()){
			return fine;
		}else if (parkedCar.getMinutesParked() > minutesPurchased.getMinPurchased() && parkedCar.getMinutesParked() < minutesPurchased.getMinPurchased() + ONE_HOUR){
			fine = 25;
			return fine;
		}else if (parkedCar.getMinutesParked() > minutesPurchased.getMinPurchased() && parkedCar.getMinutesParked() > minutesPurchased.getMinPurchased() + ONE_HOUR){
			fine = 25 + (10 * (parkedCar.getMinutesParked() / ONE_HOUR));
		}
		return fine;
	}
}




I think I have been working on this now for about 3 hours. I cannot even think anymore! Any help on this topic would be SOO fantastic.

Thanks to whoever leaves a reply I really appreciate it!

** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: Error: Missing return Statement

#2 Kikinit  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 30-September 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 12:47 AM

Isn't the last return fine supposed to be inside the curly brackets above it.

EDIT: Doesn't make any difference. Sorry.

This post has been edited by Kikinit: 01 October 2009 - 12:48 AM

Was This Post Helpful? 0
  • +
  • -

#3 ArcDarkSmurf  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 01-October 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 12:49 AM

View PostKikinit, on 30 Sep, 2009 - 11:47 PM, said:

Isn't the last return fine supposed to be inside the curly brackets above it.

EDIT: Doesn't make any difference. Sorry.


Nope that didn't work :(
Was This Post Helpful? 0
  • +
  • -

#4 TyVeryMuch  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 33
  • Joined: 24-March 07

Re: Error: Missing return Statement

Posted 01 October 2009 - 01:03 AM

I do not see anything wrong with this code, could you post all class files so i can get a better look at it?
Was This Post Helpful? 0
  • +
  • -

#5 Kikinit  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 30-September 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 01:04 AM

View PostArcDarkSmurf, on 30 Sep, 2009 - 11:49 PM, said:

View PostKikinit, on 30 Sep, 2009 - 11:47 PM, said:

Isn't the last return fine supposed to be inside the curly brackets above it.

EDIT: Doesn't make any difference. Sorry.


Nope that didn't work :(


What is actually wrong with the code. Is it returning the wrong fine?
Was This Post Helpful? 0
  • +
  • -

#6 ArcDarkSmurf  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 01-October 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 01:07 AM

View PostKikinit, on 1 Oct, 2009 - 12:04 AM, said:

View PostArcDarkSmurf, on 30 Sep, 2009 - 11:49 PM, said:

View PostKikinit, on 30 Sep, 2009 - 11:47 PM, said:

Isn't the last return fine supposed to be inside the curly brackets above it.

EDIT: Doesn't make any difference. Sorry.


Nope that didn't work :(


What is actually wrong with the code. Is it returning the wrong fine?


No I cant even get it to compile... it says that its missing return statement

I am trying to call getFineAmount() in my class called BenPoliceOfficer, and that class is getting the exact same error

This post has been edited by ArcDarkSmurf: 01 October 2009 - 01:12 AM

Was This Post Helpful? 0
  • +
  • -

#7 ArcDarkSmurf  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 01-October 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 01:23 AM

/**
	This class simulates an Officer inspection.
	It will have badge number and name of officer.
	Also it Examines a ParkedCar and ParkingMeter.
	Will Determine if the car's time is expired.
*/
public class BenPoliceOfficer
{
	private int badgeNum;
	private String officerName;
	private BenPoliceOfficer officer;
	private BenParkedCar parkedCar;
	private BenParkingMeter minutesPurchased;
	private BenParkingTicket parkingTicket;
	
	// set police officer
	public BenPoliceOfficer(int badgeNum, String officerName)
	{
		this.badgeNum = badgeNum;
		this.officerName = officerName;
	}
	
	// compare minutes parked vs. purchased to see if should issue ticket
	public BenPoliceOfficer getParked()
	{
		if (parkedCar.getMinutesParked() <= minutesPurchased.getMinPurchased()){
			System.out.println("This car is parked legally.");
		}else if (parkedCar.getMinutesParked() > minutesPurchased.getMinPurchased()){
			System.out.println("This car is parked illegally!\nThe ticket amount is:\n" + parkingTicket.getFineAmount());
		}
	}
}



This is my other class this might help.

** Edit ** :code:
Was This Post Helpful? 0
  • +
  • -

#8 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Error: Missing return Statement

Posted 01 October 2009 - 01:24 AM

try this out
  public int getFineAmount()
	{
		int fine = 0;
	   
		if (parkedCar.getMinutesParked() <= minutesPurchased.getMinPurchased()){
			return fine;
		}else if (parkedCar.getMinutesParked() > minutesPurchased.getMinPurchased() && parkedCar.getMinutesParked() < minutesPurchased.getMinPurchased() + ONE_HOUR){
			fine = 25;
			return fine;
		}else 
			fine = 25 + (10 * (parkedCar.getMinutesParked() / ONE_HOUR));

		return fine;
	}
}


Was This Post Helpful? 0
  • +
  • -

#9 ArcDarkSmurf  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 01-October 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 01:30 AM

C:\Users\Ben\Desktop\School\Java II\Chapter9>javac BenParkingTicket.java
.\BenPoliceOfficer.java:31: missing return statement
}
^
1 error

So I guess it is in my BenPoliceOfficer Class

This post has been edited by ArcDarkSmurf: 01 October 2009 - 01:31 AM

Was This Post Helpful? 0
  • +
  • -

#10 Kikinit  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 30-September 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 01:45 AM

// compare minutes parked vs. purchased to see if should issue ticket
public BenPoliceOfficer getParked()
{
	 if (parkedCar.getMinutesParked() <= minutesPurchased.getMinPurchased()){
	 System.out.println("This car is parked legally.");
	 } else if (parkedCar.getMinutesParked() > minutesPurchased.getMinPurchased()) {
	 System.out.println("This car is parked illegally!\nThe ticket amount is:\n" + parkingTicket.getFineAmount());
}



This code is not returning anything. And if it is to return something, it should be a BenPoliceOffice object. You sure that is your intention?

This post has been edited by Kikinit: 01 October 2009 - 01:46 AM

Was This Post Helpful? 0
  • +
  • -

#11 AntonWebsters  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 88
  • View blog
  • Posts: 428
  • Joined: 15-August 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 01:46 AM

Quote

C:\Users\Ben\Desktop\School\Java II\Chapter9>javac BenParkingTicket.java
.\BenPoliceOfficer.java:31: missing return statement
}
^
1 error

So I guess it is in my BenPoliceOfficer Class

You didn't post your BenPoliceOfficer class..so we can't find out what that error is.
Was This Post Helpful? 0
  • +
  • -

#12 ArcDarkSmurf  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 01-October 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 01:49 AM

View PostKikinit, on 1 Oct, 2009 - 12:45 AM, said:

// compare minutes parked vs. purchased to see if should issue ticket
public BenPoliceOfficer getParked()
{
	 if (parkedCar.getMinutesParked() <= minutesPurchased.getMinPurchased()){
	 System.out.println("This car is parked legally.");
	 } else if (parkedCar.getMinutesParked() > minutesPurchased.getMinPurchased()) {
	 System.out.println("This car is parked illegally!\nThe ticket amount is:\n" + parkingTicket.getFineAmount());
}



This code is not returning anything. And if it is to return something, it should be a BenPoliceOffice object. You sure that is your intention?


Ya, I tried a return new BenPoliceOfficer(officer);
but that didnt work...
i posted my BenPoliceOfficer class up above.
Was This Post Helpful? 0
  • +
  • -

#13 ArcDarkSmurf  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 01-October 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 02:04 AM

I have the two other classes also.

/**
	This class demonstrates a Parking Meter.
	Its responsibility is to know the number
	of minutes purchased.
*/
public class BenParkingMeter
{
	private int minutesPurchased;
	
	public BenParkingMeter(int minutesPurchased)
	{
		this.minutesPurchased = minutesPurchased;
	}

	public BenParkingMeter(BenParkingMeter object2)
	{
		this.minutesPurchased = object2.minutesPurchased;
	}
	
	public int getMinPurchased()
	{
		return minutesPurchased;
	}
}

And....

/** 
	This class simulates a parked car.
	It knows make,model,color,license number and 
	number of minutes parked.
*/
public class BenParkedCar
{
	private String carMake;
	private String carModel;
	private String carColor;
	private String carLicense;
	private int minutesParked;
	
	public BenParkedCar(String carMake, String carModel, String carColor, String carLicense, int minutesParked)
	{
		this.carMake = carMake;
		this.carModel = carModel;
		this.carColor = carColor;
		this.carLicense = carLicense;
		this.minutesParked = minutesParked;
	}
	
	//makes a copy of the parked car constructor
	public BenParkedCar(BenParkedCar object2)
	{
		this.carMake = object2.carMake;
		this.carModel = object2.carModel;
		this.carColor = object2.carColor;
		this.carLicense = object2.carLicense;
		this.minutesParked = object2.minutesParked;
	}
	
	public String getCarMake()
	{
		return carMake;
	}
	public String getCarModel()
	{
		return carModel;
	}
	public String getCarColor()
	{
		return carColor;
	}
	public String getCarLicense()
	{
		return carLicense;
	}
	public int getMinutesParked()
	{
		return minutesParked;
	}
	public String toString()
	{
		// create a string describing the stock.
		String str = "Car Make: " + carMake + "\nCar Model: " + carModel + "\nCar Color: " + carColor + "\nCar License Number: " + carLicense + "\nMinutes Parked: " + minutesParked;
		
		//return the string
		return str;
	}
	
	public BenParkedCar copy()
	{
		BenParkedCar copyObject = new BenParkedCar(carMake, carModel, carColor, carLicense, minutesParked);
		return copyObject;
	}

}



** Edit ** :code:
Was This Post Helpful? 0
  • +
  • -

#14 Kikinit  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 30-September 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 02:34 AM

Quote

Ya, I tried a return new BenPoliceOfficer(officer);
but that didnt work...
i posted my BenPoliceOfficer class up above.


But the code is not returning anything at the moment. If you want to return nothing then change it to void.

If you want to return a BenPoliceOfficer object then maybe

BenPoliceOfficer bpo = new BenPoliceOfficer(badge, Officer);
return bpo;



Your call on BenPoliceOfficer you wrote in your reply did not have two parameters as the constructor did.

I couldn't see where this getParked() method is called in your code.

This post has been edited by Kikinit: 01 October 2009 - 02:34 AM

Was This Post Helpful? 0
  • +
  • -

#15 ArcDarkSmurf  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 01-October 09

Re: Error: Missing return Statement

Posted 01 October 2009 - 02:38 AM

So if i change it to void lets say... Will it still do the println commands then! Cause thats what i basically want it to do.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2