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...
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....
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...
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.
(JAVA) ExceptionSum The objective of this exercise is to create a method that adds all the...
(JAVA) ExceptionSum The objective of this exercise is to create a method that adds all the numbers within an array with an exception you cant sum the 6, and the 7, and the numbers between them cannot be added too, taking into account that whenever a 6 appears will be followed by a 7. If we have an array such that [1,2,3,6,10,9,8,7,5] when we pass it through the method it will give us an int such that the sum will...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Find a method of ArrayList that is not in the List interface, specifically a method that...
Find a method of ArrayList that is not in the List interface, specifically a method that trims the internal array down to fit exactly. A Google search for this did work, but the JDK API of course is the definitive source. Give the method header for the method. Add a call to this method to TestArrayList.java (which is available online in TestArrayList.zip), and see that it compiles and runs fine. Now change the line creating the ArrayList to use type...
only JAVA code /** Create a method as instructed below and then call it appropriately. */...
only JAVA code /** Create a method as instructed below and then call it appropriately. */ import java.util.Scanner; public class MoreBankCharges { //Constant declarations for base fee and per check fees //Class scope so constants are accessible by all methods static final double BASE_FEE = 10.0; static final double LESS_THAN_20_FEE = 0.10; static final double TWENTY_TO_THIRTYNINE_FEE = 0.08; static final double FORTY_TO_FIFTYNINE_FEE = 0.06; static final double SIXTY_OR_MORE_FEE = 0.04; public static void main(String[] args) { //Variable declarations int numChecks;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT