编了一段代码 语法没有问题 但是程序运行到红色代码的那一行就运行不下去了 找不到问题所在 求问大佬解惑
import FormatIO.*;
public class part1 {
public static void main(String[] arg)
{
Console con = new Console();
con.print("Creat new account");
con.println("Please enter your first account number:");
String accountNumber = con.readLine();
con.println("Please enter your initial balance:");
double initialBalance = con.readDouble();
String fileName = "account-"+accountNumber+".txt";
FileOut fout = new FileOut(fileName);
String accountLine = accountNumber+" "+initialBalance;
fout.print(accountLine);
con.println("Account file <"+fileName+"> written") ;
fout.close();
con.println("Please enter your second account number:");
accountNumber = con.readLine();
con.println("Please enter your initial balance:");
initialBalance = con.readDouble();
fileName = "account-"+accountNumber+".txt";
fout = new FileOut(fileName);
accountLine = accountNumber+""+initialBalance;
fout.print(accountLine);
con.println("Account file <"+fileName+"> written") ;
fout.close();
/*
* Step1 is completed
*/
con.print("Please enter the number of your apartment rental months to be paid:");
int months = con.readInt();
con.println("Please enter the rent per month:");
double perRent = con.readDouble();
double rent = months*perRent;
con.println(String.format("The total rent that you need to pay is %.2f", rent));
con.println("Please enter your bank account number:");
accountNumber = con.readLine();
fileName = "account-"+accountNumber+".txt";
FileIn fIn = new FileIn(fileName);
accountNumber = fIn.readWord();
double balance = fIn.readDouble();
fIn.close();
balance = balance-rent;
fout = new FileOut(fileName);
accountLine = accountNumber+" "+balance;
fout.print(accountLine);
con.println("successful payment");
fout.close();
}
}
题主悬赏了10铜
|
已采纳 yes_rpg 的答案
有木有会java的大佬 解惑一段很简单的代码
回答
-
在p9你甚至可以讨论java
-
yes_rpg @youmenjun 甚至可以被采纳233
-
-
double balance = Double.valueOf(acountNumber+“”);
-
@yes_rpg 很感谢回复 但是我看了答案 fileName的格式(红色部分)跟我的是一样的 但是这一整串代码是可以运行的
import FormatIO.*;
public class Lab5 {
public static void main(String[] arg)
{
Console con = new Console("Open New Bank Accounts") ;
con.print("Enter first bank account number: ") ;
String accountNumber = con.readLine() ;
con.print("Enter initial balance of account "+accountNumber+": £") ;
double initialDeposit = con.readDouble() ;
String fileName = "account-"+accountNumber+".txt" ;
String accountLine = accountNumber+" "+initialDeposit ;
FileOut fout = new FileOut(fileName) ;
fout.println(accountLine) ;
con.println("Account file <"+fileName+"> written") ;
fout.close() ;
con.print("\nEnter second bank account number: ") ;
accountNumber = con.readLine() ;
con.print("Enter initial balance of account "+accountNumber+": £") ;
initialDeposit = con.readDouble() ;
fileName = "account-"+accountNumber+".txt" ;
accountLine = accountNumber+" "+initialDeposit ;
fout = new FileOut(fileName) ;
fout.println(accountLine) ;
con.println("Account file <"+fileName+"> written") ;
fout.close() ;
con.println("\n\nPayment") ;
con.print("Enter number of apartment rental months to be paid: ") ;
int months = con.readInt() ;
con.print("Enter the monthly price of the apartment: £") ;
double rental = con.readDouble() ;
double price = rental * months ;
con.println(String.format("The total price is £%.2f", price)) ;
con.print("Enter account number to be debited: ") ;
accountNumber = con.readLine() ;
fileName = "account-"+accountNumber+".txt" ;
FileIn fin = new FileIn(fileName) ;
accountNumber = fin.readWord();
double balance = fin.readDouble();
fin.close() ;
balance = balance - price ;
accountLine = accountNumber+" "+balance ;
fout = new FileOut(fileName) ;
fout.println(accountLine) ;
fout.close() ;
con.println("Account file <"+fileName+"> written") ;
con.println(String.format("The new balance of account %s is £%.2f",accountNumber,balance)) ;
}
} -
public static void main(String[] arg)
{
Console con = new Console();
con.print("在p9你甚至能讨论游戏");
} -
在p9你甚至能讨论游戏系列
发表评论,请先 登录