Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
QuestionHow autoconnect shapes in Canvas WPF Pin
Newbee_Mark30-Mar-21 23:54
Newbee_Mark30-Mar-21 23:54 
AnswerRe: How autoconnect shapes in Canvas WPF Pin
Gerry Schmitz31-Mar-21 7:33
mveGerry Schmitz31-Mar-21 7:33 
GeneralRe: How autoconnect shapes in Canvas WPF Pin
Newbee_Mark31-Mar-21 7:37
Newbee_Mark31-Mar-21 7:37 
GeneralRe: How autoconnect shapes in Canvas WPF Pin
Gerry Schmitz31-Mar-21 14:57
mveGerry Schmitz31-Mar-21 14:57 
GeneralRe: How autoconnect shapes in Canvas WPF Pin
Newbee_Mark31-Mar-21 23:40
Newbee_Mark31-Mar-21 23:40 
GeneralRe: How autoconnect shapes in Canvas WPF Pin
Gerry Schmitz1-Apr-21 6:24
mveGerry Schmitz1-Apr-21 6:24 
GeneralRe: How autoconnect shapes in Canvas WPF Pin
Newbee_Mark1-Apr-21 22:54
Newbee_Mark1-Apr-21 22:54 
QuestionList not printing out hardcoded books already added to list Pin
Member 1451443230-Mar-21 12:14
Member 1451443230-Mar-21 12:14 
Hi, I'm trying to make a library where you can add books, search for books etc, I have a hardcoded book that you should be able to search for but it only displays the after I add a new book and then it will display the hardcoded book if you search for it again

the code

public class Book
    {
        public String BookName { get; set; }
        public String AuthorName { get; set; }
        public int NumberOfCopiesInStock { get; set; }
        public String ISBN { get; set; }

        public Book(String bookName, String authorName, int numberOfCopiesInStock, String isbn)
        {
            this.BookName = bookName;
            this.AuthorName = authorName;
            this.NumberOfCopiesInStock = numberOfCopiesInStock;
            this.ISBN = isbn;
        }

        public override String ToString()
        {
            return ("BookName: " + BookName
                  + "\n"
                  + "Author Name: " + AuthorName
                  + "\n"
                  + "Number Of Copies: " + NumberOfCopiesInStock
                  + "\n"
                  + "ISBN: " + ISBN);
        }
    }


C#
public class Search
    {
        public Boolean SearchForBook()
        {
            Console.WriteLine("Please enter name of book: ");
            String search = Console.ReadLine();
            UserInput.MakeTheComputerSleep();
            foreach (Book b in UserInput.bookList)
            {
                if (b.BookName.Equals(search))
                {
                    Console.WriteLine(b);
                    return true;
                }
            }
            Console.WriteLine("Book doesn't exist! ");
            return false;
        }
    }



C#
<pre>public class UserInput
    {
        public static Boolean KeepGoing = true;
        public static List<Book> bookList = new List<Book>();
        private static readonly String INPUT_ERROR_MESSAGE = "Please only enter NUMBERS!";
        private static readonly String INVALID_CHOICE = "INVALID CHOICE ENTERED!";
        private static readonly String SEARCH_MESSAGE = "Searching for book,please wait......";
        private static Random RandomObject = new Random();

        public static void WelcomeMessage()
        {
            Console.WriteLine("********************");
            Console.WriteLine("*       Cork       *");
            Console.WriteLine("*      Library     *");
            Console.WriteLine("********************");
        }

        private static void MenuHeader()
        {
            Console.WriteLine("********************");
            Console.WriteLine("*       Menu       *");
            Console.WriteLine("*      Options     *");
            Console.WriteLine("********************");
        }

        private static void MenuOptions()
        {
            Console.WriteLine("1.) Add Book.             ");
            Console.WriteLine("2.) Search for Book.      ");
            Console.WriteLine("3.) Delete Book.          ");
            Console.WriteLine("4.) Display all Book.     ");
            Console.WriteLine("0.) Exit.                 ");
        }

        public static void GetUserInput()
        {
            int choice;
            MenuHeader();
            do
            {
                MenuOptions();
                Console.WriteLine(">");
                choice = 0;
                while (!int.TryParse(Console.ReadLine(), out choice))
                {
                    Console.WriteLine(INPUT_ERROR_MESSAGE);
                }
                PickChoice(choice);
            } while (choice != 0);
        }

        private static void PickChoice(int choice)
        {
            switch (choice)
            {
                case 1:
                    AddBook addBook = new AddBook();
                    addBook.EnterBookInfo();
                    break;

                case 2:
                    Search search = new Search();
                    search.SearchForBook();
                    break;

                case 3:
                    break;

                case 4:
                    
                    AddBook addBook1 = new AddBook();
                    addBook1.PrintListOfBooks();
                    break;

                case 0:
                    Exit exit = new Exit();
                    exit.Exit_Application();
                    break;

                default:
                    Console.WriteLine(INVALID_CHOICE);
                    break;
            }
        }

        public static void MakeTheComputerSleep()
        {
            int number = RandomObject.Next(10) + 1;
            Console.WriteLine("Searching for Book.......");
            Thread.Sleep(number * 1000);
        }

        
    }



C#
public class AddBook
    {
        public void EnterBookInfo()
        {
            while (UserInput.KeepGoing)
            {

                Console.WriteLine("Please enter name of book: ");
                String BookName = Console.ReadLine();

                if (BookName.Equals("end"))
                {
                    break;
                }

                Console.WriteLine("Please enter Author Name: ");
                String AuthorName = Console.ReadLine();

                Console.WriteLine("Please enter ISBN Number: ");
                String ISBN = Console.ReadLine();

                Console.WriteLine("Please enter number of books: ");
                int NumberOfCopiesInStock = Convert.ToInt32(Console.ReadLine());

                Book book1 = new Book("Neverwhere", "Neil Gaimen", 1, "aaaaa");
                Book book = new Book(BookName, AuthorName, NumberOfCopiesInStock, ISBN);
                UserInput.bookList.Add(book);
                UserInput.bookList.Add(book1);

            }

        }

        public void PrintListOfBooks()
        {
            foreach (Book b in UserInput.bookList)
            {
                Console.WriteLine(b.ToString());
                Console.WriteLine();
            }
        }
    }



C#
class Program
    {
        public static void Main(string[] args)
        {
            UserInput.WelcomeMessage();
            UserInput.GetUserInput();
        }
    }



any help at all would be appreciated , thanks.
AnswerRe: List not printing out hardcoded books already added to list Pin
Dave Kreskowiak30-Mar-21 14:03
mveDave Kreskowiak30-Mar-21 14:03 
GeneralRe: List not printing out hardcoded books already added to list Pin
Member 1451443231-Mar-21 10:27
Member 1451443231-Mar-21 10:27 
GeneralRe: List not printing out hardcoded books already added to list Pin
Dave Kreskowiak31-Mar-21 10:33
mveDave Kreskowiak31-Mar-21 10:33 
GeneralRe: List not printing out hardcoded books already added to list Pin
Member 1451443231-Mar-21 10:43
Member 1451443231-Mar-21 10:43 
QuestionHow to convert a column of DataTable into integer values? Pin
Alex Dunlop29-Mar-21 5:30
Alex Dunlop29-Mar-21 5:30 
AnswerRe: How to convert a column of DataTable into integer values? Pin
Richard Deeming29-Mar-21 5:42
mveRichard Deeming29-Mar-21 5:42 
AnswerRe: How to convert a column of DataTable into integer values? Pin
Mycroft Holmes29-Mar-21 20:21
professionalMycroft Holmes29-Mar-21 20:21 
AnswerRe: How to convert a column of DataTable into integer values? Pin
Arfat M1-Apr-21 19:58
Arfat M1-Apr-21 19:58 
GeneralRe: How to convert a column of DataTable into integer values? Pin
Richard Deeming6-Apr-21 0:06
mveRichard Deeming6-Apr-21 0:06 
GeneralChanging value in variable from another called class Pin
StealthRT28-Mar-21 17:26
StealthRT28-Mar-21 17:26 
GeneralRe: Changing value in variable from another called class Pin
Richard Deeming28-Mar-21 22:15
mveRichard Deeming28-Mar-21 22:15 
QuestionHow to detect user email address when user clicks on a link sent to their email? Pin
Zeyad Jalil28-Mar-21 1:44
professionalZeyad Jalil28-Mar-21 1:44 
AnswerRe: How to detect user email address when user clicks on a link sent to their email? Pin
Dave Kreskowiak28-Mar-21 8:20
mveDave Kreskowiak28-Mar-21 8:20 
AnswerRe: How to detect user email address when user clicks on a link sent to their email? Pin
OriginalGriff28-Mar-21 9:59
mveOriginalGriff28-Mar-21 9:59 
AnswerRe: How to detect user email address when user clicks on a link sent to their email? Pin
Richard Deeming28-Mar-21 22:04
mveRichard Deeming28-Mar-21 22:04 
QuestionHow to access cell information and controls of DevExpress Spreadsheet Form from another form in the same application? Pin
Alex Dunlop25-Mar-21 2:43
Alex Dunlop25-Mar-21 2:43 
AnswerRe: How to access cell information and controls of DevExpress Spreadsheet Form from another form in the same application? Pin
OriginalGriff25-Mar-21 5:03
mveOriginalGriff25-Mar-21 5:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.