一、People类
package org.jsoft.FengZhuang;
public class People { //人
private float height;
private float weight;
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
public void speakHello(){
System.out.println("Hello");
}
public float averageHeight(){
return getHeight();
}
public float averageWeight(){
return getWeight();
}
}
package org.jsoft.FengZhuang;
public class ChinaPeople extends People{ //中国人
public String chinaMartial(){
return "太极,武术,拳法";
}
public void speakHello(){
System.out.println("打招呼说您好!");
}
public float averageHeight(){
return this.getHeight();
}
public float averageWeight(){
return this.getWeight();
}
}
package org.jsoft.FengZhuang;
public class AmericanPeople extends People{ //美国人
public String AmericanBoxing(){
return "搏击,格斗";
}
public float averageHeight(){
return this.getHeight();
}
public float averageWeight(){
return this.getWeight();
}
}
package org.jsoft.FengZhuang;
public class BeijingPeople extends ChinaPeople{ //北京人
public String BeijingOpera(){
return "说唱脸谱";
}
public float averageHeight(){
return this.getHeight();
}
public float averageWeight(){
return this.getWeight();
}
}
二、Account类
package org.jsoft.FengZhuang;
public class Account {
private long id; //账户id
private double balance; //账户余额
private String passward; //账户密码
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public String getPassward() {
return null;
}
public void setPassward(String passward) {
if(passward.length()==6){
this.passward = passward;
}else{
System.out.println("密码不是六位,修改失败");
}
}
}
package org.jsoft.FengZhuang;
public class SavingAccount extends Account{
private double interestRate; //存款利率
public double getInterestRate() {
return interestRate;
}
public void setPassward(String passward) {
if(passward.length()==6){
super.setPassward(passward);
System.out.println("储蓄帐户"+super.getId()+"密码修改成功");
}else{
System.out.println("密码不是六位,修改失败");
}
}
public void setInterestRate(double interestRate) {
if(interestRate>0&&interestRate<0.1){
this.interestRate = interestRate;
}
}
}
package org.jsoft.FengZhuang;
public class CreditAccount extends Account{
private double creditLine;
public double getCreditLine() {
return creditLine;
}
public void setCreditLine(double creditLine) {
this.creditLine = creditLine;
}
public void setPassward(String passward) {
if(passward.length()==6){
super.setPassward(passward);
System.out.println("信用用户"+super.getId()+"密码修改成功");
}else{
System.out.println("密码不是六位,修改失败");
}
}
}
package org.jsoft.FengZhuang;
public class TestAccount {
public static void main(String[] args) {
SavingAccount saveAccount=new SavingAccount();
saveAccount.setId(123456789);
saveAccount.setPassward("266666");
saveAccount.setBalance(800);
saveAccount.setInterestRate(0.08);
System.out.println("储蓄银行的利率为:"+saveAccount.getInterestRate());
CreditAccount creditAccount=new CreditAccount();
creditAccount.setId(987654321);
creditAccount.setPassward("111111");
creditAccount.setBalance(117);
System.out.println("信用帐户"+creditAccount.getId()+"的信用额度为"+creditAccount.getBalance());
}
}
三、 A
四、
右上角
在不同包类:MyClass mc2=new MyClass(10); 不能调用缺省的构造函数
私有类型不能直接点出来
左下角
私有类型不能直接点出来