升学考试与生成器模式

凭印象,可能概念不对? 等我晚上回去看看书,也欢迎大家帮我:)
using System;
using System.Collections.Generic;
using System.Text;

namespace 生成器模式
{
    
class Program
    {
        
static void Main(string[] args)
        {
            
try
            {
                
//要想升学一定要学习
                升学 小朋友A = new 学习();
                
//当然要经过考试
                new 考试(小朋友A);

                小朋友A.升学成功();
            }
            
catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.Read();
        }
    }

    
interface 升学
    {
        
double 语文成绩
        { 
get;set;}
        
double 数学成绩
        { 
get;set;}
        
double 外语成绩
        { 
get;set;}

        
void 升学成功();
    }

    
class 学习 : 升学
    {
        
double 语文 = 0;
        
double 数学 = 0;
        
double 外语 = 0;

        
public double 语文成绩
        {
            
get
            {
                
return 语文;
            }
            
set
            {
                语文 
= value;
            }
        }

        
public double 数学成绩
        {
            
get
            {
                
return 数学;
            }
            
set
            {
                数学 
= value;
            }
        }

        
public double 外语成绩
        {
            
get
            {
                
return 外语;
            }
            
set
            {
                外语 
= value;
            }
        }

        
public void 升学成功()
        {
            
if (语文 < 60)
            {
                
throw new Exception("语文不及格,别想升学");
            }

            
if (数学 < 60)
            {
                
throw new Exception("数学不及格,别想升学");
            }

            
if (外语 < 60)
            {
                
throw new Exception("外语不及格,别想升学");
            }

            Console.WriteLine(
"我终于升学成功了");
        }
    }

    
class 考试
    {
        升学 天天学习;

        
private 考试()
        { }

        
public 考试(升学 天天学习)
        {
            
this.天天学习 = 天天学习;
            最终考试();
        }

        
void 最终考试()
        {
            Random rd 
= new Random();
            天天学习.数学成绩 
= (double)rd.Next(1100);
            天天学习.外语成绩 
= (double)rd.Next(1100);
            天天学习.语文成绩 
= (double)rd.Next(1100);
        }
    }
}

posted on 2006-06-04 19:25  萝卜青菜  阅读(326)  评论(4编辑  收藏  举报

导航