建筑模块【难度:1级】:
答案1:
class Block
{
public int Width { get ; private set ; }
public int Length { get ; private set ; }
public int Height { get ; private set ; }
public Block ( int [ ] properties) {
this . Width = properties[ 0 ] ;
this . Length = properties[ 1 ] ;
this . Height = properties[ 2 ] ;
}
public int GetWidth ( ) { return Width; }
public int GetLength ( ) { return Length; }
public int GetHeight ( ) { return Height; }
public int GetVolume ( ) { return GetWidth ( ) * GetHeight ( ) * GetLength ( ) ; }
public int GetSurfaceArea ( ) {
return ( 2 * GetLength ( ) * GetWidth ( ) )
+ ( 2 * GetLength ( ) * GetHeight ( ) )
+ ( 2 * GetWidth ( ) * GetHeight ( ) ) ;
}
}
答案2:
using System;
class Block
{
private readonly int _width;
private readonly int _length;
private readonly int _height;
public Block ( int [ ] p)
{
if ( p. Length != 3 || p[ 0 ] <= 0 || p[ 1 ] <= 0 || p[ 2 ] <= 0 )
{
throw new ArgumentException ( ) ;
}
this . _width = p[ 0 ] ;
this . _length = p[ 1 ] ;
this . _height = p[ 2 ] ;
}
public int GetWidth ( )
{
return _width;
}
public int GetLength ( )
{
return _length;
}
public int GetHeight ( )
{
return _height;
}
public int GetVolume ( )
{
return _width* _length* _height;
}
public int GetSurfaceArea ( )
{
return 2 * ( _width* _length + _length* _height + _width* _height) ;
}
}
答案3:
class Block
{
private int width, length, height;
public Block ( int [ ] data)
{
width = data[ 0 ] ;
length = data[ 1 ] ;
height = data[ 2 ] ;
}
public int GetWidth ( )
{
return width;
}
public int GetLength ( )
{
return length;
}
public int GetHeight ( )
{
return height;
}
public int GetVolume ( )
{
return width * length* height;
}
public int GetSurfaceArea ( )
{
return 2 * ( width* length + length* height + height* width) ;
}
}
答案4:
class Block
{
int [ ] dimension;
public Block ( int [ ] dim) {
dimension = dim;
}
public int GetWidth ( ) {
return dimension[ 0 ] ;
}
public int GetLength ( ) {
return dimension[ 1 ] ;
}
public int GetHeight ( ) {
return dimension[ 2 ] ;
}
public int GetVolume ( ) {
return dimension[ 0 ] * dimension[ 1 ] * dimension[ 2 ] ;
}
public int GetSurfaceArea ( ) {
return 2 * ( dimension[ 0 ] * dimension[ 1 ] + dimension[ 1 ] * dimension[ 2 ] + dimension[ 2 ] * dimension[ 0 ] ) ;
}
}
答案5:
class Block
{
int width;
int length;
int height;
public Block ( int [ ] dimensions)
{
this . width = dimensions[ 0 ] ;
this . length = dimensions[ 1 ] ;
this . height = dimensions[ 2 ] ;
}
public int GetWidth ( ) { return width; }
public int GetLength ( ) { return length; }
public int GetHeight ( ) { return height; }
public int GetVolume ( ) { return width * length* height; }
public int GetSurfaceArea ( ) { return 2 * ( width* length+ width* height+ length* height) ; }
}
答案6:
using System;
class Block
{
private int width;
private int length;
private int height;
public Block ( int [ ] args) {
if ( args. Length != 3 )
throw new Exception ( "invalid arguments" ) ;
SetWidth ( args[ 0 ] ) ;
SetLength ( args[ 1 ] ) ;
SetHeight ( args[ 2 ] ) ;
}
private void SetWidth ( int width) {
this . width = width;
}
private void SetLength ( int length) {
this . length = length;
}
private void SetHeight ( int height) {
this . height = height;
}
public int GetWidth ( ) {
return this . width;
}
public int GetLength ( ) {
return this . length;
}
public int GetHeight ( ) {
return this . height;
}
public int GetVolume ( ) {
return this . width * this . height * this . length;
}
public int GetSurfaceArea ( ) {
return 2 * ( this . width * this . height + this . width * this . length + this . height * this . length) ;
}
}
答案7:
class Block {
private int w, l, h;
public Block ( int [ ] dim) {
w = dim[ 0 ] ; l = dim[ 1 ] ; h = dim[ 2 ] ;
}
public int GetWidth ( ) { return w; }
public int GetLength ( ) { return l; }
public int GetHeight ( ) { return h; }
public int GetVolume ( ) { return w * l* h; }
public int GetSurfaceArea ( ) {
return 2 * w* l + 2 * w* h + 2 * l* h;
}
}
答案8:
class Block
{
private int _width { get ; set ; }
private int _length { get ; set ; }
private int _height { get ; set ; }
public Block ( int [ ] arr)
{
_width = arr[ 0 ] ;
_length = arr[ 1 ] ;
_height = arr[ 2 ] ;
}
public int GetWidth ( ) = > _width;
public int GetLength ( ) = > _length;
public int GetHeight ( ) = > _height;
public int GetVolume ( )
{
return _width * _length * _height;
}
public int GetSurfaceArea ( )
{
return 2 * _length * _width + 2 * _length * _height + 2 * _width * _height;
}
}
答案9:
class Block
{
public int [ ] a{ get ; set ; }
public Block ( int [ ] b) { a= b; }
public int GetWidth ( ) { return a[ 0 ] ; }
public int GetLength ( ) { return a[ 1 ] ; }
public int GetHeight ( ) { return a[ 2 ] ; }
public int GetVolume ( ) { return a[ 0 ] * a[ 1 ] * a[ 2 ] ; }
public int GetSurfaceArea ( ) { return ( a[ 0 ] * a[ 1 ] + a[ 0 ] * a[ 2 ] + a[ 1 ] * a[ 2 ] ) * 2 ; }
}
答案10:
class Block
{
private int width;
private int height;
private int length;
public Block ( int [ ] values)
{
width = values[ 0 ] ;
height = values[ 1 ] ;
length= values[ 2 ] ;
}
public int GetWidth ( )
{
return width;
}
public int GetLength ( )
{
return height;
}
public int GetHeight ( )
{
return length;
}
public int GetVolume ( )
{
return length * height* width;
}
public int GetSurfaceArea ( )
{
return 2 * ( length * height + width * height + width * length) ;
}
}