アカウントクラスにアクセスする際の支援が必要です。プログラムを実行すると、ATMクラスのWriteLine( "Welcome/Enter Account/Exit");というプロンプトが表示されます。しかし、数字を入力すると、コマンドウィンドウが閉じます。私はここで何をすべきか分からない。私はこれがCシャープの私の最初のプログラムだと言及するべきです。また、私はサイトの初心者として、なぜ私の質問に投票していないのか分かりません。別のクラスの中からクラスにアクセスする方法。
Accountクラス:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Account //Within the Account class, we have balance, withdraw,and deposit
{
////An account array to create 3 seperate accounts each with a default balance of $100.00.
//int[] myAccount = new int[3];
Account[] account = new Account[3];
public double balance;
public void deposit(double n)
{
balance += n;
}
public void withdraw(double n)
{
balance -= n;
}
public void calcInterest(double n)
{
//Here is where we calculate the interest!
}
public void menu()
{
{
{
int input = Convert.ToInt32(Console.ReadLine());
var currAccount = account[input]; // Not sure what this code is for.
if (account[input] == null)
{
account[input] = new Account();
account[input].balance = 100; //Set initial balance to $100
}
if (input != 4)
{
Console.WriteLine("1) Deposit");
Console.WriteLine("2) Withdraw");
Console.WriteLine("3) Get Balance");
Console.WriteLine("4) Exit");
if(input == 1)
{
Console.WriteLine("How much would you like to deposit today?");
int moneyIn = Convert.ToInt32(Console.ReadLine());
account[input].deposit(moneyIn); //access the deposit method and increase balance by the amount entered by user.
Console.WriteLine("Here is your current balance:" + account[input].balance);
}
if(input == 2)
{
Console.WriteLine("How much would you like to withdraw today?");
int moneyOut = Convert.ToInt32(Console.ReadLine());
account[input].withdraw(moneyOut); //Access the withdraw method and decrease balance by the amount entered by user.
Console.WriteLine("Here is your current balance:" + account[input].balance);
}
if (input == 3)
{
Console.WriteLine("Here is your current balance:"+account[input].balance);
//return account[input].balance;
}
if (input == 4)
{
//I want to exit the application here.
}
}
}
}
}
}
}
ATMクラス:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Atm //With the atm class we will have the atm menu
{
static void Main(string[] args)
{
Console.WriteLine("Welcome!");
Console.WriteLine("Please enter your account number (1-3 or '4' to exit.");
int input = Convert.ToInt32(Console.ReadLine());
{
if (input >= 1 && input <= 3)
{
Console.WriteLine("You have entered " + input);
Console.ReadLine();
//ConsoleApplication3.Account[input]; // How do I access the account here?
}
else if (input == 4)
{
Console.WriteLine("Goodbye.");
//Exit Application
}
}
}
}
}
プログラムのクラス:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
//Not really sure what this is for at the moment, or if it is even needed.
}
}
まだ分かりません。 – user2187341