Question #40082

Question # 773

A Book is Good if it satisfies the following conditions:

It has more than 100 pages and Its title must not end with the character 's'.
If title ends wih the character 'e', then should not start with character 'a'
The publisher of the book must be one of "Niho books", "DreamWorldz", "Pogo Books" and "Diamond Comics"
The number of authors must be greater than 2. But if "CK Bose" is one of the authors, then this conditon is not required.
If "Pran" is one of the authors, the publisher must be "Diamond comics".
There should be atleast 10 pages per rupee cost of the book.

Write a method:

boolean isGoodBook(String title, String publisher, int numPages, float price, String[] authors)

title The title of the book
publisher Name of the publisher of the book.
numPages Number of pages in the book.
price Price of the book in rupees.
authors A string array containing the list of authors.
1

Expert's answer

2014-03-17T14:54:58-0400

Answer on Question #40082, Programming, Other


using System;
using System.Collections.Generic;
using System.Linq;
namespace Good_Book
{
    class Program
    {
        static void Main(string[] args)
        {
            String title; String publisher; int numPages; float price; String[] authors={"CK Bose"};
            // authors value is CK Bose - custom value
            Console.WriteLine("Enter title name:");
            title = Console.ReadLine();
            Console.WriteLine("Enter publisher:");
            publisher = Console.ReadLine();
            Console.WriteLine("Enter the number of pages:");
            numPages = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter book price:");
            price = (float)Convert.ToDouble(Console.ReadLine());
            if (isGoodBook(title, publisher, numPages, price, authors)) Console.WriteLine("good book");
            else Console.WriteLine("The book isn't good");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
        static bool isGoodBook(String title, String publisher, int numPages, float price, String[] authors)
        {
            if (numPages < 100 || (title.ToLower())[title.Length - 1] == 's') return false;
            if ((title.ToLower())[title.Length - 1] == 'e' && title.ToLower()[0] == 'a') return false;
            string[] publishers = { "niho books", "dreamworldz", "pogo books", "diamond comics" };
            if (!publishers.Contains<string>(publisher.ToLower())) return false;
            string super_author = "CK Bose";
            if (!authors.Contains<string>(super_author) && authors.Length < 3) return false;
            if (authors.Contains<string>("Pran") && publisher.ToLower() != publishers[3]) return false;
            if ((double)(price / numPages) * 10 < 1) return false;
            return true;
        }
    }
}

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!
LATEST TUTORIALS
APPROVED BY CLIENTS