Playing with cubes II
Description:
Hey Codewarrior!
You already implemented a Cube class, but now we need your help again! I'm talking about constructors. We don't have one. Let's code two: One taking an integer and one handling no given arguments!
Also we got a problem with negative values. Correct the code so negative values will be switched to positive ones!
The constructor taking no arguments should assign 0 to Cube's Side property.
http://www.codewars.com/kata/playing-with-cubes-ii/csharp
using System; public class Cube
{
private int Side; //This cube needs your help.
//Define a constructor which takes one integer and assignes its value to 'Side'
public Cube()
{} public Cube(int side)
{
this.Side = Math.Abs(side);
} public int GetSide()
{
return this.Side;
} public void SetSide(int s)
{
this.Side = Math.Abs(s);
}
}
可以使用this来处理构造函数,无参构造函数,字段的默认值,可以通过调用有参函数来处理
赋值的时候,可以调用类本身的函数
public class Cube
{
private int Side; //This cube needs your help.
//Define a constructor which takes one integer and assignes its value to 'Side'
public Cube(int s)
{
SetSide(s);
} public Cube()
: this()
{ }
public int GetSide()
{
return Side;
} public void SetSide(int s)
{
Side = System.Math.Abs(s);
}
}
可以使用函数的缺省参数
using System; public class Cube
{
private Int32 _side; public Cube(Int32 Side = ){
SetSide(Side);
} public Int32 GetSide()
{
return this._side;
} public void SetSide(Int32 Side)
{
this._side = Math.Abs(Side);
}
}
Playing with cubes II的更多相关文章
- Codeforces Round #274 (Div. 2) B. Towers
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting o ...
- Codeforces 479B. Towers 暴力
纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Playing with ptrace, Part II
Playing with ptrace, Part II Issue From Issue # December Dec , By Pradeep Padala inSysAdmin In Part ...
- [LeetCode] Guess Number Higher or Lower II 猜数字大小之二
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...
- (转) Deep Reinforcement Learning: Playing a Racing Game
Byte Tank Posts Archive Deep Reinforcement Learning: Playing a Racing Game OCT 6TH, 2016 Agent playi ...
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...
- HDU 4043 FXTZ II (组合数学-排列组合)
FXTZ II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- Flip Game I && II
Flip Game I Problem Description: You are playing the following Flip Game with your friend: Given a s ...
- hdu 5265 pog loves szh II
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5265 pog loves szh II Description Pog and Szh are pla ...
随机推荐
- Object-C - 类的定义
http://www.cnblogs.com/zhangweia/archive/2011/11/01/2231549.html 1. 文件分为.h:定义接口,及其属性,方法说明. .m :是实现类. ...
- spring-cloud-bus
安装rabbitmq 依赖erlang: http://erlang.org/download/otp_win64_18.2.exe
- 《WPF程序设计指南》读书笔记——第2章 基本画刷
1.Color结构 using System; using System.Windows; using System.Windows.Input; using System.Windows.Media ...
- SRM 616 ColorfulCoins
题意:给定一个从小到大的货币面值,每一个面额都是其前面面额的倍数(倍数大于等于2),每一种货币面值对应一种颜色,目前不清楚面值与颜色的对应关系.要求用最少的查询次数来确定面额与颜色的对应关系.(一次查 ...
- php数组内容分页的例子(转)
php数组内容分页代码 时间:2016-03-04 23:46:34来源:网络 导读:php数组内容分页代码,当前页如果大于总页数,当前页为最后一页,分页显示时,应该从多少条信息开始读取数据. p ...
- java8 新特性
[转载]:http://www.importnew.com/11908.html 本文由 ImportNew - 刘 家财 翻译自 javacodegeeks.欢迎加入翻译小组.转载请见文末要求. 编 ...
- C#中 Thread.Sleep精度问题
Thread.Sleep的精度默认在15ms左右,如果需要类似 Thread.Sleep(1)的精细控制,需要调用特定的平台API实现 [DllImport("winmm.dll" ...
- 【概率】BZOJ 3450:Tyvj1952 Easy
Description 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:( 我们来简化一下这个游戏的规则 有n次点击要做,成功了就是o,失败了就是x,分数是按comb计算的,连 ...
- PAT-乙级-1038. 统计同成绩学生(20)
1038. 统计同成绩学生(20) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求读入N名学生的成绩,将 ...
- hdu 1087
动规 d[i]记录以第 i 个数结尾的最大值 #include <cstdio> #include <algorithm> #include <cstring> ...