2017-06-04 35 views
-5

問題 - 文件處理[20分]Java文件處理DisplayOnConsole

鑑於對第一國民銀行客戶的一些帳戶信息如下數據:

111111約翰·史密斯500

222222馬克史密斯1500

333333史蒂夫·瓊斯2000

444444瑪麗瓊斯1000

  Write a Java program that: 

a。將上述數據寫入文件「payroll.txt」。

b。從「payroll.txt」中讀取上述數據。

c。關於java控制檯上顯示了每個客戶的帳戶信息如下:

賬戶1 ID:111111名:約翰·史密斯的平衡:$ 500

帳戶2 ID:222222名:馬克·史密斯餘額:1500 $

Account 3 id: 333333 name: steve jones balance: 2000 $ 

帳戶4 ID:444444名稱:瑪麗瓊斯餘額:1000 $

d。計算和顯示所有客戶的總餘額: 所有賬戶的餘額合計爲5000 $


我只能做一部分& BI需要幫助的C部分& d請

import java.io.*; 
import java.util.Scanner; 
public class FileHandling { 
    public static void main(String[] args) throws Exception { 

     PrintWriter out = new PrintWriter("payroll.txt"); 
     out.println("111111 john smith 500"); 
     out.println("222222 mark smith 1500"); 
     out.println("333333 steve jones 2000"); 
     out.println("444444 mary jones 1000"); 
     out.close(); 
     Scanner in=new Scanner("payroll.txt"); 
     while (in.hasNext()){ 

回答

-2

Ç 。

System.out.println("Account 1 id 111111 name: john smith balance: 500 $"); 
System.out.println("Account 2 id 222222 name: mark smith balance: 1500 $"); 
System.out.println("Account 3 id 333333 name: steve jones balance: 2000 $"); 
System.out.println("Account 4 id 444444 name: mary jones balance: 1000 $"); 

如果您有變量數據,則可以使用字符串連接直接從變量中替換每個id,名稱和餘額。 d)。

int totalBalance = 500 + 1500 + 2000 + 1000; 
System.out.println("Total balance of all accounts is " + totalBalance + " $");