Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1038533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:59:13+00:00 2026-05-16T14:59:13+00:00

I’m trying to make a program that check the ISBN number and sees if

  • 0

I’m trying to make a program that check the ISBN number and sees if it has the correct check digit, if it doesn’t have the check digit it will add one. I have an Idea of how it will work I just cant figure out how to code for it as in the classes inheriting from each other.
This is an in class example that is not going to be graded it is just to familiarize us with getting our designs to a working program. here’s what I have so far mind you this is a simple console program.

alt text

Code Updated

public class isbn
{   //attributes
     private string isbnNum;
     //method   
     public string GetIsbn()
     {
         return this.isbnNum;
     }
       //constructor
       public isbn()
       {
           Console.Write("Enter Your ISBN Number: ");
           this.isbnNum = Console.ReadLine();

       }//end default constructor

        //method
       public string displayISBN()
       {

           return  this.GetIsbn();

       }


   public static void Main(string[] args)
    {
        //create a new instance of the ISBN/book class

        isbn myFavoriteBook = new isbn();

        //contains the method for checking validity 
        bool isValid = CheckDigit.CheckIsbn(myFavoriteBook.GetIsbn());

        //print out the results of the validity.
        Console.WriteLine(string.Format("Your book {0} a valid ISBN",
                                   isValid ? "has" : "doesn't have"));

        Console.ReadLine();

    }//end main

This is the check digit code the professor provided in class we just have to mesh it up to get it to work. I know this goes in the check digit class what I don’t know is how to incorporate it into code.

Code Updated

 public static class CheckDigit
{       // attributes
    public static string NormalizeIsbn(string isbn)
    {
        return isbn.Replace("-", "").Replace(" ", "");
    }
   public static bool CheckIsbn(string isbn) // formula to check ISBN's validity
    {
        if (isbn == null)
            return false;

        isbn = NormalizeIsbn (isbn);
        if (isbn.Length != 10)
            return false;

        int result;
        for (int i = 0; i < 9; i++)
            if (!int.TryParse(isbn[i].ToString(), out result))
                return false;

        int sum = 0;
        for (int i = 0; i < 9; i++)
            sum += (i + 1) * int.Parse(isbn[i].ToString());

        int remainder = sum % 11;
        if (remainder == 10)
            return isbn[9] == 'X';
        else
            return isbn[9] == (char)('0' + remainder);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:59:14+00:00Added an answer on May 16, 2026 at 2:59 pm

    It sounds like the class CheckDigit is the business rules validator for ISBN numbers.

    In that case:

    public static class CheckDigit
    {
        public static bool CheckIsbn(string isbn)
        { 
           //implementation as in your question.
        }
    }
    

    Now write a new application (here it’s a console app) that uses both of your classes.

    class MyConsoleApp
    {
        static void Main(string[] args)
        {
            //create a new instance of the ISBN/book class. you're prompted as part
            //of the constructor.
            isbn myFavoriteBook = new isbn();
    
            //new class contains the method for checking validity 
            bool isValid = CheckDigit.CheckIsbn(myFavoriteBook.GetIsbn());
    
            //write out the results of the validity.
            Console.WriteLine(string.Format("Your book {0} a valid ISBN", 
                                       isValid ? "has" : "doesn't have"));
    
            Console.ReadLine();
        }
    }
    

    Here’s what’s happening:

    • we create a new instance of isbn/book. Its constructor has the Console.Readline command to ask the user for input. It then stores the user’s entry into this.isbnNum.
    • our new static class CheckDigit is simply a validator of any given string. It determines whether the argument sent is a valid ISBN number. It’ll return a bool. We sent it the isbn.GetIsbn(), which is what the user entered.
    • the bool returned from the CheckIsbn() is displayed nicely in a sentence for the user in the console.

    So really there are 2 main classes – isbn and the CheckDigit. The other Main(string[] args) can be removed from your code.

    Here’s the entire console app in one file. Paste into your application, and you can see what’s happening.

    Is that the help you were looking for? Either way, leave a comment, and we can get it sorted out for you.

    Updates:

    • The CheckIsbn really only does 1 thing – returns whether the 9th character is an X or some other number. It doesn’t modify the ISBN from the user, as it stands today. If you wanted to maintain that formatting (removing dashes, spaces), and otherwise modify the input ISBN, then you could specify the ISBN as an out parameter.

    Redefine your method like this if you want the ISBN entered by the user, to retain any changes made within the method CheckIsbn:

    public static bool CheckIsbn(out string isbn) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.