Question

In: Computer Science

In Java Create an interface Create an interface Printing, which have a method getPageNumber () that...

In Java

Create an interface Create an interface Printing, which have a method getPageNumber () that return page number of any printing.

Create an abstract class named Novel that implements Printing. Include a String field for the novel's title and a double field for the novel price. Within the class, include a constructor that requires the novel title, and add two get methods--one that returns the title and one that returns the price. Include an abstract method named setPrice().. Create two child classes of Novel: Fiction and NonFiction. Each must include a setPrice() method that sets the price for all Fiction Novel at 89.90 SAR and for all NonFiction Novels at $124.50 SAR. Write a constructor for each subclass, and include a call to setPrice() within each. Write an application demonstrating that you can create both a Fiction and NonFiction Novel and display their fields. Save the fields as Novel.java, Fiction.java, NonFiction.java, and UseNovel.java.

Write an application named NovelArray in which you create an array that holds 8 Novels, some Fiction and some NonFiction. Using a for loop, display details about all 8 novels. Save the file as NovelArray.java.

Solutions

Expert Solution

If you have any problem with the code feel free to comment.

Printing

public interface Printing {
  
   public int getPageNumber();

}

Novel

public abstract class Novel implements Printing {

   protected String title;
   protected double price;

   public Novel(String title) {
       this.title = title;
   }

   public String getTitle() {
       return title;
   }

   public double getPrice() {
       return price;
   }

   abstract public void setPrice();

}

Fiction

public class Fiction extends Novel {

  
   public Fiction(String title) {
       super(title);
       setPrice();
   }

   @Override
   public int getPageNumber() {
       // TODO Auto-generated method stub
       return 0;
   }

   @Override
   public void setPrice() {
       price = 89.90;
   }

}

NonFiction

public class NonFiction extends Novel {

   public NonFiction(String title) {
       super(title);
       setPrice();
   }

   @Override
   public int getPageNumber() {
       // TODO Auto-generated method stub
       return 0;
   }

   @Override
   public void setPrice() {
       price = 124.50;
   }
}

UseNovel

public class UseNovel {
   public static void main(String[] args) {
       Fiction fic = new Fiction("Alone");
       NonFiction nonfic = new NonFiction("Im alive");
       System.out.println("Title: "+fic.getTitle()+", Price: $"+fic.getPrice());
       System.out.println("Title: "+nonfic.getTitle()+", Price: $"+nonfic.getPrice());
   }
}

NovelArray

public class NovelArray {
   public static void main(String[] args) {
      
       Novel[] novels = {
               new Fiction("Somthings Wrong!!"),
               new NonFiction("Stupid"),
               new Fiction("Love"),
               new Fiction("Ghost"),
               new NonFiction("Money"),
               new Fiction("Freedom"),
               new NonFiction("Anger"),
               new NonFiction("Greed"),
               new NonFiction("Chemistry")
       };
      
       for(Novel i: novels) {
           System.out.println("Title: "+i.getTitle()+", Price: $"+i.getPrice());
       }
   }
}

Outputs


Related Solutions

JAVA Given the company and Employee interface, create a findLeastPaid() method (that will do the opposite...
JAVA Given the company and Employee interface, create a findLeastPaid() method (that will do the opposite of whats below). instead of finding the the best paid convert it find the lowest paid person. Given the Company and FullTimeEmployee classes and the Employee interface, write a Java program that reads in a file of full time employees with each line of input containing the name of the employee (String) and gross Salary (double) and stores them in an array list. Then...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then create 4 classes: 1- Leaf: that implements turn(), which changes the color of the Leaf object and returns true. If for any reason it is unable to change color, it should return false (you can come up with a reason for failure). The new color can be determined at random. 2- Document: that implements turn(), which changes the page on the document to the...
JAVA 1. Create an Interface Vehicle. Declare one public void method in it paint( ). 2....
JAVA 1. Create an Interface Vehicle. Declare one public void method in it paint( ). 2. Create a class Car. Implements Vehicle. It's paint() method prints "Car Painted". It's drive( ) method prints "Car Driven". 3. Create a class Bus. Implements Vehicle. It's paint() method prints "Bus Painted" . It's drive( ) method prints "Bus Driven".   4. Create a method AutoWork which accepts an object of type Vehicle. The method makes a call to the vehicle's paint( ) and drive()...
Use JAVA language. Using the switch method concept create a program in which you have an...
Use JAVA language. Using the switch method concept create a program in which you have an artist (singer) and the list of his or her songs. Add 18 songs. Then alter the script to achieve the following in each test run: a) Print all the songs. b) Print only song 15. c) Print only song 19.
Use the below info to create a java program A GUI interface to ensure a user...
Use the below info to create a java program A GUI interface to ensure a user is old enough to play a game. Properly formatted prompts to input name, address, phone number, and age. Remember that name, address, phone number, etc. can be broken out in additional fields. Refer to the tutorial from this week’s Reading Assignment Multiple vs. Single Field Capture for Phone Number Form Input for help with this. Instructions to ensure that the information is displayed back...
Create an interface MessageEncoder that has a single abstract method encode(plainText) where the plainText is the...
Create an interface MessageEncoder that has a single abstract method encode(plainText) where the plainText is the message to be encoded. The method will return the encoded version of the message. Then create a class SubstitutionCipher that implements this interface. The constructor should have on parameter called shift. Define the method encode so that each letter is shifted by the value in shift. For example if shift is 3 a will be replaced by d, b will be replaced by e....
in java Write an interface for a CD player. It should have the standard operations (i.e....
in java Write an interface for a CD player. It should have the standard operations (i.e. play, stop, nextTrack, previousTrack, etc.) that usual CD players have.
Create a java program that will do the following: Create a method called getInt.Allow the user...
Create a java program that will do the following: Create a method called getInt.Allow the user to enter up to 20 student names,and for each student 3 quiz scores (in the range 0-100). Once input is done, display each student’s name, their three quiz scores, and their quiz score average, one student per line. The output table does not need to line up perfectly in columns.Use dialog boxes for all input and output.Use the method to input the three scores.Parameter...
Java Create a method to display a menu. When this method is called it should receive...
Java Create a method to display a menu. When this method is called it should receive the user's name, great the user, and ask them to make a selection. 1 - Change your name, 2 - Test your IQ, 3 - Display a table, 4 - Play a game, 5 - Exit.
******IN JAVA******** I need the following interface implemented accordingly. It is a linked list. The interface...
******IN JAVA******** I need the following interface implemented accordingly. It is a linked list. The interface can be found below: List.java public interface List<T> extends Iterable<T> { /** * Insert an element at a specified location. * @param index * @param obj * @throws IndexOutOfBoundsException */ public void add(int index, T obj); /** * Append an object to the end of the list. * @param obj */ public boolean add(T obj); public void clear(); public boolean contains(T obj); /** *...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT