Beginner...need help with exception statements.

Ok, I have written the blocks of code the assignment asked for to the best of my knowledge. The IDE I am using is called Replit, which is where the Lab for my class is administered. Still, it is showing two exceptions for dividing with 0, Book does not contain a constructor that takes 0 arguments.

and the build needs to be fixed....

using System;

class Program { public static void Main (string[] args) { Console.WriteLine(20/2); // After completing Step 1, you should be able to uncomment this line. Console.WriteLine(20/0); MyMath.Divide(20/0);

Book book1 = new Book();
book1.Display();

 //After completing steps 2 and 3 below, you should be able to uncomment the following lines:

Book book2 = new Book("0-201-03801-3", "The Art of Computer Programming");
book2.author = "Donald Knuth";
book2.year = 1968;
book2.Display();

Book book3 = new Book("0-13-937681-X", "The UNIX Prgramming Environment", "Rob Pike", 1984);
book3.Display();

} }

class MyMath {

// Step 1 - Add exception handling to make sure dividing by 0 does not crash the program. public static double Divide(double a, double b) { try { double result = a / b; return result; } catch (DivideByZeroException e) { Console.WriteLine(e.Message); return 0; } } }

class Book { private string isbn; private string title; public string author; public int year;

public Book(string ISBN, string Title) { isbn = ISBN; title = Title; }

// Step 2 - add a constructor method that accepts 2 parameters: isbn and title. Assign the parameters values to the class properties. public Book(string ISBN, string Title, string Author, int Year) { isbn = ISBN; title = Title; author = Author; year = Year; } // Step 3 - add a constructor method that accepts 4 parameters (isbn, title, author, year) and assigns values to all of the properties of the class. Assign the parameters values to the class properties.

public void Display() { Console.WriteLine($"Book: {isbn}\n{title}\n{author}\n{year}"); } }

/r/csharp Thread Parent