5-8万年薪顶级嵌入式,京沪深就业地 浅谈并行编程中的任务分解模式
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  J2SE / 基础类

这是一个英国大学的考试题目,是java版的

楼主Godfinger(no1dog)2006-08-09 00:12:23 在 Java / J2SE / 基础类 提问

我个人感觉国外与国内的教育有些不一样,大家觉的自己行的可以试试  
  a) Explain   what   you   understand   by   the   term   monitor   in   relation   to   concurrent   systems.     Briefly   outline   the   facilities   provided   by   Java   for   implementing   monitors.  
  (5   marks)  
   
  b)   A   home   heating   system   contains   the   following   objects:  
   
  An   instance   of   class   TemperatureReader;   this   regularly   reads   the   room   temperature   (of   classTemperature)   from   a   thermometer   and   writes   this   value   into   an   object   of   class   Pool  
   
  An   instance   of   class   Pool,   which   provides   storage   and   access   methods   for   the   latest   temperature   read   by   TemperatureReader.     Pool   only   holds   a   single   value.  
   
  An   instance   of   class   Controller   which   regularly   takes   the   latest   temperature   from   the   Pool,   and   uses   it   to   calculate   and   execute   appropriate   adjustments   to   the   boiler   settings.   This   Controller   object   can   have   its   operation   suspended   if   its   turnOff()   method   is   called,   and   reactivated   if   its   turnOn()   method   is   called.    
   
  An   instance   of   class   WatchDog   which   regularly   compares   the   latest   temperature   in   the   Pool   against   an   upper   threshold   value.   If   the   temperature   exceeds   this   threshold,   the   WatchDog   reports   this   in   a   log   file,   and   suspends   the   operation   of   the   Controller   object   (by   calling   its   turnOff   method)   until   the   temperature   falls   below   a   second   (lower)   threshold,   when   it   reactivates   the   Controller   (by   calling   its   turnOn   method)..  
   
  In   these   questions,   assume   that   threads   should   sleep   for   one   second   between   execution   of   repeated   actions,   and   that   the   main   loop   in   a   thread   should   run   indefinitely   (i.e.   do   not   worry   about   terminating   threads).  
   
  i. Draw   a   UML   communication   (object   collaboration)   diagram   for   this   system.  
   
  (2   marks)  
   
  ii.   Write   code   for   the   Pool   class,   explaining   how   its   clients   use   it.     Note:   the   getTemperature   method   in   Pool   is   a   non-destructive   read,   so   the   same   value   may   be   read   more   than   once.  
  (3   marks)  
   
  iii.   Write   code   for   the   main   routine   in   the   WatchDog   class,   assuming   that   this   has   references   to   the   Pool   and   Controller   objects.  
  (4   marks)  
   
  iv..   Write   outline   code   for   the   whole   of   the   Controller   class,   assuming   that   a   reference   to   the   Pool   object   is   passed   to   it   in   its   constructor.  
  (6   marks)  
   
  Notes:   We   do   not   expect   you   to   submit   executable   code   for   this   question,   just   Java   pseudocode   demonstrating   that   you   understand   how   Java   threads   work.     You   do   not   need   to   include   exception   handlers.      
   
  Do   NOT   use   the   deprecated   methods   stop,   suspend   and   resume   from   java.lang.Thread.  
  问题点数:100、回复次数:60Top

1 楼alexwan(牧林:才多身子弱)回复于 2006-08-09 00:42:19 得分 0

看到就有点晕^_^Top

2 楼emin_lee(emin)回复于 2006-08-09 08:55:51 得分 0

mark!Top

3 楼UnAgain()回复于 2006-08-09 09:09:34 得分 0

 
  国内大学都怎么教java?Top

4 楼konj(恰八零后一代)回复于 2006-08-09 09:11:39 得分 0

谁能翻译过来Top

5 楼treeroot(旗鲁特)回复于 2006-08-09 09:17:33 得分 0

都是多线程的问题Top

6 楼boyu_song(我这样会不会遭天谴,我只是想看看这个论坛的ID最大可以多大?)回复于 2006-08-09 09:29:12 得分 0

没有排好板阿Top

7 楼hbwhwang(【生病了,好好休息中...】)回复于 2006-08-09 09:39:55 得分 0

没看出什么不一样~Top

8 楼luomopiao(落寞漂)回复于 2006-08-09 10:01:39 得分 0

???????????????????????????????????????Top

9 楼TinyJimmy(Jimmy)回复于 2006-08-09 10:06:41 得分 0

感觉上差不多嘛。要真不同,国内注重结果,国外注重过程Top

10 楼solonc(rabbit)回复于 2006-08-09 10:11:41 得分 0

赞同楼上的/   mark.Top

11 楼wqnashqu()回复于 2006-08-09 10:16:17 得分 0

hehe     是不太一样Top

12 楼bigc2000(公元2005年4月9日)回复于 2006-08-09 11:06:07 得分 0

国内java,教的是语言本身,国外是实现面向对象的方法。  
   
  记得老师出的题就是  
  用swing写一个程序来实现+-*/的calc。  
  汗!Top

13 楼Godfinger(no1dog)回复于 2006-08-09 12:50:37 得分 0

大家谁会写着试试看,就当练习,写得好的给分啊Top

14 楼forget4ever()回复于 2006-08-09 13:04:52 得分 0

markTop

15 楼ilove8(千里|你去哪里了,我等了你很久了!)回复于 2006-08-09 14:06:15 得分 0

不错的题目,锻炼思维,又锻炼英文,呵呵Top

16 楼shilixiu()回复于 2006-08-09 14:16:52 得分 0

晕啊Top

17 楼UnAgain()回复于 2006-08-09 14:54:00 得分 0

 
  啊呀,佩服佩服!  
  人家英国的教学水平就是高啊,单看这个题目,学生既练习了编程,又学习了英语。国内学校差远了……     ^_^Top

18 楼z184931481(GOLD)回复于 2006-08-09 16:28:31 得分 0

国内教学先面向书本,工作后再面向对象,过几年面向服务,呵呵!!Top

19 楼hbwhwang(【生病了,好好休息中...】)回复于 2006-08-09 16:41:44 得分 80

class   TemperatureReader   extends   Thread{  
          private   Pool   pool;  
          private   int   interval;  
          TemperatureReader(Pool   pool,int   interval){  
                  this.pool=pool;  
                  this.interval=interval;  
          }  
          private   double   getTemperature(){  
                  System.out.println("read   value   from   the   thermometer   ");  
                  //return   value   from   the   thermometer    
                  return   0.0;  
          }  
          public   void   run(){  
                  while   (true){  
                          double   degree=getTemperature();  
                          Temperature   t=new   Temperature();  
                          synchronized   (pool){  
                                  pool.setTemperature(t);  
                          }  
                          try{  
                                  this.sleep(interval);     //block   thread   1   second  
                          }catch(Exception   ex){  
                                  ex.printStackTrace();  
                          }  
                  }  
          }  
  }  
   
  class   Temperature   {  
          private   double   degree;  
          Temperature(){  
                  degree=0;  
          }  
          Temperature(double   degree){  
                  this.degree=degree;  
          }  
   
          public   void   setDegree(double   degree){  
                  this.degree=degree;  
          }  
          public   double   getDegree(){  
                  return   this.degree;  
          }  
  }  
   
  class   Pool   {  
          private   Temperature   temperature;  
          public   void   setTemperature(Temperature   temperature){  
                  this.temperature=temperature;  
          }  
          public   Temperature   getTemperature(){  
                  return   this.temperature;  
          }  
  }  
   
  /**  
    An   instance   of   class   Controller   which   regularly   takes   the   latest   temperature    
    from   the   Pool,   and   uses   it   to   calculate   and   execute   appropriate   adjustments   to    
    the   boiler   settings.   This   Controller   object   can   have   its   operation   suspended    
    if   its   turnOff()   method   is   called,   and   reactivated   if   its   turnOn()   method   is    
    called.  
    */  
  class   Controller   extends   Thread   {  
          private   Pool   pool;  
          private   int   interval;  
          private   boolean   onoff=false;  
          Controller(Pool   pool,int   interval){  
                  this.pool=pool;  
                  this.interval=interval;  
                  onoff=true;  
          }  
          private   void   adjustBoiler(Temperature   t){  
                  System.out.println("   adjustments   to   the   boiler   settings   ");  
          }  
          public   synchronized   void   turnOn(){  
                  if   (onoff==false){  
                          System.out.println("turn   on   the   Controller   and   boiler");  
                          onoff   =   true;  
                  }  
          }  
          public   synchronized   void   turnOff(){  
                  if   (onoff){  
                          System.out.println("turn   off   the   Controller   and   boiler");  
                          onoff   =   false;  
                  }  
          }  
           
          public   void   run(){  
                  while(true){  
                          synchronized   (this){  
                                  if   (onoff){  
                                          Temperature   t=null;  
                                          synchronized   (pool){  
                                                  t=pool.getTemperature();  
                                          }  
                                          adjustBoiler(t);  
                                  }  
                          }  
                          try{  
                                  this.sleep(this.interval);  
                          }catch(Exception   ex){  
                                  ex.printStackTrace();  
                          }  
                  }  
          }  
  }  
   
  /*  
    An   instance   of   class   WatchDog   which   regularly   compares   the   latest   temperature    
    in   the   Pool   against   an   upper   threshold   value.   If   the   temperature   exceeds   this    
    threshold,   the   WatchDog   reports   this   in   a   log   file,   and   suspends   the   operation    
    of   the   Controller   object   (by   calling   its   turnOff   method)   until   the   temperature    
    falls   below   a   second   (lower)   threshold,   when   it   reactivates   the   Controller    
    (by   calling   its   turnOn   method)..  
  */  
  public   class   WatchDog   extends   Thread   {  
          private   Pool   pool;  
          private   Controller   controller;  
          private   double   upperthreshold;  
          private   double   lowerthreshold;  
          private   int   interval;  
          public   WatchDog(Pool   pool,Controller   controller,double   upperthreshold,  
                                          double   lowerthreshold,int   interval)   {  
                  this.controller=controller;  
                  this.pool=pool;  
                  this.upperthreshold=upperthreshold;  
                  this.lowerthreshold=lowerthreshold;  
                  this.interval=interval;  
          }  
          private   void   writeLog(String   s){  
                  System.out.println("write   log:   "+s);  
          }  
          public   void   run(){  
                  while   (true){  
                          try{  
                                  this.sleep(interval);  
                          }catch(Exception   ex){  
                                  ex.printStackTrace();  
                          }  
                          Temperature   t=null;  
                          synchronized(pool){  
                                  t=pool.getTemperature();  
                          }  
                          if   (t.getDegree()>upperthreshold){  
                                  synchronized(controller){  
                                          controller.turnOff();  
                                  }  
                                  writeLog(new   java.util.Date().toString()+t.getDegree());  
                          }   else   if   (t.getDegree()<lowerthreshold){  
                                  synchronized(controller){  
                                          controller.turnOn();  
                                  }  
                          }  
                  }  
          }  
           
          public   static   void   main(String[]   args)   {  
                  Pool   pool=new   Pool();  
                  TemperatureReader   tr=new   TemperatureReader(pool,1000);  
                  tr.start();  
                   
                  Controller   ctrl=new   Controller(pool,900);  
                  ctrl.start();  
                   
                  WatchDog   dog=new   WatchDog(pool,ctrl,30,20,800);  
                  dog.start();  
          }  
  }Top

20 楼xiao7cn(o(∩_∩)o... 哈哈!)回复于 2006-08-09 17:28:35 得分 10

a)请谈谈你怎么理解术语“监视器”与并发系统的关系。简要的列出由Java提供的实现监视器的组件。(5分)  
   
   
  b)一个室内供热系统包含如下对象:  
  一个TemperatureReader类的实例:它周期性地从一个温度计上读取室内温度(Temperature类),并将其写入Pool类的一个对象中。  
  一个Pool类的实例:它为由TemperatureReader读取的最新温度值提供存储和访问的方法。Pool只保存单个值。  
  一个Controller类的实例:它周期性地从Pool中取最新的温度值,并进行计算,然后对加热器的设置进行适当的调节。如果它的turnOff()方法被调用,将暂停它的操作,而当turonOn()方法被调用时将会恢复。  
  一个WatchDog类的实例:它周期性地对最新温度值和上限值进行比较。如果温度超过了这个上限,WatchDog在一个日志文件里报告,并且暂停Controller对象的操作(调用turnOff()方法),直到温度降到上限值以下,它才恢复Controller(调到turnOn()方法)。  
   
  在上面的问题中,假设所有线程在执行重复的操作时,中间休息一秒种,而且线程中的主循环是无限执行的(也就是不用关心线程的终止)。  
   
  i.为这个系统画一个UML通信图。  
  (2分)  
   
  ii.写出Pool类的代码来描述它的客户如何使用它。注意:Pool中的getTemperature()方法是非破坏性读取,所以同样的值可以被读取多次。  
  (3分)  
   
  iii.写出WatchDog类主要功能的代码,假设它有Pool和Controller对象的引用。  
  (4分)  
   
  iv.大概地写出整个Controller类的代码,假设对Pool对象的引用是通过构造函数来传递。  
  (6分)  
   
  注意:我们并不希望你提交这个问题的可执行代码,只要Java伪代码来描绘你对Java线程机制的理解。你不需要把异常处理包含进来。  
   
  不要使用来自java.lang.Thread的stop(),suspend()和resume()的过时方法。Top

21 楼flean(administrator)回复于 2006-08-09 17:49:56 得分 0

看不懂,还要多学学,唉Top

22 楼Godfinger(no1dog)回复于 2006-08-09 22:26:40 得分 0

谢谢xiao7cn的翻译,期待更加完美的答案Top

23 楼lbx19822004()回复于 2006-08-10 08:05:33 得分 0

啊呀,佩服佩服!  
  人家英国的教学水平就是高啊,单看这个题目,学生既练习了编程,又学习了英语。国内学校差远了……     ^_^  
  ------------------------------------------------------------------------------------  
  哈哈,  
  我们国家的教育也不错的,还可以附带教中文的啊,听说去国外学中文好贵哦Top

24 楼Godfinger(no1dog)回复于 2006-08-10 09:34:27 得分 0

问题A有没有人愿意回答下Top

25 楼bluesky23(乐天_正在开发右半脑。。。^_^)回复于 2006-08-10 10:33:40 得分 0

markTop

26 楼Godfinger(no1dog)回复于 2006-08-10 12:39:38 得分 0

问题A   没人知道吗Top

27 楼hbwhwang(【生病了,好好休息中...】)回复于 2006-08-10 12:52:06 得分 0

Godfinger(no1dog):  
  每个人出的题目都有他的上下文环境。  
  这个题目肯定有它的上下文环境,可能是出题人讲过的一个专题。他的答案我也许知道,但我现在不知道他是说什么,也就是说他的说法跟我的知识库匹配不起来Top

28 楼wanghaha(@#$)回复于 2006-08-10 13:50:27 得分 0

还好,谢谢搂主!Top

29 楼quanquan626(圈圈)回复于 2006-08-10 15:45:02 得分 0

一头雾水Top

30 楼Godfinger(no1dog)回复于 2006-08-10 16:51:01 得分 0

To:quanquan626(圈圈)这里还有道补考题目。  
  大家应该都懂吧  
  An   application   running   on   a   network   client   displays   a   regularly-updated   list   of   stock   price   information,   received   from   a   server.   The   design   of   the   client   application   includes   the   following   classes:  
   
  &#8226; Stock   –   this   class   has   attributes   including   a   unique   identifier   for   the   company   and   stock,   itslatest   price,   the   time   it   was   last   updated,   the   number   held,   and   so   on.  
   
  &#8226; StockData   –   this   stores   a   collection   of   Stock   objects,   representing   the   user's   portfolio.  
   
  &#8226; StockUpdater   –   this   receives   messages   over   the   network   containing   a   list   of   stock   prices.     It   retrieves   each   Stock   object   in   the   list   from   the   collection   in   StockData,   and   updates   it.  
   
  &#8226; ScreenView   –   each   time   the   StockData   is   updated,   an   object   of   this   classdisplays   the   fresh   data   on   the   screen   (showing   stock   code,   description,   price,   etc).     The   ScreenView   class   supports   a   number   of   different   display   formats   (e.g.   in   a   grid,   in   graphical   form,   etc.)   It   may   be   necessary   to   add   new   formats.  
   
  &#8226; LogFile   -   each   time   the   StockData   is   updated,   an   object   of   this   class   uses   the   fresh   data   to   update   a   record   of   the   stock   information   held   on   disk.  
   
  Show   how   the   following   design   patterns   could   be   used   in   the   design   of   this   system:  
   
  i)   Observer   (8   marks)  
  ii)   Singleton   (4   marks)  
  iii)   Iterator   (4   marks)  
   
  In   your   answer,   for   each   of   these   patterns:  
   
  &#8226; Describe   its   purpose.  
  &#8226; Show   where   it   could   be   used   and   explain   why   its   use   is   appropriate   here.  
  &#8226; Describe   its   structure,   giving   a   UML   class   diagram   (where   appropriate)   and   outline   Java   code   for   its   use   in   this   system   (where   Java   provides   direct   support   for   the   pattern,   you   should   use   it).  
  其实那里的教育我真的感觉不一样,考试可以带回家做。好像很少有闭卷考试。都是些设计Top

31 楼Diego1983(不再犹豫!)回复于 2006-08-10 17:07:17 得分 0

记号  
  晚上再研究.Top

32 楼xiao7cn(o(∩_∩)o... 哈哈!)回复于 2006-08-10 17:24:23 得分 10

一个运行在网络上的客户端程序,显示从服务器发来的周期性更新的股价信息。这个客户端程序的设计包含如下类:  
  Stock类:此类具有这个公司和股票的唯一标识、最新价格、最新更新时间、持有数量等等。  
  StockData类:它保存一组Stock对象,来表示用户的证券清单。  
  StockUpdater类:它从网络上接收一系列的股价信息,然后从StockData组中逐个提取Stock对象,并更新它。  
  ScreenView类:每当StockData被更新时,这个类的对象将更新的数据在屏幕上表示出来(显示股票代码、描述、价格等等)。ScreenView类技术多种不同的显示格式(比如网格、图形表示),且可能允许增加新的格式。  
  LogFile类:每当StockData被更新时,这个类的对象用最新数据来更新磁盘上的股票信息。  
   
  请说明如何使用如下几种设计模式来设计这个系统:  
  i) Observer   (观察者模式)  
  ii) Singleton     (单态模式)  
  iii) Iterator     (跌代器模式)  
   
  在你的回答中,对于每一种模式:  
  1)描述它的用途。  
  2)说明它应该用在哪里,为什么它在那里的作用是合适的?  
  3)描述它的结构,给出一个UML类图(在合适的地方),   并用大致的Java代码来说明它在系统中的作用(在Java提供了对该模式直接支持的地方,你也可以使用它)。  
  Top

33 楼xiao7cn(o(∩_∩)o... 哈哈!)回复于 2006-08-10 17:27:27 得分 0

期待高手详细解答!Top

34 楼xiao7cn(o(∩_∩)o... 哈哈!)回复于 2006-08-10 20:06:51 得分 0

就沉了?Top

35 楼Godfinger(no1dog)回复于 2006-08-10 21:22:37 得分 0

烧鸡,你翻译的好快.Top

36 楼hellsing0105()回复于 2006-08-11 00:10:20 得分 0

呵呵   看的眼睛晕啊!   得补习英语了Top

37 楼sunshine5246(阳光)回复于 2006-08-11 09:04:44 得分 0

ding   差距Top

38 楼zhmt(孜风)回复于 2006-08-11 09:14:50 得分 0

up!  
   
  mark!  
   
   
  Top

39 楼rootcn(沙砾)回复于 2006-08-11 09:20:29 得分 0

good.Top

40 楼Godfinger(no1dog)回复于 2006-08-11 09:22:59 得分 0

那道Java的模式设计没人愿意试试看吗Top

41 楼areswang(西游不记)回复于 2006-08-11 09:29:42 得分 0

MARK!Top

42 楼hbwhwang(【生病了,好好休息中...】)回复于 2006-08-11 09:33:10 得分 0

都不来,我等下来做Top

43 楼Godfinger(no1dog)回复于 2006-08-11 11:33:18 得分 0

其实这门课虽然是java程序设计,但是重点不在语法上Top

44 楼Godfinger(no1dog)回复于 2006-08-11 12:58:21 得分 0

自己给自己顶一下吧Top

45 楼Godfinger(no1dog)回复于 2006-08-11 14:04:51 得分 0

顶一下Top

46 楼sxnucseven(*)回复于 2006-08-11 14:23:44 得分 0

嗯     差别很大  
  国内出题肯定都是让职业程序员都头疼的语法细节问题  
  很少有这样宏观方法上去解决问题的试题  
  哎。。。可怜中国的软件工人啊,只能去接触语法,像翻译一样的工作。Top

47 楼Godfinger(no1dog)回复于 2006-08-11 16:00:56 得分 0

顶一下Top

48 楼xiao7cn(o(∩_∩)o... 哈哈!)回复于 2006-08-11 16:05:42 得分 0

upTop

49 楼xiachedan(瞎扯蛋)回复于 2006-08-11 16:22:13 得分 0

英文,看不懂!Top

50 楼Godfinger(no1dog)回复于 2006-08-11 17:05:52 得分 0

楼上的,烧鸡不是帮我们翻译好了吗?大致就这意思Top

51 楼Godfinger(no1dog)回复于 2006-08-11 18:11:58 得分 0

顶一下  
  Top

52 楼flyingdancing2005(返璞归C)回复于 2006-08-11 19:49:50 得分 0

学E文去了Top

53 楼Godfinger(no1dog)回复于 2006-08-11 21:02:07 得分 0

顶一下  
  Top

54 楼laiseeme(huihui)回复于 2006-08-11 21:05:14 得分 0

没有人能解答么?  
  期待答案  
  学习Top

55 楼Godfinger(no1dog)回复于 2006-08-11 22:00:16 得分 0

期待答案  
  Top

56 楼Godfinger(no1dog)回复于 2006-08-12 00:55:14 得分 0

怎么没人回答另外道题目?  
  Top

57 楼Godfinger(no1dog)回复于 2006-08-12 10:44:55 得分 0

顶一下Top

58 楼xiao7cn(o(∩_∩)o... 哈哈!)回复于 2006-08-12 11:46:48 得分 0

一个运行在网络上的客户端程序,显示从服务器发来的周期性更新的股价信息。这个客户端程序的设计包含如下类:  
  Stock类:此类具有这个公司和股票的唯一标识、最新价格、最新更新时间、持有数量等等。  
  StockData类:它保存一组Stock对象,来表示用户的证券清单。  
  StockUpdater类:它从网络上接收一系列的股价信息,然后从StockData组中逐个提取Stock对象,并更新它。  
  ScreenView类:每当StockData被更新时,这个类的对象将更新的数据在屏幕上表示出来(显示股票代码、描述、价格等等)。ScreenView类支持多种不同的显示格式(比如网格、图形表示),且可能允许增加新的格式。  
  LogFile类:每当StockData被更新时,这个类的对象用最新数据来更新磁盘上的股票信息。  
   
  请说明如何使用如下几种设计模式来设计这个系统:  
  i)Observer   (观察者模式)  
  ii)Singleton     (单态模式)  
  iii)Iterator     (跌代器模式)  
   
  在你的回答中,对于每一种模式:  
  1)描述它的用途。  
  2)说明它应该用在哪里,为什么它在那里的作用是合适的?  
  3)描述它的结构,给出一个UML类图(在合适的地方),   并用大致的Java代码来说明它在系统中的作用(在Java提供了对该模式直接支持的地方,你也可以使用它)。  
  Top

59 楼wts173(Knight Figo)回复于 2006-08-12 13:17:35 得分 0

markTop

60 楼Godfinger(no1dog)回复于 2006-08-14 18:28:14 得分 0

结贴了Top

相关问题

关键词

得分解答快速导航

  • 帖主:Godfinger
  • hbwhwang
  • xiao7cn
  • xiao7cn

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
x 提问