Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# please help Create a public interface named IDisplayable. Then, add the declaration for a method named GetDisplayText with no parameters and a string return

C# please help

  1. Create a public interface named IDisplayable. Then, add the declaration for a method named GetDisplayText with no parameters and a string return value.
  2. Display the code for the InvItem class, and copy the statement in the GetDisplayText method that this class contains. Then, delete this method.
  3. Modify the declaration for the class to indicate that it implements the IDisplayable interface. Then, generate a stub for the GetDisplayText method that this interface defines.
  4. Modify the declaration for the GetDisplayText method so it can be overridden. Then, replace the generated throw statement with the statement you copied from the original GetDisplayText method in step 3.

========

frmInvMaint.cs

=========

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

namespace InventoryMaintenance { public partial class frmInvMaint : Form { public frmInvMaint() { InitializeComponent(); }

private InvItemList invItems = new InvItemList();

private void frmInvMaint_Load(object sender, EventArgs e) { invItems.Changed += new InvItemList.ChangeHandler(HandleChange); invItems.Fill(); FillItemListBox(); }

private void FillItemListBox() { InvItem item; lstItems.Items.Clear(); for (int i = 0; i < invItems.Count; i++) { item = invItems[i]; lstItems.Items.Add(item.GetDisplayText()); } }

private void btnAdd_Click(object sender, EventArgs e) { frmNewItem newItemForm = new frmNewItem(); InvItem invItem = newItemForm.GetNewItem(); if (invItem != null) { invItems += invItem; } }

private void btnDelete_Click(object sender, EventArgs e) { int i = lstItems.SelectedIndex; if (i != -1) { InvItem invItem = invItems[i]; string message = "Are you sure you want to delete " + invItem.Description + "?"; DialogResult button = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo); if (button == DialogResult.Yes) { invItems -= invItem; } } }

private void btnExit_Click(object sender, EventArgs e) { this.Close(); }

private void HandleChange(InvItemList invItems) { invItems.Save(); FillItemListBox(); } } }

===========

frmNewItem.cs

===========

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

namespace InventoryMaintenance { public partial class frmNewItem : Form { public frmNewItem() { InitializeComponent(); }

private InvItem invItem = null;

public InvItem GetNewItem() { LoadComboBox(); this.ShowDialog(); return invItem; }

private void LoadComboBox() { cboSizeOrManufacturer.Items.Clear(); if (rdoPlant.Checked) { cboSizeOrManufacturer.Items.Add("1 gallon"); cboSizeOrManufacturer.Items.Add("5 gallon"); cboSizeOrManufacturer.Items.Add("15 gallon"); cboSizeOrManufacturer.Items.Add("24-inch box"); cboSizeOrManufacturer.Items.Add("36-inch box"); } else { cboSizeOrManufacturer.Items.Add("Bayer"); cboSizeOrManufacturer.Items.Add("Jobe's"); cboSizeOrManufacturer.Items.Add("Ortho"); cboSizeOrManufacturer.Items.Add("Roundup"); cboSizeOrManufacturer.Items.Add("Scotts"); } }

private void btnSave_Click(object sender, EventArgs e) { if (IsValidData()) { invItem = new InvItem(Convert.ToInt32(txtItemNo.Text), txtDescription.Text, Convert.ToDecimal(txtPrice.Text)); this.Close(); } }

private bool IsValidData() { return Validator.IsPresent(txtItemNo) && Validator.IsInt32(txtItemNo) && Validator.IsPresent(txtDescription) && Validator.IsPresent(txtPrice) && Validator.IsDecimal(txtPrice); }

private void btnCancel_Click(object sender, EventArgs e) { this.Close(); }

private void rdoPlant_CheckedChanged(object sender, EventArgs e) { if (rdoPlant.Checked) { lblSizeOrManufacturer.Text = "Size:"; } else { lblSizeOrManufacturer.Text = "Manufacturer:"; } LoadComboBox(); } } }

=======

InvItem.cs

==========

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace InventoryMaintenance { public class InvItem { private int itemNo; private string description; private decimal price;

public InvItem() { }

public InvItem(int itemNo, string description, decimal price) { this.itemNo = itemNo; this.description = description; this.price = price; }

public int ItemNo { get { return itemNo; } set { itemNo = value; } }

public string Description { get { return description; } set { description = value; } }

public decimal Price { get { return price; } set { price = value; } }

public virtual string GetDisplayText() => itemNo + " " + description + " (" + price.ToString("c") + ")"; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe the basic components of a wireless LAN.

Answered: 1 week ago

Question

Explain all drawbacks of the application procedure.

Answered: 1 week ago

Question

Determine Leading or Lagging Power Factor in Python.

Answered: 1 week ago

Question

understand the key issues concerning international assignments

Answered: 1 week ago