Answer to Question #239019 in Java | JSP | JSF for Jaden

Question #239019

1 When the user selects to view a report, display the product report generated from the arrays in your application. You must create a class called ReportData which will contain get and set methods for each item required in the report


1
Expert's answer
2021-09-18T23:56:54-0400

The program answering this question is based on a bookshop

. it gives a report of the books available in Dkay bookshop, the book title, the author, number of copies available for sale and the number of copies sold and this data is stored in arrays. We have getters and setters methods and also a method for printing in the ReportData class.

import java.util.Scanner;
 class ReportData {
     // private = restricted access
    private String book_name;
    private String book_author;
     private String copies_available;
     private String copies_sold;
     //private int num_of_products;

     // Setters
     public void setbook_name(String b_name) {
         this.book_name = b_name;
     }
     public void set_author(String ar_name) {
         this.book_author = ar_name;
     }
     public void setCopies_available(String cpa_code) {
         this.copies_available = cpa_code;
     }
     public void setCopies_sold(String cps_code) {
         this.copies_sold = cps_code;
     }
     // Getters
    public String getBook_name_name() {
        return book_name;
    }
     public String getBook_author() {
         return book_author;
     }
     public String getCopies_available() {
         return copies_available;
     }
     public String getCopies_sold() {
         return copies_sold;
     }
     //Method for printing the details of the products
     public void printDetails() {
         System.out.println("\tBook Name: " + book_name);
         System.out.println("\tBook Author: " + book_author);
         System.out.println("\tCopies available for sale: " + copies_available);
         System.out.println("\tCopies sold : " + copies_sold);


     }



 }

public class Main {

    public static void main(String[] args) {
        //An array listing the books available in my stock for sale, the copies available,
        // copies sold, author and book name
        String[][] books_for_sale = {
                {"Don Quixote", "Miguel de Cervantes", " 1345", "5076"},
                {"A Tale of Two Cities", "Charles Dickens", "789 ", "3459"},
                {"The Lord of the Rings","J.R.R. Tolkien", "784"," 5786"},
                {"The Little Prince","Antoine de Saint-Exupery","2356"," 567"},
                {"The Hobbit","J.R.R. Tolkien","5678","8893"}
        };
        //Menu
        System.out.println("Dkay Bookshop stock management");
        System.out.println("1.View report of your stock");
        System.out.println("2.Exit the program");
        System.out.print("Enter your option: ");
        Scanner sc = new Scanner(System.in);
        int option = sc.nextInt();
        if(option == 1)
        {

            for(int i = 0; i<books_for_sale.length;i++)
            {
                System.out.print(i+1);
                ReportData myObj = new ReportData();
                myObj.setbook_name(books_for_sale[i][0]);
                myObj.set_author(books_for_sale[i][1]);
                myObj.setCopies_available(books_for_sale[i][2]);
                myObj.setCopies_sold(books_for_sale[i][3]);

                myObj.printDetails();
            }
        }
        else if(option == 2)
        {
            System.out.println("Program exited");
        }
        else
        {
            System.out.println("Invalid option please try again");
        }

    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS