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:
public Book()
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.
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.
Get Answers For Free
Most questions answered within 1 hours.