the errors only got worse with the previous fix  Input Book1 Author1 10.99 200 Book2 Author2 19.99 100 Book3 Author2 25.00 600 Book4 Author3 5.00 20

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

the errors only got worse with the previous fix 

Input
Book1
Author1
10.99
200
Book2
Author2
19.99
100
Book3
Author2
25.00
600
Book4
Author3
5.00
20
Book5
Author4
8.00
120
Output
Book1 by Author1 Price $10.99 200 pages.
Book2 by Author2 Price $19.99 100 pages.
Book3 by Author2 Price $25 600 pages.
Book4 by Author3 Price $5 20 pages.
Book5 by Author4 Price $8 120 pages.

the results for this are in the image 

my other error is 

Unit TestIncomplete
BookException test

Build Status
Build Succeeded
Test Output
NUnit Console Runner 3.10.0 (.NET 2.0)
Copyright (c) 2019 Charlie Poole, Rob Prouse
Sunday, 26 March 2023 20:04:35

Runtime Environment
   OS Version: Linux 5.0.0.27 
  CLR Version: 4.0.30319.42000

Test Files
    NtTestce2b4463.dll


Errors, Failures and Warnings

1) Failed : TestBookException.FirstBookExceptionTest
  Expected: <BookException>
  But was:  null
  at TestBookException.FirstBookExceptionTest () [0x00000] in <79111348b1e14d73832a84bb9d5a15b5>:0 

Run Settings
    DisposeRunners: True
    WorkDirectory: /root/sandbox6ae72429
    ImageRuntimeVersion: 4.0.30319
    ImageRequiresX86: False
    ImageRequiresDefaultAppDomainAssemblyResolver: False
    NumberOfTestWorkers: 2

Test Run Summary
  Overall result: Failed
  Test Count: 2, Passed: 1, Failed: 1, Warnings: 0, Inconclusive: 0, Skipped: 0
    Failed Tests - Failures: 1, Errors: 0, Invalid: 0
  Start time: 2023-03-26 20:04:36Z
    End time: 2023-03-26 20:04:37Z
    Duration: 1.073 seconds

my code is

using System;

class Book
{
    // private fields
    private string title;
    private string author;
    private double price; //data type changed
    private int numPages;

    // constructor that takes in arguments and sets the fields
    public Book(string title, string author, double price, int numPages)
    {
        this.title = title;
        this.author = author;
        this.price = price;
        this.numPages = numPages;
    }

    // public properties that allow access to the private fields
    public string Title
    {
        get { return title; }
        set { title = value; }
    }

    public string Author
    {
        get { return author; }
        set { author = value; }
    }

    public double Price
    {
        // when setting the price, also calculate the price per page
        // and check if it's greater than a certain threshold
        get { return price; }
        set
        {
            double pricePerPage = value / numPages;
            if (pricePerPage > 0.1) //Removed m
            {
                // if the price per page is too high, throw a BookException
                throw new BookException(title, price, numPages);
            }
            price = value;
        }
    }

    public int NumPages
    {
        get { return numPages; }
        set { numPages = value; }
    }

    // override the ToString method to return a string representation of the Book object
    public override string ToString()
    {
        return title + " by " + author + " Price $" + price + " " + numPages + " pages.";
    }
}

// custom exception class that inherits from Exception
class BookException : Exception
{
    // constructor that takes in arguments and calls the base constructor with a formatted message
    public BookException(string title, double price, int numPages) //data type changed
        : base("For " + title + ", ratio is invalid....Price is $" + price + " for " + numPages + " pages.")
    {
    }
}

class BookExceptionDemo
{
    static void Main()
    {
        // create an array of Book objects
        Book[] books = new Book[5];

        // prompt the user to enter information for each book and create a new Book object
        for (int i = 0; i < 5; i++)
        {
            string title = Console.ReadLine();
            string author = Console.ReadLine();
            double price = double.Parse(Console.ReadLine());
            int numPages = int.Parse(Console.ReadLine());

            books[i] = new Book(title, author, price, numPages);
        }

        // print out each Book object using the overridden ToString method
        foreach (Book book in books)
        {
            Console.WriteLine(book);
        }
    }
}
Results Ⓒ
For Book2, ratio is invalid.
...Price is $19.99 for 100 pages.
For Book4, ratio is invalid.
...Price is $5.00 for 20 pages.
Show Details
es.
es.
es.
Transcribed Image Text:Results Ⓒ For Book2, ratio is invalid. ...Price is $19.99 for 100 pages. For Book4, ratio is invalid. ...Price is $5.00 for 20 pages. Show Details es. es. es.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education