急!!在线等!一个很简单的java代码。自己编的。没有报错。但运行不出正确结果。帮帮忙。大侠们!
importjavax.swing.JOptionPane;publicclasslove{publicstaticvoidmain(String[]args){zaoz...
import javax.swing.JOptionPane;
public class love {
public static void main (String[] args){
zao zao=new zao();
zao.expense(0, 0);
wu wu= new wu();
wu.expense(0, 0);
wan wan= new wan();
wan.expense(0, 0);
day day= new day();
day.Getsum();
JOptionPane.showMessageDialog(null, day.Getsum());
}
}
class day{
String Getsum(){
return "你一天的实际花费为:"+new zao().x+new wu().x+new wan().x+"\n"+"你一天的理想花费为:"+new zao().y+new wu().y+new wan().y;
}
}
abstract class mode{
double x,y;
abstract void expense(double x,double y);
}
class zao extends mode{
double x,y;
void expense(double x,double y){
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你早餐的实际花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}
}
class wu extends mode{
double x,y;
void expense(double x,double y){
this.x=x;
this.y=y;
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你中餐的花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}
}
class wan extends mode{
void expense(double x,double y){
this.x=x;
this.y=y;
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你晚餐的花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}}
import javax.swing.JOptionPane;
public class love {
public static void main (String[] args){
zao zao=new zao();
zao.expense(0, 0);
wu wu= new wu();
wu.expense(0, 0);
wan wan= new wan();
wan.expense(0, 0);
day day= new day();
day.Getsum();
JOptionPane.showMessageDialog(null, day.Getsum());
}
}
class day{
String Getsum(){
return "你一天的实际花费为:"+new zao().x+new wu().x+new wan().x+"\n"+"你一天的理想花费为:"+new zao().y+new wu().y+new wan().y;
}
}
abstract class mode{
double x,y;
abstract void expense(double x,double y);
}
class zao extends mode{
double x,y;
void expense(double x,double y){
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你早餐的实际花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}
}
class wu extends mode{
double x,y;
void expense(double x,double y){
this.x=x;
this.y=y;
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你中餐的花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}
}
class wan extends mode{
void expense(double x,double y){
this.x=x;
this.y=y;
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你晚餐的花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}} 展开
public class love {
public static void main (String[] args){
zao zao=new zao();
zao.expense(0, 0);
wu wu= new wu();
wu.expense(0, 0);
wan wan= new wan();
wan.expense(0, 0);
day day= new day();
day.Getsum();
JOptionPane.showMessageDialog(null, day.Getsum());
}
}
class day{
String Getsum(){
return "你一天的实际花费为:"+new zao().x+new wu().x+new wan().x+"\n"+"你一天的理想花费为:"+new zao().y+new wu().y+new wan().y;
}
}
abstract class mode{
double x,y;
abstract void expense(double x,double y);
}
class zao extends mode{
double x,y;
void expense(double x,double y){
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你早餐的实际花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}
}
class wu extends mode{
double x,y;
void expense(double x,double y){
this.x=x;
this.y=y;
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你中餐的花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}
}
class wan extends mode{
void expense(double x,double y){
this.x=x;
this.y=y;
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你晚餐的花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}}
import javax.swing.JOptionPane;
public class love {
public static void main (String[] args){
zao zao=new zao();
zao.expense(0, 0);
wu wu= new wu();
wu.expense(0, 0);
wan wan= new wan();
wan.expense(0, 0);
day day= new day();
day.Getsum();
JOptionPane.showMessageDialog(null, day.Getsum());
}
}
class day{
String Getsum(){
return "你一天的实际花费为:"+new zao().x+new wu().x+new wan().x+"\n"+"你一天的理想花费为:"+new zao().y+new wu().y+new wan().y;
}
}
abstract class mode{
double x,y;
abstract void expense(double x,double y);
}
class zao extends mode{
double x,y;
void expense(double x,double y){
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你早餐的实际花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}
}
class wu extends mode{
double x,y;
void expense(double x,double y){
this.x=x;
this.y=y;
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你中餐的花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}
}
class wan extends mode{
void expense(double x,double y){
this.x=x;
this.y=y;
x=Double.parseDouble(JOptionPane.showInputDialog("请输入你晚餐的花费:", new Double(x)));
y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:", new Double(y)));
}} 展开
展开全部
你的程序我帮你改完了,你看看吧。
完整的程序如下:
import javax.swing.JOptionPane;
public class love {
public static void main (String[] args){
zao zao=new zao();
zao.expense();
wu wu= new wu();
wu.expense();
wan wan= new wan();
wan.expense();
day day= new day();
JOptionPane.showMessageDialog(null, day.Getsum(zao,wu,wan));
}
}
class day{
String Getsum(zao zao,wu wu,wan wan){
return "你一天的实际花费为:"+(zao.x+wu.x+wan.x)+"\n"+"你一天的理想花费为:"+(zao.y+wu.y+wan.y);
}
}
abstract class mode{
double x,y;
abstract void expense();
}
class zao extends mode{
double x,y;
void expense(){
this.x=Double.parseDouble(JOptionPane.showInputDialog("请输入你早餐的实际花费:"));
this.y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:"));
}
}
class wu extends mode{
double x,y;
void expense(){
this.x=Double.parseDouble(JOptionPane.showInputDialog("请输入你中餐的花费:"));
this.y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:"));
}
}
class wan extends mode{
double x,y;
void expense(){
this.x=Double.parseDouble(JOptionPane.showInputDialog("请输入你晚餐的花费:"));
this.y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:"));
}}
完整的程序如下:
import javax.swing.JOptionPane;
public class love {
public static void main (String[] args){
zao zao=new zao();
zao.expense();
wu wu= new wu();
wu.expense();
wan wan= new wan();
wan.expense();
day day= new day();
JOptionPane.showMessageDialog(null, day.Getsum(zao,wu,wan));
}
}
class day{
String Getsum(zao zao,wu wu,wan wan){
return "你一天的实际花费为:"+(zao.x+wu.x+wan.x)+"\n"+"你一天的理想花费为:"+(zao.y+wu.y+wan.y);
}
}
abstract class mode{
double x,y;
abstract void expense();
}
class zao extends mode{
double x,y;
void expense(){
this.x=Double.parseDouble(JOptionPane.showInputDialog("请输入你早餐的实际花费:"));
this.y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:"));
}
}
class wu extends mode{
double x,y;
void expense(){
this.x=Double.parseDouble(JOptionPane.showInputDialog("请输入你中餐的花费:"));
this.y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:"));
}
}
class wan extends mode{
double x,y;
void expense(){
this.x=Double.parseDouble(JOptionPane.showInputDialog("请输入你晚餐的花费:"));
this.y=Double.parseDouble(JOptionPane.showInputDialog("请输入你希望的消费金额:"));
}}
展开全部
我想问问你 你修改的x,y是哪个。
Java中 标识符 是就就近原则。--------上面你虽然是赋值了。但是实际你,后面你修改的还是那个形参。没有修改成员变量。
所以你的成员变量都是默认值:0.0
所以 最后结果是 0.0
————————————————————————————————
还有啊 ,你那个day 的那个成员方法。返回的都是new 出来的新对象,完全没有和上面那个swing 有关。那么你这个还有意义么?全是 new 出来的 默认值就是 0.0啊
你的把zao wu wan 全都传给你的day 啊 全是new 的怎么可能有值啊
要不你就是使用getter 调用 getX() 然后在 getter中调用你重写的那个方法。这样更改也行啊。
Java中 标识符 是就就近原则。--------上面你虽然是赋值了。但是实际你,后面你修改的还是那个形参。没有修改成员变量。
所以你的成员变量都是默认值:0.0
所以 最后结果是 0.0
————————————————————————————————
还有啊 ,你那个day 的那个成员方法。返回的都是new 出来的新对象,完全没有和上面那个swing 有关。那么你这个还有意义么?全是 new 出来的 默认值就是 0.0啊
你的把zao wu wan 全都传给你的day 啊 全是new 的怎么可能有值啊
要不你就是使用getter 调用 getX() 然后在 getter中调用你重写的那个方法。这样更改也行啊。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很真
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询