Create a windows application for a library which will request the user to input the number of books checked out and the number of days they are overdue. Your program should then calculate and displays the library fine, which is 20 cents per book per day for the first seven days a book is overdue, then 50 cents per book per day for each additional day.
Note: when submitting your solution to this task, you will also need to include an image of your form (interface) design.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LibraryWindowsFormsApplication
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
/// <summary>
/// Calculate button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bntCalculate_Click(object sender, EventArgs e)
{
int numberBooks;
int.TryParse(txtNumberBooks.Text, out numberBooks);
int daysOverdue;
int.TryParse(txtDaysOverdue.Text, out daysOverdue);
//calculate and displays the library fine, which is 20 cents per book per day
//for the first seven days a book is overdue, then 50 cents per book per day for each additional day.
double libraryFine = 0.2* daysOverdue * numberBooks;
if (daysOverdue > 7) {
libraryFine =(0.2* 7 * numberBooks)+ 0.5 * (daysOverdue-7) * numberBooks;
}
txtLibraryFine.Text = libraryFine.ToString("N");
}
}
}
namespace LibraryWindowsFormsApplication
{
partial class frmMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.txtNumberBooks = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtDaysOverdue = new System.Windows.Forms.TextBox();
this.bntCalculate = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.txtLibraryFine = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(198, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Enter the number of books checked out:";
//
// txtNumberBooks
//
this.txtNumberBooks.Location = new System.Drawing.Point(231, 21);
this.txtNumberBooks.Name = "txtNumberBooks";
this.txtNumberBooks.Size = new System.Drawing.Size(100, 20);
this.txtNumberBooks.TabIndex = 1;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 50);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(211, 13);
this.label2.TabIndex = 0;
this.label2.Text = "Enter the number of days they are overdue:";
//
// txtDaysOverdue
//
this.txtDaysOverdue.Location = new System.Drawing.Point(231, 47);
this.txtDaysOverdue.Name = "txtDaysOverdue";
this.txtDaysOverdue.Size = new System.Drawing.Size(100, 20);
this.txtDaysOverdue.TabIndex = 1;
//
// bntCalculate
//
this.bntCalculate.Location = new System.Drawing.Point(231, 109);
this.bntCalculate.Name = "bntCalculate";
this.bntCalculate.Size = new System.Drawing.Size(100, 23);
this.bntCalculate.TabIndex = 2;
this.bntCalculate.Text = "Calculate";
this.bntCalculate.UseVisualStyleBackColor = true;
this.bntCalculate.Click += new System.EventHandler(this.bntCalculate_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 76);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(79, 13);
this.label3.TabIndex = 0;
this.label3.Text = "The library fine:";
//
// txtLibraryFine
//
this.txtLibraryFine.Location = new System.Drawing.Point(231, 73);
this.txtLibraryFine.Name = "txtLibraryFine";
this.txtLibraryFine.ReadOnly = true;
this.txtLibraryFine.Size = new System.Drawing.Size(100, 20);
this.txtLibraryFine.TabIndex = 1;
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(356, 155);
this.Controls.Add(this.bntCalculate);
this.Controls.Add(this.txtLibraryFine);
this.Controls.Add(this.label3);
this.Controls.Add(this.txtDaysOverdue);
this.Controls.Add(this.label2);
this.Controls.Add(this.txtNumberBooks);
this.Controls.Add(this.label1);
this.Name = "frmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Library program";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtNumberBooks;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtDaysOverdue;
private System.Windows.Forms.Button bntCalculate;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtLibraryFine;
}
}
Comments
Leave a comment