Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Parking Ticket Simulator Help (Almost done, few errors)

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Parking Ticket Simulator Help (Almost done, few errors)

    Hello. I am fairly new to programming, and this new assignment has pushed me to my limits. I am almost done with it, I think, but I am doing something incorrect because I can't seem to get rid of all of my errors at the same time. Any help is appreciated. Thank you very much:

    Design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes to design are:

    - ParkedCar class: simulates a parked car
    - This class knows the car's make, model, color, license number, and the number of minutes that the car has been parked.

    - ParkingMeter Class: simulates a parking meter.
    - This classes only responsibility is to know the number of minutes of parking time that has been purchased.

    -ParkingTicket class: Simulates a parking ticket
    Responsibilities:
    - To report make, model, color, and license number of the illegally parked car.
    - To report the amount of the fine which is $25 dollars for the first hour or part of the hour that the car is illegally parked, plus $10 for every additional hour or part of an hour that the car is parked.
    - To report the name and badge number of the police officer issuing the ticket.
    -PoliceOfficer class: Simulates a police officer
    Responsibilities:
    - To know the police officer's name and badge number
    - To examine a parked car object and a ParkingMeter object and determine whether the car's time has expired.
    - To issue a parking ticket (generate a parkingTicket object) if the car's time has expired.

    Write a program to test the classes as well.

    Here is what I have for my classes:

    public class ParkedCar {
     
    	private String make;
    	private String model;
    	private String color;
    	private String license;
    	private static int minutes;
     
    	public ParkedCar() {
     
    	}
     
    	public ParkedCar(String carMake, String carModel, String carColor, String carLicense, int carMinutes) {
     
    		make = carMake;
    		model = carModel;
    		color = carColor;
    		license = carLicense;
    		minutes = carMinutes;
    	}
     
    	public String getMake() {
    		return make;
    	}
    	public String getModel() {
    		return model;
    	}
    	public String getColor() {
    		return color;
    	}
    	public String getLicense() {
    		return license;
    	}
    	public static int getMinutes() {
    		return minutes;
    	}
     
    	public String toString() {
     
    		String string = "Make: " + make
    				+ "\nModel: " + model
    				+ "\nColor: " + color
    				+ "\nLicense Plate: " + license;
    			return string;
     
    	}
     
     
    }

    public class ParkingMeter {
     
    	private static int minPurchased;
     
    	public ParkingMeter() {
     
    	}
     
    	public ParkingMeter(int carMinPurchased) {
     
    		minPurchased = carMinPurchased;
    	}
     
    	public static int getMinPurchased() {
    		return minPurchased;
    	}
     
    	public String toString() {
    		String string = "Minutes Purchased: " + minPurchased;
    		return string;
    	}
    }

    public class ParkingTicket {
     
    		private ParkedCar vehicle;
    		private PoliceOfficer copster;
    		private double fine;
    		private int minutes;
    		private double firstFine = 25;
    		private double moreFine = 10;
     
    		public ParkingTicket(ParkedCar car, PoliceOfficer cop, double guyFine, int mins) {
     
    			vehicle = car;
    			copster = cop;
    			fine = guyFine;
    			minutes = mins;
    		}
     
    		public void getTotalFine() {
    			int  time = ParkedCar.getMinutes() - ParkingMeter.getMinPurchased();
     
    			if(time <= 60) {
    				fine = firstFine;
    			}
    			else {
    				fine = firstFine + moreFine * (time / 60);
    			}
    		}
     
    		public double getFirstFine() {
    			return firstFine;
    		}
    		public double getMoreFine() {
    			return moreFine;
    		}
    		public ParkedCar getVehicle() {
    			return vehicle;
    		}
    		public PoliceOfficer getCopster() {
    			return copster;
    		}
    		public int getMinutes() {
    			return minutes;
    		}
    		public double getFine() {
    			return fine;
    		}
     
     
    	}

    public class PoliceOfficer {
     
    	private String name;
    	private int badge;
    	private static double ticket;
     
    	public PoliceOfficer() {
     
    	}
     
    	public PoliceOfficer(String poName, int poBadge) {
     
    		name = poName;
    		badge = poBadge;
    	}
     
    	public String getName() {
    		return name;
    	}
    	public int getBadge() {
    		return badge;
    	}
     
    	static ParkingTicket search(ParkedCar car, ParkingMeter meter) {
     
    		int  time = ParkedCar.getMinutes() - ParkingMeter.getMinPurchased();
     
    		if(ParkedCar.getMinutes() > ParkingMeter.getMinPurchased()) {
    			if(time <= 60) {
    				ticket = 25;
     
    			}
     
    		else {
    			ticket = 25 + (10 * (time/60));
    		}
    		}
    		return ticket;
     
    	}
     
    }

    public class CarTest {
     
    	public static void main(String[] args) {
     
    		ParkedCar car = new ParkedCar("Honda", "Accord", "Black", "452-BTS", 78);
     
    		ParkingMeter meter = new ParkingMeter(60);
     
    		PoliceOfficer john = new PoliceOfficer("John Doe", 1337);
     
    		ParkingTicket ticket = PoliceOfficer.search(car, meter);
     
    		if(ticket != null) {
    			System.out.println(ticket);
    		}
    		else {
    			System.out.println("Car is not doing anything wrong!");
    		}
    	}
     
    }

    In this code, the only problem is "return ticket;" in the PoliceOfficer class. However, even if I got rid of that, I still don't know if my code would work... . Any help is appreciated. Thank you so much in advanced.

    -TitanVex


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Parking Ticket Simulator Help (Almost done, few errors)

    I'm not sure what you want us to do. If you want us to test your code and see if it adheres to the specs then that is unlikely to happen. If you have a specific question then ask it and get a specific answer. If you are getting error messages then post the exact messages and indicate on which line they occur (show the line don't just say line number X)
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Parking Ticket Simulator Help (Almost done, few errors)

    Quote Originally Posted by Junky View Post
    I'm not sure what you want us to do. If you want us to test your code and see if it adheres to the specs then that is unlikely to happen. If you have a specific question then ask it and get a specific answer. If you are getting error messages then post the exact messages and indicate on which line they occur (show the line don't just say line number X)
    I get an error in the PoliceOfficer class. It would be in this part:
    	static ParkingTicket search(ParkedCar car, ParkingMeter meter) {
     
    		int  time = ParkedCar.getMinutes() - ParkingMeter.getMinPurchased();
     
    		if(ParkedCar.getMinutes() > ParkingMeter.getMinPurchased()) {
    			if(time <= 60) {
    				ticket = 25;
     
    			}
     
    		else {
    			ticket = 25 + (10 * (time/60));
    		}
    		}
    		return ticket;
     
    	}

    The word 'ticket' is red underlined and I don't know how to fix that. I have tried java's default methods, such as changing the method return type to double and changing type of 'ticket.' By no means do I want you guys to test to see if my code works. I just want to make it run so that I can make the necessary adjustments. Thanks for you help thus far.
    -TitanVex

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Parking Ticket Simulator Help (Almost done, few errors)

    In future you need to copy and paste the exact error message. In your case ticket is a double but the method says it should return a ParkingTicket.
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Parking Ticket Simulator Help (Almost done, few errors)

    Quote Originally Posted by Junky View Post
    In future you need to copy and paste the exact error message. In your case ticket is a double but the method says it should return a ParkingTicket.
    Allrighty. Will do. Thanks.

  6. #6
    Junior Member
    Join Date
    Nov 2011
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Parking Ticket Simulator Help (Almost done, few errors)

    Nevermind! I solved it! Thanks anyway!
    Last edited by TitanVex; November 16th, 2011 at 10:44 AM. Reason: solved the problem

  7. #7
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Parking Ticket Simulator Help (Almost done, few errors)

    i got the same problem with the PoliceOfiicer class as same as the problem u got.
    could u tell me how to solve the problem? its call incompatible types
    found : int about ticket

    thank u so much!!!!

  8. #8
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Parking Ticket Simulator Help (Almost done, few errors)

    What did you not understand about my previous explanation?

    You have a method that says it will return something of a certain type and yet your code is attempting to return something of a different type.
    Improving the world one idiot at a time!

Similar Threads

  1. bingo ticket loop problem (doesn't compile like it should...)
    By mv740 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 14th, 2011, 04:21 PM
  2. lotto ticket generator help
    By tlckl3m3elmo in forum What's Wrong With My Code?
    Replies: 19
    Last Post: July 15th, 2011, 12:39 AM
  3. Laugh parking garage
    By madhusanka in forum What's Wrong With My Code?
    Replies: 16
    Last Post: April 20th, 2011, 09:21 AM
  4. Parking Lot Program help!
    By soul.salem in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 23rd, 2011, 10:35 PM
  5. JAVA simulator
    By YAS218 in forum Java Theory & Questions
    Replies: 8
    Last Post: July 20th, 2009, 09:57 AM