This question already has answers here:
Why does my ArrayList contain N copies of the last item added to the list?
(5 answers)
Closed 6 years ago.
This if my first question on stackoverflow. I can usually find answers myself but I'm having trouble with this one. I've got 2 objects, "Book", and "Periodical". These are subclasses to a class "Publication". Now, I'm trying to add 3 instances of "Book" and 3 instances of "Periodical" to an ArrayList. I'm having trouble figuring out how to do this.
With this current code, I get an error "no suitable method found for add(Book,Book,Book,Periodical,Periodical,Periodical).
Here is the current code:
import java.util.ArrayList;
import java.util.Date;
public class DriverProgram {
public static void main(String[] args) {
// Instantiate 3 instances of each object.
Book book1 = new Book(1234, 1, "James", 100, "Hello", "Berkwood Inc.", new java.util.Date(), "History");
Book book2 = new Book(2345, 2, "Ralph", 200, "Goodbye", "Shackles Co.", new java.util.Date(), "English");
Book book3 = new Book(3456, 3, "Julia", 300, "Hello Again", "Trustin Inc.", new java.util.Date(), "History");
Periodical periodical1 = new Periodical("Daily", "Dylan", "History 101", "History Inc.", new java.util.Date(), "History");
Periodical periodical2 = new Periodical("Weekly", "Jannette", "Mathematics 101", "Mathematics Inc.", new java.util.Date(), "Mathematics");
Periodical periodical3 = new Periodical("Monthly", "Patricia", "Science 101", "Science Inc.", new java.util.Date(), "Science");
// Create an array list of the Publication class type, and add the objects to it.
ArrayList <Publication> publications = new ArrayList<Publication>();
publications.add(book1, book2, book3, periodical1, periodical2, periodical3);
// Pass the array list to a method to loop through it and display the toString methods.
displayObjects(publications);
} // End of main
static void displayObjects (ArrayList<Publication> publications) {
// Loop through array list and display the objects using the toString methods.
for (Publication p : publications) {
System.out.print(p.toString());
} // End of for each loop
} // End of displayObjects
} // End of DriverProgram class
I've also tried changing:
publications.add(book1, book2, book3, periodical1, periodical2, periodical3);
To this:
publications.add(book1);
publications.add(book2);
publications.add(book3);
publications.add(periodical1);
publications.add(periodical2);
publications.add(periodical3);
Which rids my program of the compiler error, but then it just prints the "periodical3" object, 6 times. I'm not sure what I'm doing wrong. Any suggestions? Thank you in advance! :)
EDIT:
Here is my Book class:
public class Book extends Publication{
private static int isbn = 0;
private static int libraryOfCongressNbr = 0;
private static String author = "";
private static int nbrOfPages = 0;
// Constructor for Book class with parameters for each attribute.
public Book(int newISBN, int newLibraryOfCongressNbr, String newAuthor, int newNbrOfPages, String newTitle, String newPublisher, java.util.Date newPublicationDate, String newSubject) {
super(newTitle, newPublisher, newPublicationDate, newSubject);
isbn = newISBN;
libraryOfCongressNbr = newLibraryOfCongressNbr;
author = newAuthor;
nbrOfPages = newNbrOfPages;
}
/////////////////////////////////////////////////////// Getters ///////////////////////////////////////////////////////
int getISBN() {
return isbn;
}
int getLibraryOfCongressNbr() {
return libraryOfCongressNbr;
}
String getAuthor() {
return author;
}
int getNbrOfPages() {
return nbrOfPages;
}
/////////////////////////////////////////////////////// Setters ///////////////////////////////////////////////////////
void setISBN(int newISBN) {
isbn = newISBN;
}
void setLibraryOfCongressNbr(int newLibraryOfCongressNbr) {
libraryOfCongressNbr = newLibraryOfCongressNbr;
}
void setAuthor(String newAuthor) {
author = newAuthor;
}
void setNbrOfPages(int newNbrOfPages) {
nbrOfPages = newNbrOfPages;
}
//toString method for Book class
public String toString () {
StringBuilder result = new StringBuilder();
result.append("\nISBN: " + isbn + "\n");
result.append("\nPublisher: " + libraryOfCongressNbr + "\n");
result.append("\nAuthor: " + author + "\n");
result.append("\nNumber of Pages: " + nbrOfPages + "\n");
result.append("--------------------------------------------------------- ");
return super.toString() + result.toString();
} // End of toString
} // End of Book class
My Periodical class is identical, but here is my Publication class:
import java.util.Date;
public abstract class Publication {
// Data fields.
private static String title = "";
private static String publisher = "";
private static java.util.Date publicationDate;
private static String subject = "";
// Constructor for Publication class with parameters for each attribute.
public Publication(String newTitle, String newPublisher, java.util.Date newPublicationDate, String newSubject){
title = newTitle;
publisher = newPublisher;
publicationDate = newPublicationDate;
subject = newSubject;
}
/////////////////////////////////////////////////////// Getters ///////////////////////////////////////////////////////
String getTitle() {
return title;
}
String getPublisher() {
return publisher;
}
java.util.Date getPublicationDate() {
return publicationDate;
}
String getSubject() {
return subject;
}
/////////////////////////////////////////////////////// Setters ///////////////////////////////////////////////////////
void setTitle(String newTitle) {
title = newTitle;
}
void setPublisher(String newPublisher) {
publisher = newPublisher;
}
void setPublicationDate(java.util.Date newPublicationDate) {
publicationDate = newPublicationDate;
}
void setSubject(String newSubject) {
subject = newSubject;
}
//toString method for Publication class
public String toString () {
StringBuilder result = new StringBuilder();
result.append("\nTitle: " + title + "\n");
result.append("\nPublisher: " + publisher + "\n");
result.append("\nPublication Date: " + publicationDate + "\n");
result.append("\nSubject: " + subject + "\n");
return result.toString();
} // End of toString
} // End of Publication class
Let me know if you need anything else!
EDIT x2: Sorry, I realize my post is getting quite long.
So I've gotten rid of all "static" keywords from my class variables, or "data fields" as I've called them in my code. I then changed my code back to this code:
ArrayList <Publication> publications = new ArrayList<Publication>();
publications.add(book1);
publications.add(book2);
publications.add(book3);
publications.add(periodical1);
publications.add(periodical2);
publications.add(periodical3);
And it works! It executes as it should! I just one question though, since this code doesn't seem to work:
publications.add(book1, book2, book3, periodical1, periodical2, periodical3);
Is there a shorter way to add all of the objects to the ArrayList with out doing it one by one?
If I understand the problem correctly, you have 6 Publication objects, and you are only seeing the values of the most recently created one.
That would likely be caused because you have static class variables instead of instance variables.
For example
class A {
static int x; // class variable
int y; // instance variable
public A(int val) {
x = val; // All 'A' classes now have x = val;
y = val; // Only 'this' class has y = val;
}
}
If I were to run this
A a1 = new A(4);
A a2 = new A(5);
System.out.println(a1.x);
Then I would see it print 5 and not 4, which describes the scenario you are seeing because you have assigned all variables in the Publication class to those that you use during the last call of new Periodical.
The solution is to not use static variables if you want to have multiple instances of a class with their own values.
Related
I am having a problem when trying to print my ticket(child class) which is all my superclass variables are null or zero not initialized.
this is my superclass:-
public class movie {
protected int movieID;
protected String movieTitle;
movie(){};
movie(int movieID , String movieTitle ){
this.movieID = movieID;
this.movieTitle = movieTitle;
}
}
this is my childclass
public class ticket extends movie{
private int Number_of_ticket;
private int show_number ;
ticket(int Number_of_ticket , int show_number){
this.Number_of_ticket = Number_of_ticket;
this.show_number = show_number;
}
public void print_the_tacket(){
System.out.println("movie id is " + super.movieID);
System.out.println("movie name is " + super.movieTitle);
System.out.println("number of the ticket is " + Number_of_ticket);
System.out.println("show number is " + show_number);
}
}
the main
public class Main {
public static void main(String[] args) {
movie MyMovie = new movie(1234, "spiderman");
ticket myticket = new ticket(34 , 334);
myticket.print_the_tacket();
}
}
my output is
movie id is 0
movie name is null
number of the ticket is 34
show number is 334
I expect when I print my ticket the movie information why I am getting null values What is wrong here? thank you in advance.
When you reference super in the child class, it not bound to the Movie object you created in the main(). That is why you are getting a null value. Look here when I debug the code.
If you want to access the Movie object you created in main(), you can pass it and that will work.
To explain..
Note 1: There are 2 constructors created here. One is movie() without arguments, the other is with 2 arguments. What you extend and call is #1 not #2
public class movie {
protected int movieID;
protected String movieTitle;
movie() { //#1 - no args, so movieID=null, movieTitle=null
//you can debug by adding this line.
this.movieID = 1;
this.movieTitle = "I should not be printing this";
}
movie(int movieID , String movieTitle ){ //#2 - has args.
this.movieID = movieID;
this.movieTitle = movieTitle;
}
}
Note 2: Your problem is in ticket, when you do not write super(..) with args you are passing nothing, hence it is calling movie() without parameters. So if you are calling movie(), you get non declared variables. If you see sample above for debug you should see 1 and "I should not print this" instead to explain the scenario.
public class ticket extends movie{
private int Number_of_ticket;
private int show_number ;
ticket(int Number_of_ticket , int show_number){
//Not visible, but actually triggers super() and calling movie #1, not super(arg1, args2)
//super(1,"movie")
this.Number_of_ticket = Number_of_ticket;
this.show_number = show_number;
}
}
Note 3: You are making 2 different objects, object #1 is movie, and object #2 is ticket. To me it seems you only want 1 object which is ticket that extends movie. What happens here is that the codes are 2 different/seperated objects and they are not tied together.
public class Main {
public static void main(String[] args) {
movie MyMovie = new movie(1234, "spiderman"); //#Object 1
ticket myticket = new ticket(34 , 334); //#Object 2
myticket.print_the_tacket();
}
}
Approach: You may want the codes to be the following way where you create movie and ticket together in ticket call. This means when you create ticket your movie must be created. In a nutshell no movie created, no tickets to issue.
public class Movie { //Class name should always be captialized
protected int movieID; //you can declare final
protected String movieTitle;
Movie(int movieID , String movieTitle ){ //Only this
this.movieID = movieID;
this.movieTitle = movieTitle;
}
}
public class Ticket extends Movie { //Captialize class
private int Number_of_ticket; //should avoid _ and use Snakecase
private int show_number ;
Ticket(int Number_of_ticket , int show_number, int movieID, String movieTitle){
super(movieId, movieTitle); //always and must create movie object
this.Number_of_ticket = Number_of_ticket;
this.show_number = show_number;
}
public void print_the_tacket(){ //should use snake case printTheTacket
System.out.println("movie id is " + super.movieID);
System.out.println("movie name is " + super.movieTitle);
System.out.println("number of the ticket is " + Number_of_ticket);
System.out.println("show number is " + show_number);
}
}
public class Main {
public static void main(String[] args) {
Ticket myticket = new Ticket(34 , 334, 1234, "spiderman");
myticket.print_the_tacket();
}
}
Much ideal is that movie is created in ticket instead of passing 2 arguments or extending. In this case both are separated and tied and incase in future movie has also things like PG-13, GA parameters you can expand it. But i guess it's for school understanding on inheritance, your example fits for now.
public class Ticket {
private int numberOfTickets;
private int showNumber ;
private Movie movie;
Ticket(int numberOfTickets , int showNumber, Movie movie){
this.numberOfTickets = numberOfTickets;
this.showNumber = showNumber;
this.movie = movie
}
public void printTheTacket(){
System.out.println("movie id is " + movie.movieID);
System.out.println("movie name is " + movie.movieTitle);
System.out.println("number of the ticket is " + numberOfTickets);
System.out.println("show number is " + showNumber);
}
}
I have created a class called Album, which is this one:
public class Album {
private String Titulo;
private int temas;
private int ano;
public Album(String Titulo2, int temas2, int ano2) {
this.Titulo = Titulo2;
this.temas = temas2;
this.ano = ano2;
}
public Album(String Titulo2, int temas2) {
this.Titulo = Titulo2;
this.temas = temas2;
}
public int getAno() {
return this.ano;
}
public int getTemas() {
return this.temas;
}
public String getTitulo() {
return this.Titulo;
}
public void setAno(int ano) {
this.ano = ano;
}
public boolean foiEditadoNesteSeculo() {
if (this.ano > 2000) {
return true;
} else {
return false;
}
}
public void adicionaTemasBonus(int x) {
this.temas += x;
}
public void mostraAlbum() {
System.out.println(this.Titulo + " (editado em " + this.ano + "; tem " + this.temas + " temas)");
}
}
It works fine. The problem is that the teacher asked me to create a new class called Band and it has to have an array of Albums. The Band object should be declared with an int that represents the limit of the number of albums (the length of the array). I already have some idea on how to work with arrays, but I have no idea on how to create a type of array that contains objects from another class, and after how to use the attributes of the objects to return something. I think I can figure out the rest after I'm able to properly create the class, though.
Apologies, as it has been described in Portuguese and I don't have much experience in translating.
In my opinion this would be easier to manage with a List so you can add as many Albums as you want at any time, however, since the problem statement required Array I made an example of a Band class.
I also included main method to test the program at the bottom of the Band class:
public class Band {
private int totalAlbums;
private Album[] albums;
private int currentNumberOfAlbums;
public Band(int totalAlbums) {
this.totalAlbums = totalAlbums;
this.albums = new Album[totalAlbums];
this.currentNumberOfAlbums = 0;
}
public Band(Album[] albums) {
this.totalAlbums = albums.length;
this.albums = albums;
this.currentNumberOfAlbums = this.totalAlbums;
}
public void addNewAlbum(String titulo, int temas, int ano) {
if (this.currentNumberOfAlbums == totalAlbums) {
System.out.println("Warning: Cannot add any more albums, limit reached.");
return;
}
this.albums[this.currentNumberOfAlbums++] = new Album(titulo, temas, ano);
}
public void printAlbums() {
for (Album a : this.albums) {
a.mostraAlbum();
}
}
public static void main(String [] args) {
Band b = new Band(3);
b.addNewAlbum("The First", 4, 2001);
b.addNewAlbum("The Second", 98, 2055);
b.addNewAlbum("The Finale", 12, 2011);
b.addNewAlbum("The Extra", 12, 2111);
b.printAlbums();
}
}
There are a few things to look for in this code.
First, to address your direct question, you can simply use a custom class as an array like any other class/primitive with Album[].
Secondly, you will require a Band constructor that instantiates the array of Album based on an integer passed to it, so you know how many albums are the limit. You can see this with the this.albums = new Album[totalAlbums]; line.
Next, you need a way to add a new Album into the array of Album[]. This can be done a few different ways, but the way I chose was to create a method addNewAlbum(String, int, int) to do it for this example which will also increase currentNumberOfAlbums by 1 every time a new album is added. This is useful so you know when an Album is attempted to be added even though the totalAlbums are already full! This will prevent an ArrayIndexOutOfBoundsException in your code if addNewAlbum is called too many time.
Lastly, in addNewAlbum you need to call your Album constructor with new Album(titulo, temas, ano).
In my example main, a Band with limit of 3 albums is created, and 4 albums are attempted to be added into it, with the first 3 adding successfully, and the 4th not being added, but instead printing a warning for being outside the limit.
I also added a printAlbums() method which will use your mostraAlbum() to print each Album in the albums array.
Output:
Warning: Cannot add any more albums, limit reached.
The First (editado em 2001; tem 4 temas)
The Second (editado em 2055; tem 98 temas)
The Finale (editado em 2011; tem 12 temas)
EDIT:
I added the Band(Album[] albums) constructor, you can call this with:
Album[] albums = new Album[3];
//Add your albums into this variable
Band b = new Band(albums);
public class Band {
private Album[] albums;
private numberOfAlbums;
//...
// create an empty constructor
Band(){
albums = new Album[];
numberOfAlbums = 0;
}
// constructor that receives the albums
Band(Album[] albums){
this.albums = albums;
this.numberOfAlbums = albums.length;
}
// constructor that receives the number of albums
Band(int numOfAlbums){
this.numberOfAlbums = numOfAlbums;
this.albums = new Album[numOfAlbums];
}
// add getters and setters
// example of adding a new album
public void addNewAlbum(Album album){
if(this.numOfAlbums == this.albums.length){
// you need to create a new array with a bigger size, copy the existing data and insert the album
// or whatever you'd like
} else {
this.albums[this.numOfAlbums] = album;
// increment the numOfAlbums
this.numOfAlbums++;
}
}
}
private class Album {
//...
}
You just need to add [] to define that the field is an array.
public class Band {
private int totalAlbums;
private Album[] albums;
//...
}
private class Album {
//...
}
I hope this example helps you.
private Album[] albums; // array of album
private int albumLimit; // limit for album
public Band(int albumLimit) {
this.albumLimit = albumLimit; // initialize limit
this.albums = new Album[albumLimit]; // set limit of album array
}
// here it creates a new Album every time the loop runs
// you can fill the array in other ways too
public void fillAlbum() {
for (int i = 0; i < albumLimit; i++) {
String name = "name_" + i;
int team = i;
albums[i] = new Album(name, team);
}
}
public void printAlbum() {
for (int i = 0; i < albumLimit; i++) {
System.out.println("Name :" + albums[i].getTitulo());
System.out.println("Team :" + albums[i].getTemas());
System.out.println();
}
}
}
So Im trying to print only the novels added to the array and I cant figure out how..
Also I need to return the number of books of a specific kind.
Im new to programming so please take me easy :)
Here is the app, I have to add all the books from console
Each word added from console triggers a specific action so to print the books I need to write print, to add i need to write add , type of book, title of book, author, and so on.
import java.util.*;
public class App{
public static void main(String [] args){
Scanner s = new Scanner(System.in);
Library bib = Library.getInstance();
String line = "";
line = s.nextLine();
String[] v = line.split("\\s+");
while(true){
switch(v[0]){
case "add":
String title = v[2];
String autor = v[3];
Book c = null;
if("story".equals(v[1])){
c = new Story(title, autor);
} else if("novel".equals(v[1])){
int pages = Integer.parseInt(v[4]);
c = new Novel(title, autor, pages);
} else if("poetry".equals(v[1])){
String publish = v[4];
c = new Poetry(title, autor, publish);
}
bib.adauga(c);
break;
case "print" :
case "return" :
case "exit" : System.exit(0); break;
default : System.out.println("Command " + v[0] + " does not exist");
}
}
}
}
import java.util.*;
public class Library{
private static Library instance;
List<Book> books;
private Library(){
books = new ArrayList<>();
}
public static Library getInstance(){
if(instance == null){
instance = new Library();
}
return instance;
}
public void adauga(Book c){
books.add(c);
}
public void afisare(){
for(Book c : books){
System.out.println(c);
}
}
}
public abstract class Book{
String title;
String autor;
public Book(String title, String autor){
this.title=title;
this.autor=autor;
}
#Override
public String toString(){
return title + " " + autor;
}
}
public class Novel extends Book {
int pages;
public Novel(String title, String autor, int pages){
super(title, autor);
this.pages=pages;
}
#Override
public String toString(){
return super.toString() + " " + pages;
}
}
You can use instanceof to check what the type of an object is.
//Go through every book
for(Book book : bib.books){
if(book instanceof Novel){
System.out.println(book);
}
}
You have created a method that print all the books of theLibrary, you need to modify it to print the good type of book :
Use print novel for example :
// in App
case "print" : bib.afisare(v[1]);
break;
// in Library
public void afisare(String type){
for(Book c : books){
if("novel".equals(type) && c instance of Novel)
System.out.println(c);
else if("story".equals(type) && c instance of Story)
System.out.println(c);
else if("poetry".equals(type) && c instance of Poetry)
System.out.println(c);
}
}
Also, because of your while(true) you are going to run in infinite loop, you need to ask again after the switch or don't ask before and use do{}while();
do{
line = s.nextLine();
String[] v = line.split("\\s+");
switch(v[0]){
...
}
}while(true);
You can access variables from other objects by using '.' as long the variable is in visibility (e.g. public or in same package) or you use getter methods.
So in your case you can do something like this.
final List<Book> books = Library.getInstance().getBooks();
for(Book book : books) {
if(book instanceof Novel) {
System.out.println(((Novel)book).toString());
}
}
need to add to Library
public List<Book> getBooks() {
return this.books;
}
This is just a simple example how you can use your books and pages with your example, feel free to edit and use it as you need to.
How can I insert objects into an array? Here I have a class called HotelRoom which contains getter, setter, and the constructor method.
public class HotelRoom {
int roomNumber;
String roomGuest;
public HotelRoom (int room, String guest) {
roomNumber = room;
roomGuest = guest;
}
public int getRoom() {
return roomNumber;
}
public void setRoom() {
roomNumber = room;
}
public String getName() {
return roomGuest;
}
public void setName() {
roomGuest = guest;
}
And here I have the main method containing the array initializer and the objects. I've also inserted the objects into the array however, when compiling, the problem arises in the print command and it states: "cannot find symbol - variable HotelRoom". What am I doing wrong?
public class Hotel {
public static void main (String [] args) {
HotelRoom[] rooms = new HotelRoom [5];
HotelRoom guest1 = new HotelRoom(67, "Harry");
HotelRoom guest2 = new HotelRoom(98, "Bob");
HotelRoom guest3 = new HotelRoom(34, "Steven");
HotelRoom guest4 = new HotelRoom(99, "Larry");
HotelRoom guest5 = new HotelRoom(103, "Patrick");
rooms[0] = guest1;
rooms[1] = guest2;
rooms[2] = guest3;
rooms[3] = guest4;
rooms[4] = guest5;
System.out.println (HotelRoom);
}
}
This is because HotelRoom is a class, not an Object. If you have intentions of printing out all of the rooms, perhaps you could try something like:
for(final HotelRoom room : rooms)
System.out.printf("%s in room %d\n", room.getName(), room.getRoom());
Or you could override the toString() method in HotelRoom:
public String toString(){
return String.format("%s in room %d", roomGuest, roomNumber);
}
With the overridden toString() method, you can now modify your loop to:
for(final HotelRoom room : rooms)
System.out.println(room);
Or, if you want:
System.out.println(Arrays.toString(rooms));
HotelRoom is the name of the class. The objects are now in the rooms array. If you are wanting to print out the array, try printing rooms, or a particular place in the array, e.g
System.out.println(rooms[0].getName());
At first implement toString() in the HotelRoom:
public String toString() {
return roomNumber + " " + roomGuest;
}
And then print the right array:
System.out.println(Arrays.toString(rooms));
Currently I am teaching myself Java but I came across a simple problem but have no one to ask from. From one of the exercises, I wrote a class and write a driver class that instantiates and updates several objects. I am confused by "instantiates and updates several objects." Here is what I mean: So here is my class:
public class PP43Car {
private String make = "";
private String model = "";
private int year;
public PP43Car(String ma, String m, int y)
{
make = ma;
model = m;
year = y;
}
public void setMake(String ma)
{
make = ma;
}
public String getMake()
{
return make;
}
public void setModel(String m)
{
model = m;
}
public String getModel()
{
return model;
}
public void setYear(int y)
{
year = y;
}
public int getYear()
{
return year;
}
public String toString()
{
String result = "Make of the vehicle: " + make +
" Model of the vehicle " + model +
" Year of the vehicle: " + year;
return result;
}
}
Which instantiates make, model and year. Then once I was writing the driver class, the way I began was:
import java.util.Scanner;
public class PP43CarTest {
public static void main(String[] args) {
PP43Car car1;
Scanner scan = new Scanner(System.in);
System.out.println("Enter the model of the vehicle:");
car1.getModel();
}
}
But this class produces error and here is where I am stuck. Do I keep on going with this or is this what is meant by "instantiating and updating several objects?"
import java.util.Scanner;
public class PP43CarTest {
static PP43Car car1;
public static void main(String[] args) {
//Scanner scan = new Scanner(System.in);
car1 = new PP43Car("Millenia", "Mazda", 2011);
}
}
If the above code is correct, then can anyone show me how I can use the Scanner class to actually get the user input and update it that way because I would like to learn that as well?
Well, in your last fragment of code you are indeed instantiating an object, since you are doing:
car1 = new PP43Car("Millenia", "Mazda", 2011);
When you create a new object, you are creating a new instance of the class, so yes, you are instantiaing an object.
But you aren't updating it anywhere, because I think here updating means modifying the object, but you only create the object, not modify it...
Something like this would be an update:
car1.setYear(2013);
Since you are setting a different value for an attribute of the object, you are updating it...
EDIT: Try this code, it can't throw any exception, it's Java basics! I hope it clarifies your doubts...
public class PP43CarTest {
public static void main(String[] args) {
//Declaring objects
PP43Car car1;
PP43Car car2;
PP43Car car3;
//Instantiating objects
car1 = new PP43Car("Millenia", "Mazda", 2011);
car2 = new PP43Car("Aaaa", "Bbb", 2012);
car3 = new PP43Car("Ccc", "Ddd", 2012);
//Updating objects
car1.setMake("Xxx");
car1.setMake("Yyy");
car1.setYear(2013);
//Printing objects
System.out.println("CAR 1: " + car1.toString());
System.out.println("CAR 2: " + car2.toString());
System.out.println("CAR 3: " + car3.toString());
}
}