Java定义一个表示人民币的类Money,
1定义整形成员变量yuan,jiao,fen,分别表示元角分。2构造方法,利用实数表示的金额初始化成员yuan,jiao,fen3voidshow()方法按XX元XX角X...
1定义整形成员变量yuan,jiao,fen,分别表示元角分。
2构造方法,利用实数表示的金额初始化成员yuan,jiao,fen
3void show()方法按XX元XX角XX分格式输出
4在主方法中,接受一个实数输入,创建Money对象,再调用show()方法输出。 展开
2构造方法,利用实数表示的金额初始化成员yuan,jiao,fen
3void show()方法按XX元XX角XX分格式输出
4在主方法中,接受一个实数输入,创建Money对象,再调用show()方法输出。 展开
2个回答
展开全部
public class Money {
private int yuan;
private int jiao;
private int fen;
public Money(int yuan,int jiao, int fen){
this.yuan=yuan;
this.jiao=jiao;
this.fen=fen;
}
public void show(){
System.out.printf("%d元%d角%d分",yuan,jiao,fen);
}
public static void main(String[] args) {
Money m=new Money(4,5,6);
m.show();
}
}
private int yuan;
private int jiao;
private int fen;
public Money(int yuan,int jiao, int fen){
this.yuan=yuan;
this.jiao=jiao;
this.fen=fen;
}
public void show(){
System.out.printf("%d元%d角%d分",yuan,jiao,fen);
}
public static void main(String[] args) {
Money m=new Money(4,5,6);
m.show();
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
money实体类:
public class Money {//1 定义整形成员变量yuan,jiao,fen
private int yuan;
private int jiao;
private int fen;
public Money(int yuan,int jiao,int fen){//2 构造方法,初始化成员yuan,jiao,fen
this.yuan = yuan;
this.jiao = jiao;
this.fen = fen;
}
public int getYuan() {
return yuan;
}
public void setYuan(int yuan) {
this.yuan = yuan;
}
public int getJiao() {
return jiao;
}
public void setJiao(int jiao) {
this.jiao = jiao;
}
public int getFen() {
return fen;
}
public void setFen(int fen) {
this.fen = fen;
}
}
入口点/主方法:
public class MoneyShow {
public void show(Money money){//3 void show()方法按XX元XX角XX分格式输出
System.out.println(money.getYuan()+"元"+money.getJiao()+"角"+money.getFen()+"分");
}
public static void main(String[] args) {
int yuan = 10,jiao = 5,fen = 3;
Money money = new Money(yuan,jiao,fen);//4 创建Money对象,再调用show()方法输出
MoneyShow ms = new MoneyShow();
ms.show(money);
}
}
public class Money {//1 定义整形成员变量yuan,jiao,fen
private int yuan;
private int jiao;
private int fen;
public Money(int yuan,int jiao,int fen){//2 构造方法,初始化成员yuan,jiao,fen
this.yuan = yuan;
this.jiao = jiao;
this.fen = fen;
}
public int getYuan() {
return yuan;
}
public void setYuan(int yuan) {
this.yuan = yuan;
}
public int getJiao() {
return jiao;
}
public void setJiao(int jiao) {
this.jiao = jiao;
}
public int getFen() {
return fen;
}
public void setFen(int fen) {
this.fen = fen;
}
}
入口点/主方法:
public class MoneyShow {
public void show(Money money){//3 void show()方法按XX元XX角XX分格式输出
System.out.println(money.getYuan()+"元"+money.getJiao()+"角"+money.getFen()+"分");
}
public static void main(String[] args) {
int yuan = 10,jiao = 5,fen = 3;
Money money = new Money(yuan,jiao,fen);//4 创建Money对象,再调用show()方法输出
MoneyShow ms = new MoneyShow();
ms.show(money);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询