Jump to content

Here is a link to roughly what it should look like in the end: http://www.leveluplunch.com/java/exercises/parking-ticket-simulator-program/

Since im still pretty new to java refrain from using things like "super();" because i really dont know what they do.

 

I need help with "public ParkingTicket patrol" in the PoliceOfficer class, there needs to be some sort of if statement to test to see if it should give them a ticket or not. Also i need help with "public void calculateFine() {" in the ParkingTicket class, although that one might be fine, i just can test it out until i fix the first problem. 

 

here is the template i was given and there are also some UML diagrams in there. https://portal.itas.ca/mod/resource/view.php?id=24816

 

 

 

 

Problem one is in here. This is the "if" statement part:

 

public class PoliceOfficer
{
    private String name;
    private String badgeNumber;
    
    public PoliceOfficer(String name, String badgeNumber) {
        this.name = name;
        this.badgeNumber = badgeNumber;
    }
    
    public PoliceOfficer(PoliceOfficer officer2) {
        name = officer2.name;
        badgeNumber = officer2.badgeNumber;
    }
    
    public ParkingTicket patrol(ParkedCar car, ParkingMeter meter) {
        return This is the method 
    }
}
 
 
And hopefully this should work
 
 
public class ParkingTicket
{
    private ParkedCar car;
    private PoliceOfficer officer;
    private double fine;
    private int minutes;
    
    public double BASE_FINE = 25.0;
    public double HOURLY_FINE = 10.0;
    
    public ParkingTicket (ParkedCar car, PoliceOfficer officer, int minutes) {
        this.car = car;
        this.officer = officer;
        this.minutes = minutes;
    }
    
    public ParkingTicket (ParkingTicket ticket2) {
        car = ticket2.car;
        officer = ticket2.officer;
        minutes = ticket2.minutes;
    }
    
    public void calculateFine() {                                   //this is a different if statement then above (should/might work)
        double hours = minutes / 60.0;
        int hoursAsInt = (int) hours;
 
        if ((hours - hoursAsInt) > 0) {
            hoursAsInt++;
        }
 
        // Assign the base fine.
        fine = BASE_FINE;
 
        // Add the additional hourly fines.
        fine += (hoursAsInt * HOURLY_FINE); 
    }
    
    public String toString() {
        return ("Ticket summary:/n" + "Vehical parked Illegally for: " + minutes + " minutes./n" + "Fine: $" + fine);
    }

My Car: http://linustechtips.com/main/topic/274320-the-long-awaited-car-thread/?p=4442206


CPU: i5 4590 |Motherboard: ASRock H97M PRO4|Memory: Corsair Vengance 8gbs|Storage: WD Caviar Blue 1TB|GPU: ZOTAC GTX 760 2gb|PSU: Thermaltech TR2 500W|Monitors: LG24M35 24" & Dual 19"|Mouse:Razer DeathAdder 2013 with SteelSeries Qck mini|Keyboard: Ducky DK2087 Zero MX Red|Headset: HyperX Cloud|Cooling: Corsair 120mm blue LED, Lepa vortex 120mm, stock 120mm|Case:Enermax Ostrog Blue Windowed


 

Link to comment
https://linustechtips.com/topic/471836-parking-ticket-simulator-program-in-java/
Share on other sites

Link to post
Share on other sites

 

Please use code tags. You can add them in by using the <> icon above where you type your posts, or with your text like so

[code]Code goes here[/code]

 

Yeah totally obvious place as well... put some effort in:

 

PZ20Fqo.png

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites

I'm guessing no one has looked at this so far because your post seemed like it would take an intimidatingly large amount of time to read. It didn't. 

 

Why would a police officer write a parking ticket in real life? Ifparked car has been parked for longer than specified by the parking meter. There's the logic for your if-statement.

 

ParkedCar and ParkingMeter objects are passed to your #patrol method. According to the leveluplunch website you linked, ParkedCar has the integer minutesParked, and ParkingMeter has the integer minutesPurchased. These integers match up perfectly with the logic I proposed for your if-statement; find a way to use them.

Link to post
Share on other sites

I'm guessing no one has looked at this so far because your post seemed like it would take an intimidatingly large amount of time to read.

Lol not in the slightest. Solving/hand holding on this is trivial. I at least just don't bother when people throw up their code all over the page with zero effort and leave it like that even when asked to sort it out.

It distills down to a simple reciprocation of effort.

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites

Lol not in the slightest. Solving/hand holding on this is trivial. I at least just don't bother when people throw up their code all over the page with zero effort and leave it like that even when asked to sort it out.

It distills down to a simple reciprocation of effort.

I now agree. This could be solved by anyone who's only been programming for two to three weeks. Not adding the code tags, not responding to you, and not checking back on the thread shows a lack of dedication to his question. 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×