C# 如何从arraylist中显示这些内容?

C# 如何从arraylist中显示这些内容?,c#,C#,这是我的主课 我是基于我以前做过的另一个例子,它的工作原理是一样的,这是我第一次使用arraylist,所以可能与此有关,我不确定。我只需要它的显示和arraylist正常工作,我认为其他一切工作正常 现在我在以下方面遇到了一个错误: Console.WriteLine("{0,-12} {1,-12} {2,-12} {3,-12} {4,-12} {5,-12} {6,-12}", plan[idx].GetCardNumber(), plan[idx].GetCreditBalan

这是我的主课

我是基于我以前做过的另一个例子,它的工作原理是一样的,这是我第一次使用arraylist,所以可能与此有关,我不确定。我只需要它的显示和arraylist正常工作,我认为其他一切工作正常


现在我在以下方面遇到了一个错误:

Console.WriteLine("{0,-12} {1,-12} {2,-12} {3,-12} {4,-12} {5,-12} {6,-12}",
    plan[idx].GetCardNumber(), plan[idx].GetCreditBalance(), plan[idx].GetMonthlyPayment(),
    plan[idx].GetAnnualRate(), plan[idx].MonthsToPayOff(), plan[idx].TotalPayment(),
    plan[idx].CompanyProfit());
说:

“对象”不包含___; eg(.getcreditbalance)的定义

完整程序:

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


namespace Assignment1
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList plan = new ArrayList();
            int count = 0;
            char option;

            Console.WriteLine("--= Credit Card Calculator =-- ");
            Console.WriteLine();

            do
            {
                option = ReadMenuOption();
                switch (option)
                {
                    case 'E':
                        count = count + 1;
                        AddPaymentPlan(count, plan);

                        break;
                    case 'V':
                        Display(count, plan);
                        break;
                    case 'X':
                        Console.WriteLine("Goodybye.");
                        break;
                    default:
                        Console.WriteLine("Invalid option.");
                        break;
                }

            } while (option != 'X');
        }


        static char ReadMenuOption()
        {
            char option;

            Console.WriteLine("Options Menu");
            Console.WriteLine("====================");
            Console.WriteLine("E - Enter calculation information");
            Console.WriteLine("V - View calculation report");
            Console.WriteLine("X - Exit");
            option = Console.ReadLine().ToUpper()[0];

            return option;
        }

        static void Display(int count, ArrayList plan)
        {
            if (count == 0)
            {
                Console.WriteLine("There are no values to show!");
            }
            else
            {
                for (int idx = 0; idx < plan.Count; idx = idx + 1)
                {


                    Console.WriteLine("{0,-12}  {1,-12}  {2,-12}  {3,-12}  {4,-12}  {5,12}  {6,-12}", " Card Number", "Card Balance", "Monthly Payment", "APR", "Months to Pay", "Total Payment", "Company Profit");

                    Console.WriteLine("{0,-12}   {1,-12}  {2,-12}   {3,-12}   {4,-12}   {5,-12}   {6,-12}", plan[idx].GetCardNumber(), plan[idx].GetCreditBalance(), plan[idx].GetMonthlyPayment(), plan[idx].GetAnnualRate(), plan[idx].MonthsToPayOff(), plan[idx].TotalPayment(), plan[idx].CompanyProfit());
                }

            }
        }

        static int AddPaymentPlan(int count, ArrayList plan)


        {
            PaymentPlan p = new PaymentPlan();

                do
                {
                    try
                    {
                        Console.Write("Enter card number: ");
                        p.SetCardNumber(long.Parse(Console.ReadLine()));


                    }
                    catch
                    {
                        Console.WriteLine("Invalid card number");
                    }
                } while (p.GetCardNumber().Equals(""));

                do
                {
                    try
                    {
                        Console.Write("Enter card balance: ");
                        p.SetCreditBalance(double.Parse(Console.ReadLine()));

                    }
                    catch
                    {
                        Console.WriteLine("Invalid card balance.");
                    }
                } while (p.GetCreditBalance().Equals(""));


                do
                {
                    try
                    {
                        Console.Write("Enter payment amount: ");
                        p.SetMonthlyPayment(double.Parse(Console.ReadLine()));

                    }
                    catch
                    {
                        Console.WriteLine("Invalid payment amount.");
                    }
                } while (p.GetMonthlyPayment().Equals(""));



                do
                {
                    try
                    {
                        Console.Write("Enter annual rate: ");
                        p.SetAnnualRate(double.Parse(Console.ReadLine()));

                    }
                    catch
                    {
                        Console.WriteLine("Invalid");
                    }
                } while (p.GetAnnualRate().Equals(""));

                plan.Add(p);

                Console.WriteLine("It will take {0} months to pay off your credit card", p.MonthsToPayOff());
                Console.WriteLine();


            count = count + 1;
            return count;



        }
    }
}










and my Payment plan class :


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

namespace Assignment1
{
    class PaymentPlan
    {
        private long _cardNumber;
        private double _creditBalance;
        private double _monthlyPayment;
        private double _annualRate;

        public PaymentPlan()
        {
            _cardNumber = 0;
            _creditBalance = 0;
            _monthlyPayment = 0;
            _annualRate = 0;
        }

        public PaymentPlan(long cardNumber, double creditBalance, double monthlyPayment, double annualRate)
        {
            SetCardNumber(cardNumber);
            SetCreditBalance(creditBalance);
            SetMonthlyPayment(monthlyPayment);
            SetAnnualRate(annualRate);
        }

        public long GetCardNumber()
        {
            return _cardNumber;
        }

        public void SetCardNumber(long cardNumber)
        {
            if (cardNumber < 0)
            {
                throw new Exception("Has to be a positive number");
            }
            _cardNumber = cardNumber;
        }

        public double GetCreditBalance()
        {
            return _creditBalance;
        }

        public void SetCreditBalance(double creditBalance)
        {
            if (creditBalance < 0)
            {
                throw new Exception("Has to be a positive number");
            }
            _creditBalance = creditBalance;
        }

        public double GetMonthlyPayment()
        {
            return _monthlyPayment;
        }

        public void SetMonthlyPayment(double monthlyPayment)
        {
            if (monthlyPayment < 0)
            {
                throw new Exception("Has to be a positive number");
            }
            _monthlyPayment = monthlyPayment;
        }
        public double GetAnnualRate()
        {
            return _annualRate;
        }

        public void SetAnnualRate(double annualRate)
        {
            if (annualRate < 0 || annualRate > 1)
            {
                throw new Exception("Has to be a positive number between 0.0 & 1.0");
            }
            _annualRate = annualRate;
        }

        public double MonthsToPayOff()
        {
            double months;
            double daily;
            double monthly;
            double tinycalc;
            double innerbrac;
            double bottom;
            double upperbrac;

            daily = _annualRate / 365;

            //calculates number of months to be returned to main and displayed for user
            monthly = _creditBalance / _monthlyPayment;
            tinycalc = -1.0 / 30;
            innerbrac = Math.Pow(1 + daily, 30);
            bottom = Math.Log(1 + daily);
            upperbrac = Math.Log(1 + (_monthlyPayment * (1 - innerbrac)));

            months = Math.Round(tinycalc * (upperbrac / bottom));

            return months;
        }

        public double TotalPayment()
        {
            return GetCreditBalance() * (MonthsToPayOff() * GetMonthlyPayment());
        }

        public double CompanyProfit()
        {

            return TotalPayment() - _creditBalance;
        }

    }
}
使用系统;
使用System.Collections.Generic;
使用系统集合;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用系统配置;
命名空间分配1
{
班级计划
{
静态void Main(字符串[]参数)
{
ArrayList计划=新建ArrayList();
整数计数=0;
字符选项;
Console.WriteLine(“--=信用卡计算器=--”);
Console.WriteLine();
做
{
选项=ReadMenuOption();
开关(选件)
{
案例“E”:
计数=计数+1;
AddPaymentPlan(计数、计划);
打破
案例“V”:
显示(计数、计划);
打破
案例“X”:
Console.WriteLine(“Goodybye”);
打破
违约:
Console.WriteLine(“无效选项”);
打破
}
}while(选项!=“X”);
}
静态字符ReadMenuOption()
{
字符选项;
Console.WriteLine(“选项菜单”);
Console.WriteLine(“===============================”);
Console.WriteLine(“E-输入计算信息”);
Console.WriteLine(“V-视图计算报告”);
控制台写入线(“X-退出”);
option=Console.ReadLine().ToUpper()[0];
返回选项;
}
静态无效显示(整数计数、ArrayList平面)
{
如果(计数=0)
{
WriteLine(“没有要显示的值!”);
}
其他的
{
对于(int idx=0;idx((PaymentPlan)plan[idx]).GetCardNumber()
var plans = new List<PaymentPlan>();
plans.Add(new PaymentPlan(12345, ...));
Console.WriteLine(plans[idx].GetCardNumber());