Using Java. 1. Write class, Publisher, with attributes name and state. 2. Write
ID: 3672066 • Letter: U
Question
Using Java.
1. Write class, Publisher, with attributes name and state.
2. Write Book class with attributes, title, author, isbn, publisher, and price. Book class has method calculateCharge that accepts the quantity sold and returns the total charge.
3. Write two children of Book: Fiction and NonFiction. Fiction has attribute fiction code. NonFiction has attribute category code.
4. Data will be in a two-dimensional data array as follows:
Fiction, Abraham Lincoln Vampire Hunter, Grahame-Smith, Wiley, NY, 978-0446563079, 13.99, 222
Fiction, Frankenstein, Shelley, Prescott, GA, 978-0486282114, 7.99, 321
NonFiction, Life of Kennedy, Jones, Pearson, MT, 758-29304566, 12.90, biography
Fiction, Dracula, Stoker, Addison, CA, 978-0486411095, 5.99, 145
Fiction, Curse of the Wolfman, Hageman, Wesley, MA, B00381AKHG, 10.59, 876
NonFiction, How to Pass Java, Willis, Wiley, NY, 444-395869790, 1.99, technology
Fiction, The Mummy, Rice, Addision, CA, 978-0345369949, 7.99, 954
NonFiction, History of Texas, Smith, Prescott, CA, 123-683947687, 9.75, history
5. Rewrite the test case to create all books and calculate the charge and print out as before.
The quantity will be in a one-dimensional array as follows.
12 8 3 53 7 23 14 5 6.
Using the data array, create instances of books and store them in a one-dimensional array of Book, bookArray. Using the quantity array, walk through the book array and calculate the total charge per book sold. Print in a dialog box the book title, the book isbn, and the total charge for each book. Then, print the grand total of all books sold.
**This is what I have so far, but I know it's not complete and I'm assuming I made some mistakes possibly. Can someone help me out please?
I'm not sure how to do the quantity Array or how to calculate the charge. But I think most of what I have is on the right path. Thanks
public class Publisher private String name; private String state; public Publisher) setName(""); setstate(""); public Publisher(String name, String state) setName(name); setState(state); public void setName(String name) this.name = name; public void setState(String state) this. state = state; public String getName() return name; public String getState() return state; public String toString) return ("Name " nameState " state);Explanation / Answer
Fiction.java
// 3. Write two children of Book: Fiction and NonFiction.
// Fiction has attribute fiction code.
// NonFiction has attribute category code.
public class Fiction extends Book {
public String fiction;
public Fiction(String fictions, String titles, String authors, String publishers, String isbns, double prices) {
super(titles, authors, publishers, isbns, prices);
fiction = fictions;
}
public static void main(String[] args) {
Fiction fic = new Fiction("Fiction", "Abraham Lincoln Vampire Hunter", "Grahame-Smith", "Wiley, NY", "978-0446563079", 13.99);
System.out.println(fic.calculateCharge(222));
}
}
NonFiction.java
// 3. Write two children of Book: Fiction and NonFiction.
// Fiction has attribute fiction code.
// NonFiction has attribute category code.
public class NonFiction extends Book {
public String nonfiction;
public NonFiction(String nonfictions, String titles, String authors, String publishers, String isbns, double prices) {
super(titles, authors, publishers, isbns, prices);
nonfiction = nonfictions;
}
public String getCategory(String category) {
return category;
}
public static void main(String[] args) {
NonFiction non = new NonFiction("NonFiction", "History of Texas", "Smith", "Prescott, CA", "123-683947687", 9.75);
System.out.println(non.getCategory("history"));
}
}
Book.java
// 2. Write Book class with attributes, title, author, isbn, publisher, and price.
// Book class has method calculateCharge that accepts the quantity sold and returns the total charge
class Book {
// public class Book {
public String title;
public String author;
public String isbn;
public String publisher;
public double price;
public int quantity;
private double total = 0;
// Define Book constructor
// public Book(String titles, String authors, String publishers, String isbns, double prices, int quantities) {
public Book(String titles, String authors, String publishers, String isbns, double prices) {
title = titles;
author = authors;
publisher = publishers;
isbn = isbns;
price = prices;
// quantity = quantities;
}
// Define calculateCharge method
public double calculateCharge(int quantity) {
total = quantity * price;
return total;
}
/*
public static void main(String[] args) {
// Create book object
Book book = new Book("Java Beginner", "Java Developer", 1234, "ABC publisher", 30);
book.qty++;
int result = book.calculateCharge(book.qty, book.price);
System.out.println(book.display(result));
// Create book1 object
Book book1 = new Book("Java Beginner", "Java Developer", 1234, "ABC publisher", 10);
book1.qty++;
int result1 = book1.calculateCharge(book1.qty, book1.price);
System.out.println(book1.display(result1));
}
*/
}
Publisher.java
// 1. Write class, Publisher, with attributes name and state.
public class Publisher {
public String name;
public String state;
public Publisher(String names, String states) {
name = names;
state = states;
}
public static void main(String[] args) {
Publisher pub = new Publisher("Java Begin", "TX");
System.out.println("Name = " + pub.name);
System.out.println("State = " + pub.state);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.