티스토리 뷰
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication2
{
public class Animal
{
protected string Name;
private int Level;
private int maxLevel = 100;
private int minLevel = 1;
public string UpLevel()
{
string message;
if (this.Level < this.maxLevel)
message = (Level++).ToString;
else
message = "레벨을 증가시킬수없당";
return message;
}
public string UpLevel(int Level)
{
string message;
if (this.Level < this.maxLevel)
{
this.Level += Level;
message = this.Level.ToString();
}
else
message = "레벨을 증가시킬수없당";
return message;
}
public string GetName()
{
return Name;
}
public int GetLevel()
{
return Level;
}
public Animal()
{ }
public Animal(int Level):this()
{
if (Level < this.minLevel)
this.Level = this.minLevel;
else if (Level > this.maxLevel)
this.Level = this.maxLevel;
else
this.Level = Level;
}
public Animal(int Level, string Name): this(Level)
{ this.Name = Name; }
}
public class Cat : Animal
{
public Cat() { }
public Cat(int Level)
: base(Level)
{ }
public Cat(int Level, string Name)
: this(Level)
{
base.Name = Name;
}
}
public class Dog : Animal
{
public Dog() { }
public Dog(int Level)
: base(Level)
{ }
public Dog(int Level, string Name)
: this(Level)
{
base.Name = Name;
}
}
}
-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Animal[] animals;
int maxNo;
int currentNo;
public Form1()
{
InitializeComponent();
maxNo=10;
animals=new Animal[maxNo];
currentNo = 0;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void making_Click(object sender, EventArgs e)
{
if(comboBox1.SelectedIndex == 0)
{ animals[currentNo] = new Dog(int.Parse(textBox2.Text),textBox1.Text);}
else if (comboBox1.SelectedIndex == 1)
{ animals[currentNo] = new Cat(int.Parse(textBox2.Text),textBox1.Text); }
else
return;
listbox1.Items.Clear();
for (int i = 0; i < currentNo; i++)
{
listbox1.Items.Add(animals[i].GetName());
}
}
}
}
'IT Skills > Programming' 카테고리의 다른 글
C# 인터페이스 (0) | 2013.05.06 |
---|---|
JAVA 전쟁 프로젝트 (0) | 2013.05.06 |
C# - 동물농장 참고자료#2 (0) | 2013.04.22 |
C# - 시험참고자료#` (0) | 2013.04.22 |
java 계산기 (0) | 2013.04.15 |
- Total
- Today
- Yesterday
- 프로그래밍
- 라이언
- 디지몬
- ps4
- 아이폰X
- 고양이
- 듀얼쇼크4
- AMD
- 카카오프렌즈
- m5a97
- 일본
- razer
- 애드센스
- javascript
- 플스2
- 건담
- Windows 10
- 이어폰
- 보스
- 디지바이스
- 윈도우즈 10
- 구글
- PS2
- 노트북
- 피규어
- 안산
- 일본여행
- 프라모델
- Asus
- 마우스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |