package com.beicai.fengzhuang;
public class TriAngle {
private int base;
private int height;
public void setBase(int a){
if(a > 0){
base = 0;
}else{
System.out.println('您输入的数值有误!');
}
}
public int getBase(){
return base;
}
public void setHeight(int i){
if(i > 0){
height = 0;
}else{
System.out.println('您输入的数值有误!');
}
}
public int getHeight(){
return height;
}
}
package com.beicai.fengzhuang;
public class TestTriAngle {
public static void main(String[] args) {
TriAngle a = new TriAngle();
a.setBase(10);
a.setHeight(10);
package com.beicai.oop;
public class TestAnimal {
public static void main(String[] args) {
Animal a1 = new Animal();
a1.name = '花花';
a1.legs = 4;
a1.info();
a1.eat();
a1.color = 'white';
}
}
class Animal{
public String color;//动物的颜色
String name;//动物的名字
int legs;//几条腿
public void eat(){
System.out.println('动物吃食');
}
public void sleep(){
System.out.println('动物休眠');
}
public void color(){
System.out.println('动物颜色');
}
public void info(){
System.out.println('name:'+name+',legs:'+legs+',color:'+color);
}
//设置类的对象
public void setLegs(int l){
if(l > 0 && l % 2 == 0){