タイトルがこれに合っているかどうかは完全にはわかりません。これを行う方法を示すビデオがあると思われますが、私の人生では、ピアソンのWebサイトから生徒のファイルをダウンロードする方法がわかりません。以下は私が取り組んでいる問題です。
Employee クラスと ProductionWorker クラス
次のデータのプロパティを持つ Employee クラスを作成します。
- 従業員名
- 従業員番号
次に、Employee クラスから派生した ProductionWorker という名前のクラスを作成します。ProudctionWorker クラスには、次のデータを保持するためのプロパティが必要です。
- シフト番号 (1、2、3 などの整数)
- 時給
勤務日は、昼と夜の 2 シフトに分かれています。Shift プロパティは、従業員が勤務するシフトを表す整数値を保持します。日勤が1番、夜勤が2番です。
ProductionWorker クラスのオブジェクトを作成し、ユーザーがオブジェクトの各プロパティのデータを入力できるようにするアプリケーションを作成します。オブジェクトのプロパティを取得し、その値を表示します。
これが私が取り組んでいるコードです:
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 classes
{
public partial class frmMainClasses : Form
{
string EmpShift = "";
string EmployeeName = "";
int EmployeeNumber = 0;
float HourlyPayRate = 0;
public class Employee
{
public string EmployeeName { get; set; }
public int EmployeeNumber { get; set; }
}
public class ProductionWorker : Employee
{
public float HourlyPayRate { get; set; }
public Shift Shift { get; set; }
}
public enum Shift
{
Day = 1,
Night = 2
}
public frmMainClasses()
{
InitializeComponent();
}
private void btxExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnGetInfo_Click(object sender, EventArgs e)
{
string EmpShift = "";
ProductionWorker productionWorker = new ProductionWorker();
productionWorker.EmployeeName = txtName.ToString();
EmployeeName = productionWorker.EmployeeName; //Added mostly because I couldn't get EmployeeName to show anything in the messagebox
productionWorker.EmployeeNumber = Convert.ToInt32(txtIdNumb.text);
productionWorker.HourlyPayRate = Convert.ToInt32(txtPay.text);
EmpShift = Convert.ToString(txtShift.text);
txtName.Text = "";
txtIdNumb.Text = "";
txtPay.Text = "";
txtShift.Text = "";
}
private void btnShow_Click(object sender, EventArgs e)
{
MessageBox.Show("Name " + EmployeeName + "IDNumber " + EmployeeNumber + "Hourly rate " + txtPay + "Shift " + txtShift);
}
}
}
コード自体はエラーを表示していませんが、実行しようとすると次のようになります。
文字列 EmpShift がそこにあるのは、シフトコードを操作する方法がわからなかったからです。多かれ少なかれ、それを指で示すまでプレースホルダーとして使用しています。問題を解決する方法がわかりません。うまくいけば、小さな間違いです。
commets の助けのおかげで、最初に抱えていた問題を修正できましたが、今では最後のメッセージ ボックスに問題があります。私が入力した情報は、名前に Glitter、ID 番号に 12、シフトに 1、支払いに 12 です。その表示内容は次のとおりです。
名前 System.Windows.Forms.TextBox, Text: GlitterIDNumber 0Hourly rate System.Windows.Forms.TextBox, Text: Shift SystemWindowsForm.TextBox, Text: