Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Using the classes we have created: Publication, Magazine, and Textbook Demo 2 Inheritance

Code Block
languagejava
/* Driver to demonstrate polymorphism using the Textbook and Magazine Class 
 */
 
import java.time.LocalDate;
import java.util.ArrayList; // import the ArrayList class
import java.time.LocalDate; // for a date varaible 

public class Demo4 {
	public static void main(String[] args) {
	
		//create an Array List of Publications
		ArrayList<Publication> myPublications = new ArrayList<Publication>();
		
		//now add some Magazines and textbook to the Publication ArrayList		
		//adding textbooks
		myPublications.add(new TextBook("Learn Java", "Bart Simpson", 759, "8th Edition", "Computer Science") ); 
		myPublications.add(new TextBook("Learn C++", "Fred Flintstone", 759, "7th Edition", "Computer Science") ); 
		
		//create a date
		LocalDate myDate = LocalDate.of(2022, 8, 30); 
		
		//adding magazines
		myPublications.add(new Magazine("Time Magazine", "Time Life Publisher", 83, "Monthly", myDate)); 
		myPublications.add(new Magazine("Alamo College Magizine", "ACCC", 65, "Quarterly", myDate)); 
		
		//now iterate through the array and display the magazines and textbooks 
		for(Publication pPubs : myPublications)
		{
			System.out.println(pPubs.PrintInformation());
		}		
		
	}//end of Main

}//end of class 

...