1. Draw the UML class relationships in PowerPoint. Name the file BookUML.ppt. 2.
ID: 3682639 • Letter: 1
Question
1. Draw the UML class relationships in PowerPoint. Name the file BookUML.ppt.
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.
Explanation / Answer
import java.io.*;
import java.util.*;
import java.lang.*;
import java.swing.*;
class WriteFile {
FileWriter fw = new FileWriter(“books.txt”);
BufferedWriter bw = new BufferedWriter(fw);
BufferedReader br = new BufferedReader(newe InputStreamReader(System.in));
ArrayList a = new ArrayList();
String s;
System.out.println(“Enter Text”);
s = br.readLine();
for(int i: 0 to 10) {
a = bw.write(s);
i++; }
bw.close();
}
interface Tax {
void caluclateTax(double charge);
}
class Date{
int d,m,y;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter Day”);
d = br.readLine();
System.out.println(“Enter month”);
m = br.readLine();
System.out.println(“Enter Year”);
y = br.readLine();
}
abstract Book {
void printInvoice(); }
class Book1 extenbds BooK implements Tax {
int quantity;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
quantity = br.readLine();
Date publisheddate = new Date();
setQuantity(quantity);
void caluclateTax(double charge) {
double total charge;
double tax = 7.5%;
totalcharge = charge + tax;
return totalcharge;
}
void printInvoice() {
System.outl.println(“Invoice”);
}
}
class Fiction extends WriteFile {
super(a);
Boolen signedbyauthor;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
signedbyauthor = br.readLine();
double charge;
System.out.println(“Enter Amount:”);
charge = br.readLine();
int count = 0;
if(signedbyauthor == true) {
System.out.println(“Book is signed”);
charge = charge + $20;
count ++;
}else System.out.println(“Book is unsigned”);
}
class NonFiction {
public enum Category {
biography
technology
history
science
autobiography
};
public class Enum {
string code;
Category cat;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Code:”);
code = br.readLine();
System.out.println(“Category:”);
cat = br.readLine();
if(code == ‘‘NonFiction”)
this.cat = cat;
}
int n;
double charge;
System.out.println(“Enter Amount:”);
charge = br.readLine();
System.out.println(“Enter bo of books sold”);
n = br.readLine();
if ( n>10) {
charge = charge *((100-10)/100);
}
}
class BookTest extends Fiction, Date,NonFiction,Book1 {
public static void main(String args[]) throws Exception {
BookTest b= new BookTest() ;
Enum e = new Enum();
ArrayList a = new ArrayList();
void createInstances() {
File f = new File (“books.txt”);
BufferedReader br = new BufferedReader(new InputStreamReader(f));
a = br.read();
System.out.println(“Content:” + a);}
void writeFile() {
File file = new File(“updatebook.txt”);
File f = new File (“books.txt”);
BufferedReader br = new BufferedReader(new InputStreamReader(f));
a = br.read();
BufferedWriter bw = new BufferedWriter();
bw.write(a,file);
bw.write(totalcharge,file);
}
JOptionPane.showMessageDialog(“No of Books sold:” + n);
JOptionPane.showMessageDialog(“Nof of books signed:” + count);
JOptionPane.showMessageDialog( “Grand Total:” + totalcharge);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.