Question

PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with...

PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH!

a. Create a project with a Program class and write the following two methods (headers provided) as described below:

- A Method, public static int InputValue(int min, int max), to input an integer number that is between (inclusive) the range of a lower bound and an upper bound. The method should accept the lower bound and the upper bound as two parameters and allow users to re-enter the number if the number is not in the range or a non-numeric value was entered.

- A Method, public static bool IsValid(string id), to check if an input string satisfies the following conditions: the string’s length is 5, the string starts with 2 uppercase characters and ends with 3 digits. For example, “AS122” is a valid string, “As123” or “AS1234” are not valid strings.

b. Create a Book class containing the following:

- Two public static arrays that hold codes (categoryCodes) and descriptions of the popular book categories (categoryNames) managed in a bookstore. These codes are CS, IS, SE, SO, and MI, corresponding to book categories Computer Science, Information System, Security, Society and Miscellaneous.

- Data fields for book id (bookId) and book category name   (categoryNameOfBook)

- Auto-implemented properties that hold a book’s title (BookTitle), book’s number of pages (NumOfPages) and book’s price (Price).

- Properties for book id and book category name. Assume that the set accessor will always receive a book id of a valid format. For example, “CS125” and “IS334” are of valid format and also refer to known categories “Computer Science” and “Information Systems”. If the book ID does not refer to a known category, then the set accessor must retain the number and assign to the “MI” category. For example, “AS123” will be assigned as “MI123”. The category property is a read-only property that is assigned a value when the book id is set.

- Two constructors to create a book object:

  • one with no parameter:

public Book()

  • one with parameter for all data fields:

public Book(string bookId, string bookTitle, int numPages, double price)

- A ToString method, public override string ToString(), to return information of a book object using the format given in the screen shot under

Information of all Books

c. Extend the application in Part A (i.e., adding code in the Program class) to become a BookStore Application by making use of the Book class and completing the following tasks:

- Write a Method,

           private static void GetBookData(int num, Book[] books),

to fill an array of books. The method must fill the array with Books which are constructed from user input information (which must be prompted for). Along with the prompt for a book id, it should display a list of valid book categories and call method in Part A.2 to make sure the inputted book id is a valid format. If not the user is prompted to re-enter a valid book id.

- After the data entry is complete, write a Method,

            public static void DisplayAllBooks(Book[] books),

to display information of all books that have been entered including book id, title, number of pages and price. This method should call the ToString method that has been created in Book class.

- After the data entry is complete, write a Method,

            private static void GetLists(int num, Book[] books),

to display the valid book categories, and then continuously prompts the user for category codes and displays the information of all books in the category as well as the number of books in this category. Appropriate messages are displayed if the entered category code is not a valid code.

- Write the Main method that first prompts the user for the number of books that is between 1 and 30 (inclusive), by calling the method in Part A.1.

Then call method in Part C.1 to create an array of books.

Then call method in Part C.2 to display all books in the array.

Then call method in Part C.3 to allow the user to input a category code and see information of the category.

Homework Answers

Answer #1

using System;
class Program{
     public static int InputValue(int min, int max){
         int x;
        while(true){
         Console.WriteLine("Enter the number of books:");
         Console.Read();
         x=Console.Read();
         if(x>=min&&x<=max){
             break;
         }
         else{
         Console.WriteLine("\nInvalid Input");
         }
        }
        return x;
     }
     public static bool IsValid(string id){
         bool b=false;
         if(id.Length==5){
           string s=id.Substring(0,2);
           if(s.Equals(s.ToUpper())){
               string temp=id.Substring(2,3);
               int test;
               if(int.TryParse(temp, out test)){
                   b=true;
               }
           }
         }
         return b;
     }
      
}
class Book{
    public static string[] categoryCodes=new string[5]{"CS","IS","SE","SO","MI"};
    static string[] categoryNames=new string[5]{"Computer Science","Information System","Security","Society","Miscellaneous"};
    string bookId;
    string categoryNameOfBook;
    string bookTitle;
    int numPages;
    double price;
    public Book(){
        
    }
    public Book(string bookId, string bookTitle, int numPages, double price){
        this.bookId=bookId;
        this.bookTitle=bookTitle;
        this.numPages=numPages;
        this.price=price;
    }
    public string toString(){
        return bookId+" "+bookTitle+" "+numPages+" "+price;
    }
}
class test {
    public static void DisplayAllBooks(Book[] books){
          for(int i=0;i<books.Length;i++){
          Console.WriteLine(books[i].toString());
          }
      }
    private static void GetBookData(int num, Book[] books){
        Console.WriteLine("Valid book category:CS123,IS456,SE789,SO752,MI987");
        string bookId;
        while(true){
        Console.WriteLine("Enter Book Id:");
        bookId=Console.ReadLine();
        if(Program.IsValid(bookId)){
            break;
        }
        }
        
    }
    private static void GetLists(int num, Book[] books){
        Console.WriteLine("Valid book category:CS,IS,SE,SO,MI");
        string s;
        Console.WriteLine("Enter the category code:");
        s=Console.ReadLine();
        for(int j=0;j<books.Length;j++){
        for(int i=0;i<5;i++){
           if(s.Equals(Book.categoryCodes[i])){
                Console.WriteLine(books[j].toString());
           }
        }
        }
    }
  static void Main() {
      Book[] b=new Book[3];
      b[0]=new Book("CS125","Computer Science",125,500);
      b[1]=new Book("IS334","Information System",200,650);
      b[2]=new Book("SE187","Security",80,250);
      GetBookData(Program.InputValue(1,30),b);
      test.DisplayAllBooks(b);
      test.GetLists(Program.InputValue(1,30),b);
  }
}

Thank you! if you have any queries post it below in the comment section I will try my best to resolve your queries and I will add it to my answer if required. Please give upvote if you like it.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes...
In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes a contestant’s name, talent code, and talent description. The competition has become so popular that separate contests with differing entry fees have been established for children, teenagers, and adults. Modify the Contestant class to contain a field that holds the entry fee for each category, and add get and set accessors. Extend the Contestant class to create three subclasses: ChildContestant, TeenContestant, and AdultContestant. Child...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its variables (firstName and lastName). It should contain an abstract method called payPrint. Below is the source code for the Employee9C superclass: public class Employee9C {    //declaring instance variables private String firstName; private String lastName; //declaring & initializing static int variable to keep running total of the number of paychecks calculated static int counter = 0;    //constructor to set instance variables public Employee9C(String...
The AssemblyLine class has a potential problem. Since the only way you can remove an object...
The AssemblyLine class has a potential problem. Since the only way you can remove an object from the AssemblyLine array is when the insert method returns an object from the last element of the AssemblyLine's encapsulated array, what about those ManufacturedProduct objects that are "left hanging" in the array because they never got to the last element position? How do we get them out? So I need to edit my project. Here is my AssemblyLine class: import java.util.Random; public class...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
main The main method instantiates an ArrayList object, using the Car class. So, the ArrayList will...
main The main method instantiates an ArrayList object, using the Car class. So, the ArrayList will be filled with Car objects. It will call the displayMenu method to display the menu. Use a sentinel-controlled loop to read the user’s choice from stdin, call the appropriate method based on their choice, and redisplay the menu by calling displayMenu. Be sure to use the most appropriate statement for this type of repetition. displayMenu Parameters:             none Return value:          none Be sure to use...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
Currently stuck on this part of a project. I am struggling with creating the String for...
Currently stuck on this part of a project. I am struggling with creating the String for creating the dice values in the boxes for the "showDice" string. I have already completed the first part which was creating the class for the Die. This is Javascript. For this part, we will create the class that allows you to roll and score the dice used in a game of Yahtzee. This will be the longest part of the project, so I suggest...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...