계정 클래스에 액세스하는 데 도움이 필요합니다. 프로그램을 실행하면 ATM 클래스의 WriteLine ("Welcome/Enter Account/Exit"); 프롬프트가 표시됩니다. 그러나 숫자를 입력하면 명령 창이 닫힙니다. 나는 여기서 무엇을해야할지 모르겠다. 나는 이것이 C Sharp의 첫 번째 프로그램이라는 것을 언급해야한다. 또한, 내가 사이트에 처음 온 사람들이 왜 내 질문에 투표하지 않는지 잘 모르겠습니다.다른 클래스에서 클래스에 액세스하는 방법.
계정 클래스 :
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