Page 1 of 1

Use C# Visual Studio. Have complete codes and screenshots. Thank you! C# Create a new project, and add the Transaction C

Posted: Sat May 14, 2022 3:54 pm
by answerhappygod
Use C# Visual Studio. Have complete codes and
screenshots. Thank you!
C#
Create a new project, and add the Transaction Class from
Homework #6, making any corrections identified in class or your
homework feedback. Create a new class named TransactionList to
manage the entered transactions, using a list to store the values.
Include the following capabilities in TransactionList:
Create a form with the following:
Use C Visual Studio Have Complete Codes And Screenshots Thank You C Create A New Project And Add The Transaction C 1
Use C Visual Studio Have Complete Codes And Screenshots Thank You C Create A New Project And Add The Transaction C 1 (11.38 KiB) Viewed 68 times
Here is the transaction.cs in homework #6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Homework6V2
{
public enum TransactionTypes { Deposit, ServiceFee, Withdrawal
}
public class Transaction
{
private string payee, checkNumber;
private decimal amount;
private DateTime transactionDate;
private TransactionTypes transactionType;
// constructor has no payee so if a withdrawal, throw
exception
public Transaction(decimal Amount, DateTime TransactionDate,
TransactionTypes TransactionType)
{
if (TransactionType == TransactionTypes.Withdrawal)
throw new ApplicationException("Payee required for
withdrawal");
this.TransactionAmount = Amount;
this.TransactionDate = TransactionDate;
this.TransactionType = TransactionType;
// default payee to type
this.Payee = TransactionType.ToString();
}
// overloaded constructor for withdrawal or additional values
for fee or deposit
public Transaction(decimal Amount, DateTime TransactionDate,
TransactionTypes TransactionType, string Payee)
{
SetupInstance(Amount, TransactionDate, TransactionType,
Payee);
}
public Transaction(decimal Amount, DateTime
TransactionDate,
TransactionTypes TransactionType, string Payee,
string CheckNumber)
{
SetupInstance(Amount, TransactionDate, TransactionType,
Payee);
this.CheckNumber = CheckNumber;
}
// if it's a withdrawal and payee is empty, there's a
problem
private void SetupInstance(decimal Amount, DateTime Date,
TransactionTypes Type, string Payee)
{
if (Type == TransactionTypes.Withdrawal && Payee ==
"")
throw new ApplicationException("Withdrawal requires a
payee");
this.TransactionAmount = Amount;
this.TransactionDate = Date;
this.TransactionType = Type;
if (Payee != "")
this.Payee = Payee;
else
this.Payee = Type.ToString();
}

public decimal TransactionAmount
{
get { return amount; }
set
{
if (IsValidAmount(value))
amount = value;
else
throw new ApplicationException("Invalid amount");
}
}
public static bool IsValidAmount(decimal entry)
{
return entry > 0;
}
public DateTime TransactionDate
{
get { return transactionDate; }
set
{
transactionDate = value;
}
}
public static bool IsValidDate(string entry)
{
DateTime date;
return DateTime.TryParse(entry, out date);
}
// by making this read/write, we create a potential problem
IF
// we allowed an update to an existing transaction...
// someone could make this a withdrawal, but
// we don't know if there's a payee or not WITHIN the set
block.
// and we can't read the payee property within the set block
because
// payee may be changed AFTER we accept a type of withdrawal.
public TransactionTypes TransactionType
{
get { return transactionType; }
set { transactionType = value; }
}
public string Payee
{
get { return payee; }
set { payee = value; }
}
public string CheckNumber
{
get { return checkNumber; }
set { checkNumber = value; }
}
public override string ToString()
{
return string.Format("{0} {1}: {2}",
TransactionDate.ToShortDateString(),
TransactionType.ToString(),
TransactionAmount.ToString("c"));
}
}
}
Also Transaction2.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Homework6V2
{
class Transaction2
{
/*
* Manage transaction type and payee together - readonly
properties
* with a method (two arguments) to get both at same time for
testing.
*
* Other validation would be same as transaction class.
*/
private decimal amount;
private DateTime date;
private string payee, checkNumber;
private TransactionTypes type;
public Transaction2(decimal entryAmount, DateTime entryDate,
TransactionTypes entryType,
string entryPayee, string entryCheckNo)
{
this.Amount = entryAmount;
this.Date = entryDate;
this.CheckNumber = entryCheckNo;
SetPayeeAndType(entryPayee, entryType);
}
public decimal Amount
{
get { return amount; }
set
{
if (IsValidAmount(value))
amount = value;
else
throw new ApplicationException("Amount must be more than
zero.");
}
}
public DateTime Date
{
get { return date; }
set { date = value; }
}
public string CheckNumber
{
get { return checkNumber; }
set { checkNumber = value; }
}
// cannot set payee, since you may make it empty - but you don't
know if it's a withdrawal
public string Payee
{
get { return payee; }
}
// can't set type if don't know what the payee value is
public TransactionTypes Type
{
get { return type; }
}
// method allows passing more than one value- can set the
properties
// payee and transaction type because we can deal with both
public void SetPayeeAndType(string Payee,
TransactionTypes Type)
{
if (Payee == "" && Type ==
TransactionTypes.Withdrawal)
throw new ApplicationException("Payee required for
Withdrawals");
type = Type; // variable = argument
if (Payee != "")
payee = Payee;
else
payee = Type.ToString();
}
public static bool IsValidAmount(decimal entry)
{
return entry > 0;
}
public static bool IsValidAmount(string entry)
{
decimal value;
if (decimal.TryParse(entry, out value))
{
return IsValidAmount(value);
}
return false;
}
public static bool IsValidDate(string entry)
{
DateTime date;
return DateTime.TryParse(entry, out date);
}
public override string ToString()
{
return Type.ToString() + " " + Date.ToShortDateString() + " " +
Amount.ToString("c");
}
}
}
Homework 6 v.2 0 X Date: Ist Transactions Amount: Transaction Type Withdrawal Deposit Service Fee Payee: Check # Balance: label6 : OU O Process Clear Remove Exit