Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have this code, and I keep getting this error: test.cpp:6:1: error: expected u

ID: 3537176 • Letter: I

Question

I have this code, and I keep getting this error:


test.cpp:6:1: error: expected unqualified-id before 'public'


I'm using JGRASP. Can anyone tell me what I'm doing wrong?


---------------------------------------------------------------


#include <iostream>

#include <string>

using namespace std;


public class ParkedCar

{

private String make; // Car's make

private String model; // Car's model

private String color; // Car's color

private String licenseNumber; // Car's alphanumeric license number

public int minutes; // Minutes parked


/**

This constructor initializes the make, model, color, licenseNumber, and minutes fields.

@param pcmake The parked car's make.

@param pcmodel The parked car's model.

@param pccolor The parked car's color.

@param pclnumber The parked car's license plate number.

@param pcminutes The number of minutes that the car has been parked.

*/


public ParkedCar(String pcmake, String pcmodel, String pccolor, String pclnumber, int pcminutes)

{

make = pcmake;

model = pcmodel;

color = pccolor;

licenseNumber = pclnumber;

minutes = pcminutes;

}


/** The set method sets a value for each field.

@param pcmake The parked car's make.

@param pcmodel The parked car's model.

@param pccolor The parked car's color.

@param pclnumber The parked car's license plate number.

@param pcminutes The number of minutes that the car has been parked.

*/


public void set(String pcmake, String pcmodel, String pccolor, String pclnumber, int pcminutes)

{

make = pcmake;

model = pcmodel;

color = pccolor;

licenseNumber = pclnumber;

minutes = pcminutes;

}


/** The copy constructor initializes the object

as a copy of another ParkedCar object.

@param object2 The object to copy.

*/


public ParkedCar(ParkedCar object2)

{

make = object2.make;

model = object2.model;

color = object2.color;

licenseNumber = object2.licenseNumber;

minutes = object2.minutes;

}


/**

toString method

@return A string containing the parked car information.

*/


public String toString()

{

// Create a string representing the object.

String str = "Parked car's make.....................: " + make +

" Parked car's model..................: " + model +

" Parked car's color..................: " + color +

" Parked car's license plate number...: " + licenseNumber +

" Minutes that the car has been parked: " + minutes;


// Return the string.

return str;

}

}

public class ParkingMeter

{

public int minutesPurchased; // The number of minutes of parking time that has been purchased


/**

This constructor initializes the minutesPurchased field.

@param Minutes of parking time purchased.

*/


public ParkingMeter(int pmmpurchased)

{

minutesPurchased = pmmpurchased;

}


/**

The set method sets a value for each field.

@param Minutes of parking time purchased.

*/


public void set(int pmmpurchased)

{

minutesPurchased = pmmpurchased;

}


/** The copy constructor initializes the object

as a copy of another ParkingMeter object.

@param object2 The object to copy.

*/


public ParkingMeter(ParkingMeter object2)

{

minutesPurchased = object2.minutesPurchased;

}


/**

getMinutesPurchased method

@return The number of minutes of parking time that has been purchased.

*/


public int getMintuesPurchased()

{

return minutesPurchased;

}

}

public class ParkingTicket

{

private double fine; // The amount of the fine.

private ParkedCar parkedcar; //

private ParkingMeter parkingmeter; //

private PoliceOfficer policeofficer; //


/**

This constructor initializes the parkedcar, parkingmeter, and policeofficer fields.

@param parkedcar

@param parkingmeter

@param policeofficer

*/


public ParkingTicket(double fine, ParkedCar pcar, ParkingMeter pmeter)

{

// Create a new ParkedCar object, passing

// pcar as an argument to the copy constructor.

parkedcar = new ParkedCar(pcar);


// Create a new ParkingMeter object, passing

// pmeter as an argument to the copy constructor.

parkingmeter = new ParkingMeter(pmeter);


// Create a new PoliceOfficer object, passing

// pofficer as an argument to the copy constructor.

//policeofficer = new PoliceOfficer(pofficer);


this.fine = fine;

}




/**

toString method

@return A string containing the parking ticket information.

*/


public String toString()

{

// Create a string representing the object.

String str = "Illegally parked car info: " + parkedcar +

" Parking meter info:" + parkingmeter +

" Amount of the fine...: " + fine;

//" Police officer info: " + policeofficer;


// Return the string.

return str;

}

}

public class PoliceOfficer

{

private String name; // Name

private int badgeNumber; // Badge number

private ParkedCar parkedcar; // Initialize "parkedcar" object to be copied

private ParkingMeter parkingmeter; // Initialize "parkingmeter" object to be copied

private ParkingTicket parkingticket; //

public double fine = 0; //


/**

This constructor initializes the name and badgeNumber fields.

@param poname The police officer's name.

@param pobnumber The police officer's badge number.

*/


public PoliceOfficer(String poname, int pobnumber, ParkedCar pcar, ParkingMeter pmeter)

{

name = poname;

badgeNumber = pobnumber;


// Create a new ParkedCar object, passing

// pcar as an argument to the copy constructor.

parkedcar = new ParkedCar(pcar);


// Create a new ParkingMeter object, passing

// pmeter as an argument to the copy constructor.

parkingmeter = new ParkingMeter(pmeter);

}


/** The set method sets a value for each field.

@param poname The police officer's name.

@param pobnumber The police officer's badge number.

*/


public void set(String poname, int pobnumber)

{

name = poname;

badgeNumber = pobnumber;

}


/** The copy constructor initializes the object

as a copy of another PoliceOfficer object.

@param object2 The object to copy.

*/


public PoliceOfficer(PoliceOfficer object2)

{

name = object2.name;

badgeNumber = object2.badgeNumber;



// Create a new ParkedCar object, passing

// pcar as an argument to the copy constructor.

//parkedcar = new ParkedCar(pcar);


//Create a new ParkedCar object.

//parkedcar = new ParkedCar(pcar);


//Create a ParkingMeter object.

//parkingmeter = new ParkingMeter(pmeter);

}


public ParkedCar getParkedCar()

{

// Return a copy of the ParkedCar object.

return new ParkedCar(parkedcar);

}


public ParkingMeter getParkingMeter()

{

// Return a copy of the ParkingMeter object.

return new ParkingMeter(parkingmeter);

}


public void inspectParkedCar()

{

// Determine whether the car is illegally parked.

if (parkedcar.minutes > parkingmeter.minutesPurchased)

// Determine the amount of the fine.

if (parkedcar.minutes - parkingmeter.minutesPurchased <= 60)

fine = 25;

else

fine = 25 + (10 * ((parkedcar.minutes - parkingmeter.minutesPurchased) / 60));


// Create a ParkingTicket object, passing

// 3 objects as arguments to the constructor.

parkingticket = new ParkingTicket(fine, parkedcar, parkingmeter);

}

}

public class Demo

{

public static void main (String[ ] args)

{

// Create a ParkedCar object, passing arguments to the constructor.

ParkedCar myParkedCar = new ParkedCar("Chevrolet", "Lumina APV", "White", "556 TNT", 48);


// Create a ParkingMeter object, passing arguments to the constructor.

ParkingMeter myParkingMeter = new ParkingMeter(48);


// Create a ParkedCar object.

//ParkedCar secondParkedCar = new ParkedCar("Chevrolet", "Lumina APV", "White", "556 TNT", 48);


// Create a ParkingMeter object.

//ParkingMeter secondParkingMeter = new ParkingMeter(60);


// Create a PoliceOfficer object.

PoliceOfficer myPoliceOfficer = new PoliceOfficer("John Doe", 1337, myParkedCar, myParkingMeter);


// Create a PoliceOfficer object.

//PoliceOfficer secondPoliceOfficer = new PoliceOfficer("John Doe", 1337, secondParkedCar, secondParkingMeter);


//

myPoliceOfficer.inspectParkedCar();


ParkingTicket myParkingTicket = new ParkingTicket(myPoliceOfficer.fine, myParkedCar, myParkingMeter);

myParkingTicket.toString();


myParkedCar.toString();

//

//secondPoliceOfficer.checkMeter(secondParkedCar, secondParkingMeter);

}//end main

}//end class


------------------------------------------------------------------------

Explanation / Answer

Please change your syntax of functions