Practice Exercises Java - Learn to program performing exercises with Java

Practice Exercises Java

Learn to program performing exercises with Java

12 Lessons Java with the Solutions - 228 Exercises Java with the solutions
For Beginners, Intermediates and Advanceds


App Practice Exercises Java

The human knowledge belongs to the world
¡The infomation should be free!



Catalog - Practice Exercises Java


Lesson 7:

More on classes


Exercise 7.7:

Catalog


Objetive:

Create the classes diagram and then, using Visual Studio, a project and the corresponding classes for a catalog utility:

It will be able to store information about music files, films and computer programs.
For each item, it must store: name, code, category and size. For films it must also hold the director, the main actor and the main actress. For music files, the singer and the length (in seconds).
For music and movies it must have a method "Play" (not implemented yet) and also a method "RetrieveInformation", which will (in a later version) connect to an internet server to get information about it.
Use inheritance if needed. In "Main", create arrays of each kind of object.


Source Code:


package Catalog;
public class Main
{
	public static void main(String[] args)
	{
		Film[] myFilms = new Film[3];
		Music[] myMusic = new Music[3];
		ComputerProgram[] myComputerProgram = new ComputerProgram[3];
	}
}

public class Item
{
	protected String name;
	protected String code;
	protected String category;
	protected String size;

	public Item()
	{
	}
	public Item(String name, String code, String category, String size)
	{
		this.name = name;
		this.code = code;
		this.category = category;
		this.size = size;
	}

	public final String getName()
	{
		return name;
	}
	public final void setName(String value)
	{
		name = value;
	}
	public final String getCode()
	{
		return code;
	}
	public final void setCode(String value)
	{
		code = value;
	}
	public final String getCategory()
	{
		return category;
	}
	public final void setCategory(String value)
	{
		category = value;
	}
	public final String getSize()
	{
		return size;
	}
	public final void setSize(String value)
	{
		size = value;
	}
}

public class Film extends Item
{
	protected String director;
	protected String mainActor, mainActress;

	public Film()
	{

	}
	public Film(String director, String mainActor, String mainActress)
	{
		this.director = director;
		this.mainActor = mainActor;
		this.mainActress = mainActress;
	}

	public final String getDirector()
	{
		return director;
	}
	public final void setDirector(String value)
	{
		director = value;
	}
	public final String getMainActor()
	{
		return mainActor;
	}
	public final void setMainActor(String value)
	{
		mainActor = value;
	}
	public final String getMainActress()
	{
		return mainActress;
	}
	public final void setMainActress(String value)
	{
		mainActress = value;
	}

	public final void Play()
	{

	}
	public final void RetrieveInformation()
	{

	}
}

public class Music extends Item
{
	protected String singer;
	protected int length;

	public Music()
	{

	}
	public Music(String singer, int length)
	{
		this.singer = singer;
		this.length = length;
	}

	public final String getSinger()
	{
		return singer;
	}
	public final void setSinger(String value)
	{
		singer = value;
	}
	public final int getLenght()
	{
		return length;
	}
	public final void setLenght(int value)
	{
		length = value;
	}

	public final void Play()
	{

	}
	public final void RetrieveInformation()
	{

	}
}
public class ComputerProgram extends Item
{

}
Exercisey 7.7




Privacy Policy:



Google uses associated advertising companies to serve ads when it visits our website. These companies may use the information they obtain from your visits to this and other websites (not including your name, address, email address, or phone number) to provide you with announcements about products and services that interest you. If you would like to learn more about this practice and know your options to prevent these companies from using this information. Click in... Privacy and Terms of Google.

Cookies

This site uses Google cookies to provide its services, to personalize advertisements and to analyze traffic. Google receives information about your use of this website. More information in... Privacy and Terms of Google.