0 votes
1 view
in Java by (120 points)

Truthfully i got myself all mixed up in my own code an idk how to fix and im lost

My output keeps saying 


Fined amount: 
Car issued to: 
Parking ticket #:null
Fined amount: 
Issued by officer:

and i need it to say 

Parking ticket #:
Fined amount:
Car issued to:
Issued by officer:

 

Code is 

package main;
import java.util.Scanner;
public class Main

  public static void main(String[] args)
   {

        String make, model, color, license, name, badge;

        int parkedMinutes, meterMinutes;

        Scanner keyboard = new Scanner(System.in);

        System.out.print("=== Parking Ticket Simulator ===\n\n");

        System.out.print("---------\n");

        System.out.print("Car Data\n");

        System.out.print("---------\n\n");

        System.out.print("Enter the car make: ");

        make = keyboard.nextLine();

        System.out.print("Enter the car model: ");

        model = keyboard.nextLine();

        System.out.print("Enter the car color: ");

        color = keyboard.nextLine();

        System.out.print("Enter the car license number: ");

        license = keyboard.nextLine();

        System.out.print("Enter minutes car has been parked:");

        parkedMinutes = keyboard.nextInt();

        System.out.print("\n----------\n");

        System.out.print("Meter Data\n");

        System.out.print("----------\n\n");

        System.out.print("Enter minutes purchased by driver:");

        meterMinutes = keyboard.nextInt();

        keyboard.nextLine();

        System.out.print("\n-------\n");

        System.out.print("PO Data\n");

        System.out.print("-------\n\n");

        System.out.println();

        System.out.print("Enter police officer's name:");

        name = keyboard.nextLine();

        System.out.print("Enter police officer's badge number:");

        badge = keyboard.nextLine();

        System.out.print("\n---------------------\n");

        System.out.print("Parking Ticket Issued\n");

        System.out.print("---------------------\n\n");

        ParkedCar car = new ParkedCar(make, model, color, license, parkedMinutes);

        ParkingMeter meter1 = new ParkingMeter(meterMinutes);

        PoliceOfficer officer1 = new PoliceOfficer(name, badge, car, meter1);

        System.out.println(officer1.getExpired(officer1));

    }

    public static class ParkedCar

    {

        private String make;

        private String model;

        private String color;

        private String license;

        private int minutesParked;

        public ParkedCar()

        {

            make = "";

            model = "";

            color = "";

            license = "";

            minutesParked = 0;

        }

        public ParkedCar(ParkedCar carDetails)

        {

            make = carDetails.make;

            model = carDetails.model;

            color = carDetails.color;

            license = carDetails.license;

            minutesParked = carDetails.minutesParked;

        }

        public ParkedCar(String make, String model, String color, String license, int minutesParked)

        {

            this.make = make;

            this.model = model;

            this.color = color;

            this.license = license;

            this.minutesParked = minutesParked;

        }

        public void setMake(String make)

        {

            this.make = make;

        }

        public void setModel(String model)

        {

            this.model = model;

        }

        public void setColor(String color)

        {

            this.color = color;

        }

        public void setLicense(String license)

        {

            this.license = license;

        }

        public void minutesParked(int minutesParked)

        {

            this.minutesParked = minutesParked;

        }

        public String getMake()

        {

            return make;

        }

        public String getModel()

        {

            return model;

        }

        public String getColor()

        {

            return color;

        }

        public String getLicense()

        {

            return license;

        }

        public int getMinutesParked()

        {

            return minutesParked;

        }

        public String toString()

        {

            //String str = "\nMake: " + make + "\nModel: " + model + "\nColor: " + color + "\nLicense: " + license + "\nMinutes parked: " + minutesParked;

            String str = "Car issued to: " + color + make + model + ", license #: " + license;

            return str;

        }

    }

    public static class ParkingMeter

    {

        private int minutes;

        public ParkingMeter()

        {

            minutes = 0;

        }

        public ParkingMeter(int minutes)

        {

            this.minutes = minutes;

        }

        public ParkingMeter(ParkingMeter minutesDetail)

        {

            minutes = minutesDetail.minutes;

        }

        public void setMinutes(int minutes)

        {

            this.minutes = minutes;

        }

        public int getMinutes()

        {

            return minutes;

        }

        public String toString()

        {

            String str = "\nMinutes: " + minutes;

            return str;

        }

    }

    public static class ParkingTicket

    {

        private PoliceOfficer officer;

        private ParkedCar car;

        private ParkingMeter meter;

        private int fees;

        public ParkingTicket(PoliceOfficer officer)

        {

            this.officer = new PoliceOfficer(officer);

            this.meter = officer.getMeter();

            this.car = officer.getParkedCar();

        }

        public ParkingTicket()

        {

        }

        public int fees()

        {

            int time;

            if (car != null || meter != null)

            {

                time = car.getMinutesParked() - meter.getMinutes() - 1;

                fees = 25;

                while (time > 0)

                {

                    time = time - 1;

                    fees = fees + 10;

                }

            }

            return fees;

        }

        public String toString()

        {

            if (fees() == 0)

            {

                String str = "There is no ticket issued.";

                return str;

            }

            else

            {

                //String str = "\n" + officer +"\nTime over: "  + (car.getMinutesParked() - meter.getMinutes()) + "\nThe fee is $" + fees();

                String str = "\nFined amount: $" + fees() + "\n" + car + "\n" + officer;

                return str;

            }

        }

    }

    public static class PoliceOfficer

    {

        private String name;

        private String badge;

        private ParkedCar car;

        private ParkingMeter meter;

        private ParkingTicket ticket;

        public PoliceOfficer(String name, String badge, ParkedCar carDetails, ParkingMeter time)

        {

            this.name = name;

            this.badge = badge;

            car = new ParkedCar(carDetails);

            meter = new ParkingMeter(time);

        }

        public PoliceOfficer(PoliceOfficer officerDetails)

        {

            name = officerDetails.name;

            badge = officerDetails.badge;

            car = officerDetails.car;

            meter = officerDetails.meter;

        }

        public void setName(String name)

        {

            this.name = name;

        }

        public void setBadge(String badge)

        {

            this.badge = badge;

        }

        public String getName()

        {

            return name;

        }

        public String getBadge()

        {

            return badge;

        }

        public ParkedCar getParkedCar()

        {

            return new ParkedCar(car);

        }

        public ParkingMeter getMeter()

        {

            return new ParkingMeter(meter);

        }

        public ParkingTicket getExpired(PoliceOfficer officer)

        {

            if (meter.getMinutes() - car.getMinutesParked() < 0)

            {

                ticket = new ParkingTicket(officer);

                return ticket;

            }

            else

                ticket = new ParkingTicket();

            return ticket;

        }

        public String toString()

        {

            //String str = "Officer Details\nOfficer's Name: " + name + "\nOfficer's Badge Number: " + badge + "\n\nCar Information: " + car + "\n\nMeter Information: " + meter;

            String str = "Parking ticket #:" + ticket + "\nFined amount: " + "\nIssued by officer: " + name + ", badge #: " + badge;

            return str;

        }

    }

}

Please log in or register to answer this question.

Related questions

0 votes
1 answer
asked Nov 24, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 26, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Sep 26, 2019 in Java by Shubham (3.9k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...