Class Photo Album Learn programming Java

Lesson:

Object Oriented Programming


Exercise:

Class Photo Album 10


Objetive:

Create a class "PhotoAlbum" with a private attribute "numberOfPages."

It should also have a public method "GetNumberOfPages", which will return the number of pages.

The default constructor will create an album with 16 pages. There will be an additional constructor, with which we can specify the number of pages we want in the album.

Create a class "BigPhotoAlbum" whose constructor will create an album with 64 pages.

Create a test class "AlbumTest" to create an album with its default constructor, one with 24 pages, a "BigPhotoAlbum" and show the number of pages that the three albums have.


Code:

package December_19th__b_;
public class BigPhotoAlbum extends PhotoAlbum
{
	public BigPhotoAlbum()
	{
		numberOfPages = 64;
	}
}

package December_19th__b_;
import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		boolean debug = false;

		//Create an album with its default constructor
		PhotoAlbum myAlbum1 = new PhotoAlbum();
		System.out.println(myAlbum1.GetNumberOfPages());

		//Create an album with 24 pages
		PhotoAlbum myAlbum2 = new PhotoAlbum(24);
		System.out.println(myAlbum2.GetNumberOfPages());

		//Create an BigPhotoAlbum 
		BigPhotoAlbum myBigPhotoAlbum1 = new BigPhotoAlbum();
		System.out.println(myBigPhotoAlbum1.GetNumberOfPages());

		if (debug)
		{
			new Scanner(System.in).nextLine();
		}
	}
}