import java.util.Scanner;
class Goods{
private String name;
private double price;
public void setname(){
String name;
Scanner in = new Scanner(System.in);
name = in.nextLine();
this.name = name;
in.close();
}
public void setprice( ){
double price;
Scanner in = new Scanner(System.in);
price = in.nextDouble();
this.price = price;
in.close();
}
public String getname(){
return this.name;
}
public double getprice(){
return this.price;
}
}
class Store{
private double harvest;
public void sell(Goods a1){
System.out.println("请输入要卖的商品:"+a1.getname());
System.out.println("正在交易中请稍后");
this.harvest = a1.getprice();
System.out.println("微信收款"+a1.getprice());
}
public void setPriceAndName(Goods a1){
System.out.println("please set name and price of the goods");
a1.setname();
a1.setprice();
}
public double getharvest(){
return this.harvest;
}
}
public class Tester{
public static void main(String[] args){
System.out.println("please start");
Store yang = new Store();
Goods a1 = new Goods();
yang.setPriceAndName(a1);
yang.sell(a1);
System.out.println("请输出获得的收入:"+yang.getharvest());
}
}
编译通过,运行出错。输入有问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- CSDN专家-link 2022-03-09 20:54关注
Scanner in = new Scanner(System.in);
输入代码不要放在函数里,放到main函数中,将输入值作为参数传递给set函数解决 1无用
悬赏问题
- ¥15 网络爬虫 在北京新发地抓取数据
- ¥15 在centos7安装conda
- ¥15 c#调用yolo3 dll文件获取的数据对不上
- ¥20 WPF 如何实现多语言,label 和cs(live Charts)中是否都能翻译
- ¥15 STM32F103上电短路问题
- ¥15 关于#单片机#的问题:以ATMEGA128或相近型号单片机为控制器设计直流电机调速的闭环控制系统(相关搜索:设计报告|软件设计|流程图)
- ¥15 打开软件提示错误:failed to get wglChoosePixelFormatARB
- ¥15 (标签-python|关键词-char)
- ¥15 python+selenium,在新增时弹出了一个输入框
- ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。