帮助收集租赁计划 [英] help with collection in rental program

查看:76
本文介绍了帮助收集租赁计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在研究一个在互联网上找到的出租程序,我需要一些帮助完成此任务的最终任务.

我需要保存一个函数,以显示哪些电影已租出以及何时到期.

我想知道是否应该使用一些集合来保存电影对象以及在哪里进行保存?来自main()?还有什么是影片应有的最佳实现方式?我应该有一个使用DateTime参数查看影片何时租借的功能吗?



ok so im working on a rental program I found on the internet and I need some help with the finaly task on this assigment.

I need to save have a function to show which films are rented out and when they are due.

I''m wondering if I should use some collection to save the movie object in and from where do I do this ? from main()? and also whats the best way to implement when the film a due function...should I have a function that use DateTime parameter to see when the movie is rented?



public class Transaction
    {
        private static double _amountcollected = 0;
        private double _amount = 0;

        public Transaction(int days)
        {
            PriceToPay(days);
        }

        public void PriceToPay(int days)
        {
            double price = 12.50;
            double amount = price * days;
            if(days > 7)
            {
                _amount = 400;
            }
        }
        public override string ToString()
        {
            return String.Format("You owe us {0}", _amount);
        }
    }


 public class Video
    {
        private static int _numb_of_films;
        private int _year;
        private string _director;
        private string _title;
        private bool _avalible = true;

        public Video(string title, string director, int year)
        {
            Title = title;
            this._director = director;
            this._year = year;
            _numb_of_films++;

        }
        public void SetVideo(string title, string director, int year)
        {
            this._title = title;
            this._director = director;
            this._year = year;
        }
        public bool IsAvailabe(bool avalible)
        {
            _avalible = avalible;
            return this._avalible;
        }
        public bool Rented(bool rented)
        {
            _avalible = rented;
            return this._avalible;
        }
        public string VideoInfo { get { return  _year + " " +  _title + " " + _director; } }

        public static int NumOfFilms { get { return _numb_of_films; } }

        public string Title
        {
            get
            {
                return _title;
            }
            set
            {
                _title = value;
                if (_title.Length > 25)
                {
                    _title = Title.Substring(0, 25);
                }
            }
        }

    }

推荐答案

You need a List<Video>

,您将其实例化到视频实例化的同一位置,因为您需要将每个视频添加到此列表.
接下来,您必须为电影的租借时间和到期时间添加DateTime的一些属性.
如果这样做,则可以在列表上使用简单的迭代逻辑来查找到期的电影.甚至最好使用linq.假设您还在Video类上创建了一个简单的布尔方法isDue,则可以执行以下操作:

, you instantiate it at the same location where the videos are instantiated because you need to add each video to this list.
Next you have to add some properties of DateTime for the time when the film is rented and when it is due.
If you do this you can use simple iteration logic over the list to find the films that are due. Or even better use linq. Suppose you also created a simple boolean method isDue on the Video class you can do something like this :

List<Video> list = new List<Video>();
list.add(new Video(blabla));
list.add(new Video(blabla));
list.add(new Video(blabla));

var Query = (from v in list
             where v.isDue()
             select v);
foreach(Video v in Query){
  //v is now a video that is due
}



可以基于DateTime.now或DateTime.Today方法实现isDue方法.



isDue method can be implemented based on DateTime.now or DateTime.Today methods.


这篇关于帮助收集租赁计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆