1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Andrei [34K]
3 years ago
11

1. Write program, WriteData.java, that writes the following data to file books.txt. Include the semicolons. Fiction;Abraham Linc

oln Vampire Hunter;Grahame-Smith;Wiley;NY;13.99;222 Fiction;Frankenstein;Shelley;Prescott;GA;7.99;321 NonFiction;Life of Kennedy;Jones;Pearson;MT;12.90;biography Fiction;Dracula;Stoker;Addison;CA;5.99;145 Fiction;Curse of the Wolfman;Hageman;Wesley;MA;10.59;876 NonFiction;How to Pass Java;Willis;Wiley;NY;1.99;technology Fiction;The Mummy;Rice;Addision;CA;7.99;954 NonFiction;History of Texas;Smith;Prescott;CA;9.75;history 2. Write class Publisher with attributes name and state. 3. Rewrite the Book class to include a type Publisher attribute. 4. Write two children of the Book class: FictionBook and NonFictionBook. FictionBook has an additional attribute, fictionCode. NonFictionBook has an additional attribute, catagoryCode. 5. Rewrite the BookTest program. Method buildInstances will read the data from the file, create instances of FictionBook and NonfictionBook from the data, assign these instances to the Book array and return the bookArray as before. Since it is reading data from the file, it does not have any method parameters. 6. Method createCharges should work the same.
Computers and Technology
1 answer:
Amiraneli [1.4K]3 years ago
7 0

Answer:

Check the explanation

Explanation:

WriteData.java:

import java.io.FileWriter;

import java.io.PrintWriter;

class WriteData {

  String[][] data;

 

  public WriteData() {

      // Data to write to the file

      data = new String[][]{{ "Fiction", "Abraham Lincoln Vampire Hunter", "Grahame-Smith", "Wiley", "NY", "13.99", "222"},

          {"Fiction", "Frankenstein", "Shelley", "Prescott", "GA", "7.99", "321"},

          {"NonFiction", "Life of Kennedy", "Jones", "Pearson", "MT", "12.90", "biography"},

          {"Fiction", "Dracula", "Stoker", "Addison", "CA", "5.99", "145"},

          {"Fiction", "Curse of the Wolfman", "Hageman", "Wesley", "MA", "10.59", "876"},

          {"NonFiction", "How to Pass Java", "Willis", "Wiley", "NY", "1.99", "technology"},

          {"Fiction", "The Mummy", "Rice", "Addision", "CA", "7.99", "954"},

          {"NonFiction", "History of Texas", "Smith", "Prescott", "CA", "9.75", "history"}};

      }

 

  public void writeToFile() {

      try {

          PrintWriter pw = new PrintWriter(new FileWriter("books.txt"));   // Creating an output stream to write to file

         

          // Writing data to the file line by line

          for (int i = 0; i < 8; i++) {

              pw.println(data[i][0] + ";" + data[i][1] + ";" + data[i][2] + ";" + data[i][3] + ";" + data[i][4] + ";" + data[i][5] + ";" + data[i][6]);

          }

         

          pw.close();       // Closing the created output stream

      }

      catch(Exception e) {

          System.err.println(e);

      }

  }

}

Publisher.java:

class Publisher {

  private String name, state;

 

  public Publisher(String name, String state) {

      this.name = name;

      this.state = state;

  }

 

  // Getters and Setters

  public String getName() {

      return name;

  }

  public void setName(String name) {

      this.name = name;

  }

  public String getState() {

      return state;

  }

  public void setState(String state) {

      this.state = state;

  }

 

  public String toString() {

      return name + ";" + state;

  }

}

Book.java:

class Book {

  private String title, author;

  private double price;

  private Publisher publisher;

  public Book(String title, String author, Publisher publisher, double price) {

      this.title = title;

      this.author = author;

      this.publisher = publisher;

      this.price = price;

  }

  public Double calculateCharge(int Qty){

      return getPrice()*Qty;

  }

  public String getTitle() {

      return title;

  }

  public void setTitle(String title) {

      this.title = title;

  }

  public String getAuthor() {

      return author;

  }

  public void setAuthor(String author) {

      this.author = author;

  }

  public String getPublisher() {

      return publisher.toString();

  }

  public void setPublisher(Publisher publisher) {

      this.publisher = publisher;

  }

  public double getPrice() {

      return price;

  }

  public void setPrice(double price) {

      this.price = price;

  }

}

FictionBook.java:

class FictionBook extends Book {

  String fictionCode;

 

  public FictionBook(String title, String author, Publisher publisher, double price, String fictionCode) {

      super(title, author, publisher, price);       // Calling the parent constructor to initialize values

      this.fictionCode = fictionCode;

  }

 

  // Getter and Setter

  public String getFictionCode() {

      return fictionCode;

  }

  public void setFictionCode(String fictionCode) {

      this.fictionCode = fictionCode;

  }

}

NonFictionBook.java:

class NonFictionBook extends Book {

  String categoryCode;

 

  public NonFictionBook(String title, String author, Publisher publisher, double price, String categoryCode) {

      super(title, author, publisher, price);       // Calling the parent constructor to initialize values

      this.categoryCode = categoryCode;

  }

 

  // Getter and Setter

  public String getCategoryCode() {

      return categoryCode;

  }

  public void setCategoryCode(String categoryCode) {

      this.categoryCode = categoryCode;

  }

}

BookTest.java:

import java.util.Scanner;

import java.util.*;

import java.io.File;

import java.io.FileNotFoundException;

public class BookTest {

  public static void main(String[] args) {

      // TODO code application logic here

     

      // Writing data to the file using WriteData.java program

      WriteData writeData = new WriteData();

      writeData.writeToFile();

     

      int[] BookQauntity = {12, 8, 3, 53, 7, 23, 14, 5, 6};

      Book[] book = new BookTest().buildInstances();

      Double GrandTotal= new BookTest().createCharges(BookQauntity, book);

      System.out.println("GrandTotal : "+ GrandTotal);

 

 

  }

      catch(FileNotFoundException e) {

          System.err.println("File not found");

      }

     

      return bk;

  };

 

  // ISBN info is removed

  Double createCharges(int[] BookQuantity, Book[] book){

      Double Gtotal =0.0, total=0.0;

      for(int i=0; i<8; i++){

          total = book[i].calculateCharge(BookQuantity[i]);

          System.out.println("Title : "+ book[i].getTitle() + ", Total Charge : "+ total);

          Gtotal +=total;

      }

     

      return Gtotal;

  };

}

You might be interested in
Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, a
Viktor [21]

Answer:

The program to this question can be given as:

Program:

import java.util.*;

//import package for user input  

class Main     //define class

{

public static void main(String a[])  

//define main function

{

int positive_number=0,negative_number=0,count=0,num; //define variable

double total=0,avg=0;  

//creating Scanner class object.

Scanner ob = new Scanner(System.in);

System.out.println("Enter an integer, when done input 0: "); //message

num= ob.nextInt();

//taking input from user

if (num==0)  //check number equal to 0  

{  

System.out.println("No numbers are entered except 0"); //message

System.exit(1);

}

else

{

while (num!= 0)  

{    

   if (num> 0)

   {

positive_number++; // Increase positives

}

else

{

negative_number++; // Increase negatives

}

total=total+num; // Accumulate total

count++;    // Increase the count

num=ob.nextInt();

}

// Calculate the average

avg=total/count;

// Display values

System.out.println("The positive number is:"+positive_number);

System.out.println("The negatives number is:"+negative_number);

System.out.println("total is:"+total);

System.out.println("average is:"+avg);

}

}

}

Output:

Enter an integer, when done input 0: 22

2

1

4

0

The positive number is:4

The negatives number is:0

total is:29.0

average is:7.25

Explanation:

In the above program firstly we import the package for user input then we define a class that is main in this class we define the main method in the main method we define variable. Then we create a scanner class object for user input. In the number variable, we take multiple inputs from the user and also check that the user does not insert 0 at the starting of the program. To check this we use the condition statement that is a number equal to 0 then it will terminate the program. In the else part we first declare the loop that checks that inserted number is positive and negative and in this, we calculate the total of the numbers and at the end of the loop, we calculate the average of the number and print all the values.

4 0
2 years ago
Read 2 more answers
What are the two main parts of system unit hardware?
Georgia [21]

Answer: Computers have two main parts: hardware and software

Like piano (hardware) and music (software)

Explanation:

4 0
2 years ago
What does project manager do?
lapo4ka [179]
Project managers (PMs) are responsible for planning, organizing, and directing the completion of specific projects for an organization while ensuring these projects are on time, on budget, and within scope.
7 0
2 years ago
In order to be compliant with the NIST publications, policies must include key security control requirements. One of these key r
rodikova [14]

Answer:

The answer is "Option A".

Explanation:

A comprehensive collection of principles, guidelines, proposals, and studies on information and information systems privacy and safety are produced and carried out in the NIST publications.

  • The FIPS management standards for federal information and security laws contain various technical reporting sequences.
  • This process takes place after a plan is identified, reviews are carried out and risk analysis is performed.
8 0
3 years ago
Suppose that, on average, 4 percent of all cd drives received by a computer company are defective. the company has adopted the f
kicyunya [14]

The fraction of shipments that will be accepted is 0.1299.

<h3>How to calculate the probability?</h3>

Probability of a defective DVD = 0.04

Using Binomial distribution,

Fraction of shipments accepted = Probability of zero defects in sample of 50 = P(X = 0)

= 50C0 * 0.040 * (1 - 0.04)⁵⁰

= 0.96⁵⁰

= 0.1299

Fraction of shipments accepted = Probability of zero or one defects in sample of 50 = P(X = 0) + P(X = 1)

= 50C0 * 0.040 * (1 - 0.04)50-0 + 50C1 * 0.041 * (1 - 0.04)50-1

= 0.9650 + 50 * 0.04 * 0.9649

= 0.4005

Learn more about probability on:

brainly.com/question/24756209

#SPJ1

6 0
2 years ago
Other questions:
  • (20 points) Given a collection of n nuts and a collection of n bolts, arranged in an increasing order of size, give an O(n) time
    9·1 answer
  • Each peripheral device has its own software, called a(n) ____, which contains the detailed instructions required to start that d
    6·1 answer
  • True or false: when considering data backups, it is most important to verify that the integrity of the backup file or data is va
    9·1 answer
  • MTTF is a file format developed by Microsoft commonly used on Windows systems; it offers file security, large volume size, large
    11·1 answer
  • Which line in the following program will cause a compiler error? #include using namespace std; int main() { int number =5; if (n
    10·1 answer
  • What are some of these new iPad extras? One is the iMarker. Crayola teamed up with another company to make it. It costs $29.99.
    8·1 answer
  • your friend's parent's are worried about going over their budget for the month. Which expense would you suggest is NOT a need?
    11·1 answer
  • The user cannot use a computer system without.................... software<br><br>​
    13·2 answers
  • python. create a program that asks the user to input their first name and their favorite number. Then the program should output
    12·1 answer
  • Each computer on a network requires a unique way to identify itself and to refer to other computers. This is accomplished by usi
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!