Question

In: Computer Science

Create a C# application for Library that allows you to enter data for books and saves...

Create a C# application for Library that allows you to enter data for books and saves the data to a file named Books.txt. Create a Book class that contains fields for title, author, number of pages, and price of the book and ToString() method. The fields of records in the file are separated with asterisk (*). Expecting sentinel value for ending the process of writing to file is "000"

Solutions

Expert Solution

Application Name :LibraryDemo

Application type :Console Application

Language used:C#

IDE used :Visual Studio 2019

Program.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
//application namespace
namespace LibraryDemo
{
class Program //C# class
{
//Main() method
static void Main(string[] args)
{
//creating object of
StreamWriter streamWriter = new StreamWriter("Books.txt");
//Creating obejct of Book class
Book book = new Book();
while (true)
{
//asking user book title
Console.Write("Enter book title: ");
//reading book title
string bookTitle = Console.ReadLine();
//checking boomTitle
if (bookTitle == "000")
{
//when book title is 000 then break while loop
Console.WriteLine("Books written to the file.");
break;
}
else
{
book.Title = bookTitle;
//asking user book author
Console.Write("Enter book author: ");
//reading book author
book.Author = Console.ReadLine();
//asking user number of pages
Console.Write("Enter number of pages: ");
//reading number of pages
book.NumberOfPages = int.Parse(Console.ReadLine());
//asking user price
Console.Write("Enter book price: ");
//reading book price
book.Price = double.Parse(Console.ReadLine());
//call toString() method on Book and write to the file
streamWriter.WriteLine(book.ToString());
}
}
streamWriter.Close();//close streamWriter
//to hold the screen
Console.ReadKey();
}
}
//C# Book class
class Book
{
private string title;
private string author;
private int numberOfPages;
private double price;
//getter and setter methods
public string Title
{
get { return title; }
set
{
this.title = value;
}
}
public string Author
{
get { return author; }
set
{
this.author = value;
}
}
public int NumberOfPages
{
get { return numberOfPages; }
set
{
this.numberOfPages = value;
}
}
public double Price
{
get { return price; }
set
{
this.price = value;
}
}
//method ToString()
public string ToString()
{
return title + "*" + author + "*" + numberOfPages.ToString() + "*" + price.ToString();
}
}
}

==============================================

Screen showing output :

Screen showing books.txt :


Related Solutions

Create a C# application for Cricket Team that allows you to enter data for player of...
Create a C# application for Cricket Team that allows you to enter data for player of Cricket Team and saves the data to a file named Players.txt. Create a Player class that contains fields for of participant's first name, last name, age, salary and position (wicketkeeper, bawler, striker, midwicket), and To String() method. The fields of records in the file are separated with semicolon (. Expecting sentinel value for ending the process of writing to file is *. E.g. of...
Create an application that allows the user to enter the total for an order and the...
Create an application that allows the user to enter the total for an order and the name of the customer. If the order is less than 500 dollars, the customer gets no discount. If the order is greater than or equal to 500 and less than 1000 dollars, the customer gets a 5 percent discount. If the order is greater than or equal to 1000 dollars, the customer gets a 10 percent discount. The application should display the name of...
Show: Create an application that allows the user to enter the number of calories and fat...
Show: Create an application that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *9 The percentage of...
Android Studio. Java. Please create an application that -> An activity that allows user to enter...
Android Studio. Java. Please create an application that -> An activity that allows user to enter name, gender, date of birth, state of residence (selected from a pre-defined list: CA, AZ, NV, OR), email address and favorite website. This activity has a button "Show Data" that displays detail entered
Write a C++ console application that allows your user to enter the total rainfall for each...
Write a C++ console application that allows your user to enter the total rainfall for each of 12 months into an array of doubles. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts.
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *...
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
Library Management System allows the user to borrow and return the books. The book is identified...
Library Management System allows the user to borrow and return the books. The book is identified by book name, accession number, item category, due date, due time, and status. Before the user proceeds to borrow or return the books, they need to register for an account. Each user can have only one account. The user can be a staff or student. Each user is identified by ID number, name, school/department name, address. The books are arranged on a shelf. The...
C# Create an application that asks the user to enter their new password. The password must...
C# Create an application that asks the user to enter their new password. The password must be at least 6 characters long. Develop a custom exception handling case that checks for the password length. (hint: use " .Length " built-in method). If the new password is less than 6 characters long the custom exception should output an error message.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT