南软19官方机试练习题

相对简单

题干

Nextday用于计算当前日期的下一天的日期。
需要补充实现有功能注释的函数
Year.java

public class Year extends CalendarUnit {
   
	private int year;
	public Year(int pYear) {
   
		setYear(pYear);
	}
	
	//设置年份
	public void setYear(int pYear) {
   
		this.year = pYear;
		if(!isValid()) {
   
			throw new IllegalArgumentException("Not a valid year");
			
		}
	}
	
	//获取年份
	public int getYear() {
   
		return year;
	}
	
	//实现年份的增�? 
	@Override
	public boolean increment() {
   
		year++;
		return true;
	}
	
	//判断是否是闰�?(能被4整除但不能被100整除,且能被400整除)
	public boolean isLeap() {
   
		boolean flag = false ;
		if(year%4 ==0 && year%100 !=0 || year%400 == 0){
   
			flag =true ; 
		}
		return flag;
	}
	
	//判断年份是否合法
	@Override
	protected boolean isValid() {
   
		boolean flag = false;
		if(this.year > 0 ){
   
			flag = true ; 
		}
		
		return flag;
	}
	
	//判断年份是否相等
	public 
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package ms; import robocode.*; import java.util.*; //******************************************************************************************/ // GoodBot: determine, if a bot is a bastart or not // // needed: public void run() // GoodBot.Reset(); // public void onRobotDeath(RobotDeathEvent e) // GoodBot.BotDeath(e.getName(), this); // // example: public void onScannedRobot(ScannedRobotEvent e) // if (GoodBot.badBot(e.getName(), this)) //******************************************************************************************/ class GoodBot { static private Hashtable Bots = new Hashtable(); static private int GoodBots1 = 1; static private int GoodBots2 = 0; static private String bot; static public int KilledGoodBots1 = 0; static public int KilledGoodBots2 = 0; //******************************************************************************************/ // BadBot: is it a bad bot? //******************************************************************************************/ public static boolean badBot(String Name, AdvancedRobot in_this) { bot = (String)Bots.get(Name); if (bot == null) classBot(Name, in_this); int others = in_this.getOthers(); if ( (bot.compareTo("1") == 0) && (others >= GoodBots1 - KilledGoodBots1) ) return false; else if ( (bot.compareTo("2") == 0) && (others >= GoodBots1 - KilledGoodBots1 + GoodBots2 - KilledGoodBots2) ) return false; else return true; } public static void BotDeath(String Name, AdvancedRobot in_this) { bot = (String)Bots.get(Name); if (bot == null) classBot(Name, in_this); if ( bot.compareTo("1") == 0 ) KilledGoodBots1++; else if ( bot.compareTo("2") == 0 ) KilledGoodBots2++; } public static void Reset() { KilledGoodBots1 = 0; KilledGoodBots2 = 0; } private static void classBot(String Name, AdvancedRobot in_this) { int M_GoodBots = GoodBots1; String Gegnertyp = botTyp(Name); String Mytyp = botTyp(in_this.getName()); if (Gegnertyp.compareTo(Mytyp) == 0) { bot = "1"; if (GoodBots1 > M_GoodBots) in_this.out.println("I've found " + (GoodBots1 - 1) + " more " + Mytyp + "-Bot(s)."); } else { GoodBots1 = M_GoodBots; String Gegnerpack = botTyp2(Name); String Mypack = botTyp2(in_this.getName()); if (Gegnerpack.compareTo(Mypack) == 0) { bot = "2"; GoodBots2++; in_this.out.println("I've found " + (GoodBots2) + " more " + Mypack + "-Bot(s)."); } else bot = "0"; } Bots.put(Name, new String(bot)); } private static String botTyp(String BotName) { int k=BotName.indexOf("("); if (k != -1) { int Nr=Integer.parseInt(BotName.substring(k+1, BotName.indexOf(")")),10); if (GoodBots1 < Nr) GoodBots1 = Nr; return BotName.substring(0, k-1); } else return BotName; } private static String botTyp2(String BotName) { int k=BotName.indexOf("."); if (k != -1) { return BotName.substring(0, k); } else return BotName; } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值