Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

**In java, below is what I have so far. 2. Write program WriteFile that writes t

ID: 3683133 • Letter: #

Question

**In java, below is what I have so far.

2. Write program WriteFile that writes the book data to books.txt. The data array is no longer used.

Fiction AbrahamLincolnVampireHunter Grahame-Smith Wiley NY 978-0446563079 13.99 222 true 12 1/1/2015

Fiction Frankenstein Shelley Prescott GA 978-0486282114 7.99 321 true 8 5/12/2008

NonFiction LifeofKennedy Jones Pearson MT 758-29304566 12.90 biography 3 11/11/2011

Fiction Dracula Stoker Addison CA 978-0486411095 5.99 145 false 53 8/15/2005

Fiction CurseoftheWolfman Hageman Wesley MA B00381AKHG 10.59 876 true 7 10/20/2010

NonFiction HowtoPassJava Willis Wiley NY 444-395869790 1.99 technology 23 7/12/2012

Fiction TheMummy Rice Addision CA 978-0345369949 7.99 954 false 13 6/30/2000

NonFiction HistoryofTexas Smith Prescott CA 123-683947687 9.75 history 5 9/18/2010

NonFiction RealWorldPhysics Einstein Pearson MT 145-234512654 29.75 science 15 3/14/2014

Fiction Avengers Whedon Addison CA 345-683947687 12.75 111 true 6 4/25/2009

3. Write interface Tax with method calculateTax that accepts a double and returns a double. Book will use interface Tax and implement calculateTax. Method calculateTax accepts the total charge, adds 7.5% tax and returns the charge plus tax.

4. Write class Date with integer instance variables month, day, and year.

5. Make Book class an abstract class with abstract method, printInvoice. printInvoice returns a String. For now, printInvoice is a stub method that we will complete in the next homework. Rewrite calculateCharge so it does not have any parameters. The quantity array is no longer used.

6. Add the instance variable quantity to Book and update the constructors to set the quantity. Add instance variable datePublished of type Date.

7. Add a boolean attribute to Fiction; signedByAuthor. A true value indicates the book is signed.

8. Turn NonFiction category code into an enumerated type with possible values of biography, technology, history, science, autobiography.

9. Write calculateCharge in Fiction and NonFiction to accommodate the following changes.

10. A NonFiction book gets a 10% discount if more than 10 books are sold. A Fiction book is charged an extra $20 if the book is signed. BookTest will have method createInstances that opens file books.txt, reads the data to create the instances, and returns an ArrayList of book instances. BookTest will have method writeFile which accepts the Book arraylist and writes the instance data and the total charge per book to file, updatebooks.txt.

11. BookTest will print to a dialog box the total number of books sold, how many books were signed, and the grand total.

**THIS IS WHAT I HAVE SO FAR

import java.util.Formatter;
import java.util.Scanner;
import java.io.*;
public class WriteFile
{
public static void main(String args[])
{
  writeToFile();
}
public static void writeToFile()
{
  Formatter output;
  try
  {
   output = new Formatter("books.txt");
   output.format("%s %s %s %s %s %s %.2f %s %s %d %s ", "Fiction", "AbrahamLincolnVampireHunter", "Grahame-Smith", "Wiley", "NY", "978-0446563079", 13.99, "222", "true", 12, "1/1/2015");
   output.format("%s %s %s %s %s %s %.2f %s %s %d %s ", "Fiction", "Frankenstein", "Shelley", "Prescott", "GA", "978-0486282114", 7.99, "321", "true", 8, "5/12/2008");
   output.format("%s %s %s %s %s %s %.2f %s %d %s ", "NonFiction", "LifeofKennedy", "Jones", "Pearson", "MT", "758-29304566", 12.90, "biography", 3, "11/11/2011");
   output.format("%s %s %s %s %s %s %.2f %s %s %d %s ", "Fiction", "Dracula", "Stoker", "Addison", "CA", "978-0486411095", 5.99, "145", "false", 53, "8/15/2005");
   output.format("%s %s %s %s %s %s %.2f %s %s %d %s ","Fiction", "CurseoftheWolfman", "Hageman", "Wesley", "MA", "B00381AKHG", 10.59, "876", "true", 7, "10/20/2010");
   output.format("%s %s %s %s %s %s %.2f %s %d %s ", "NonFiction", "HowtoPassJava", "Willis", "Wiley", "NY", "444-395869790", 1.99, "technology", 23, "7/12/2012");
   output.format("%s %s %s %s %s %s %.2f %s %s %d %s ", "Fiction" , "TheMummy", "Rice", "Addision", "CA", "978-0345369949", 7.99, "954", "false", 13, "6/30/2000");
   output.format("%s %s %s %s %s %s %.2f %s %d %s ", "NonFiction", "HistoryofTexas", "Smith","Prescott", "CA", "123-683947687", 9.75, "history", 5, "9/18/2010");
   output.format("%s %s %s %s %s %s %.2f %s %d %s ", "NonFiction", "RealWorldPhysics", "Einstein", "Pearson", "MT", "145-234512654", 29.75, "science", 15, 3/14/2014);
   output.format("%s %s %s %s %s %s %.2f %s %s %d %s ", "Fiction", "Avengers", "Whedon", "Addison", "CA", "345-683947687", 12.75, "111", "true", 6, "4/25/2009");
   output.close();
  }
  catch(IOException ioe)
  {
   System.out.println(ioe);
  }
}
}

3.

public interface Tax
{
public abstract double calculateTax();
}

4.

public class Date {
   private int month;
   private int day;
   private int year;
   public Date(int month, int day, int year){
       this.month = month;
       this.day = day;
       this.year = year;
   }
   public int getMonth() {
       return month;
   }
   public void setMonth(int month) {
       this.month = month;
   }
   public int getDay() {
       return day;
   }
   public void setDay(int day) {
       this.day = day;
   }
   public int getYear() {
       return year;
   }
   public void setYear(int year) {
       this.year = year;
   }
  
}

5.

public abstract class Book implements Tax
{
//Call Variables
private String title;
private String author;
private String isbn;
private Publisher publisher;
private double price;
private int quantity;

//set book
public Book()
{
  setTitle("");
  setAuthor("");
  setIsbn("");
  setPublisher(new Publisher());
  setPrice(0.0);
  setQuantity(0);
}

//Make book Constructor
public Book(String title, String author, String isbn, Publisher publisher, double price, int quantity)
{
  setTitle(title);
  setAuthor(author);
  setIsbn(isbn);
  setPublisher(publisher);
  setPrice(price);
  setQuantity(quantity);
}

//Make calculate Charge method
//public static Double calculateCharge(int quantity, double price)
//{
  //double total_charge = quantity * price;
  //return total_charge;
//}
public abstract double calculateCharge();

//Gets and Sets
public void setTitle(String title)
{
  this.title = title;
}
public String getTitle()
{
  return title;
}
public void setAuthor(String author)
{
  this.author = author;
}
public String getAuthor()
{
  return author;
}
public void setIsbn(String isbn)
{
  this.isbn = isbn;
}
public String getIsbn()
{
  return isbn;
}
public void setPublisher(Publisher publisher)
{
  this.publisher = publisher;
}
public Publisher getpublisher()
{
  return publisher;
}
public void setPrice(double price)
{
  this.price = price;
}
public double getPrice()
{
  return price;
}
public void setQuantity(int quantity)
{
  this.quantity = quantity;
}
public int getQuantity()
{
  return quantity;
}

//To String
public String toString()
{
  return("Title: " + title + " Author: " + author + " Isbn: " + isbn + " Publisher: " + publisher + " Price: "+ price);
}

public double calculateTax()
{
  Double tax = (getPrice()*getQuantity())* 0.075;
  Double total_charge_with_tax = getPrice() + tax;
  return total_charge_with_tax;
  
}
public abstract String printInvoice();


}

Explanation / Answer

public class Assignment_4 { public static void main(String[] args) { Scanner user_input = new Scanner(System.in); Double taxrate; Double annual_Income; Double tax_amount; Double final_income; While (annual_Income >=0;) { System.out.println("Enter Gross Income"); annual_Income = scanner.nextDouble(); if (annual_Income < 25000.00 ) taxrate = 0.10; else if (annual_Income