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 1064775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:43:10+00:00 2026-05-16T19:43:10+00:00

The program works in its current for but I would like to make it

  • 0

The program works in its current for but I would like to make it more object oriented like its design using constructors and such but I don’t know where to start and how to make it work. I would like your insight and examples on how you would accomplish this task? Here is a sample UML for what I am trying to do.
UML

Original Design

  public static class IsbnConsole
{
   public static void Main(string[] args)
    {
        Console.Write("Enter a valid 10 digit ISBN Number ");
        string isbn = checkIsbnClass.DestabilizeIsbn(Console.ReadLine()); // Normalizes the input and puts it on string "str"
        if (isbn.Length > 10 || isbn.Length < 9) // If the string length is greather than 10, or smaller than 9
        {
            Console.WriteLine("The number you have entered is not a valid ISBN try again."); // Print invalid number
            Console.ReadLine();
        }
        else if (isbn.Length == 10) // If the length is 10
        {
            if (checkIsbnClass.CheckNumber(isbn)) // If function CheckNum return "true"...
                Console.WriteLine("The number you have entered is a Valid ISBN");

            else // If it returns "false"...
                Console.WriteLine("The number you have entered is not a valid ISBN try again.");
                Console.ReadLine();
        }
        else // Else (If the number is NOT greater than 10 or smaller than 9, NOR is it 10 -> If the number is 9)
        {
            Console.WriteLine("The Check digit that corresponds to this ISBN number is " + checkIsbnClass.CheckIsbn(isbn) + "."); // Print the checksum digit
            Console.ReadLine();
        }

  public static class checkIsbnClass
{ 

public static string CheckIsbn(string isbn) // Calculates the 10th digit of a 9-digits partial ISBN number
    {
        int sum = 0;
        for (int i = 0; i < 9; i++) // For each number...
        {
            sum += int.Parse(isbn[i].ToString()) * (i + 1); // ...Multiply the number by it's location in the string
        }
        if ((sum % 11) == 10) // If the remainder equals to 10...
        {
            return "x"; // Output X
        }
        else // If it does not equal to 10...
        {
            return (sum % 11).ToString(); // Output the number
        }
    }
  public static bool CheckNumber(string isbn) // Checks if the checksum digit is correct
    {
        if (isbn[9].ToString() == CheckIsbn(isbn)) // If the 10th digit of the number is the same as the calculated digit...
            return true;
        else // If they're not the same...
            return false;
    }
  public static string DestabilizeIsbn(string isbn) // replace the string
  {
      return isbn.Replace("-", "").Replace(" ", "");
  }

Newly Designed Method Using Constructors

   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();

        }

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-16T19:43:11+00:00Added an answer on May 16, 2026 at 7:43 pm
    public static class IsbnConsole 
    { 
       public static void Main(string[] args) 
        { 
            Console.Write("Enter a valid 10 digit ISBN Number "); 
            string isbn = checkIsbnClass.DestabilizeIsbn(Console.ReadLine()); // Normalizes the input and puts it on string "str" 
    
            Isbn isbn = new Isbn(Console.In)
            if (!isbn.CheckLength())   
                Console.WriteLine("The number you have entered is not a valid ISBN try again."); // Print invalid number 
            } 
            else if (isbn.HasCheckDigit)
            { 
                if (isbn.CheckNumber(isbn)) 
                    Console.WriteLine("The number you have entered is a Valid ISBN"); 
                else
                    Console.WriteLine("The number you have entered is not a valid ISBN try again."); // Print invalid number 
            } 
            else 
            { 
                Console.WriteLine("The Check digit that corresponds to this ISBN number is " + isbn.GetCheckDigit(isbn) + "."); // Print the checksum digit 
            } 
            Console.ReadLine(); 
    }
    
    public class Isbn
    {
       public Isbn(TextReader cin)
       {
            /// do stuff here.
       }
    
       public bool CheckLength()
       {
            /// do stuff here.
       }
    
       public bool HasCheckDigit {  get {    ..... } }
       public int  GetCheckDigit() {..... }
       public bool CheckNumber() {......}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a Python program using PIL to render text, and it works great
I am looking for a good, free (preferred) screen sharing program that works well
When I run the program from IDE (VS2008) it works perfectly. When I want
This is a good candidate for the Works on My Machine Certification Program .
The example program below compiles two in-memory assemblies. The first compilation works fine. The
I am writing somewhat of a proxy program in Java. Here's how it works:
I need my program to work only with certain USB Flash drives (from a
A program that I work on assumes that the UUID generated by the Windows
I work on a program in Delphi that holds a lot of data, and
I'm starting work on a program which is perhaps most naturally described as a

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.