私の問題は、File Reader で顧客名を読み取る方法がわからないことです。
予約システムを作っていますが、顧客がすでに存在することを知る必要があります。そのため、誰かが既に顧客であるかどうかを確認できるように、Customers.txt ファイルを読み取る必要があります。彼がそうでない場合は、ファイルライターで新しいものを作成します(私はすでにコードを持っています)。
この予約制の意味は、理容室に予約を入れることです。予約を Reservations.txt という別の txt ファイルに入れる必要があります。そのファイルでは、各予約時間と予約者を確認できます。
助けてくれてありがとう!
これは私がすでに持っているコードです: (いくつかのコメントはオランダ語ですが、翻訳します)
package nielbutaye;
import java.io.*;
import java.util.UUID;
/**
* @author Niel
*
*/
public class Klant {
//declaration that represents the text
public static String S;
public static String NEWLINE = System.getProperty("line.separator");
/**
* constructor
*/
public Klant(){}
/**
* @return
* By giving the name of the customer you will get all the data from the customer
*/
public double getCustomer() {
return 0 ;
}
/**
* Make a new customer
*/
public void setNew customer(){
// make a newSimpleInOutDialog
SimpleInOutDialog input = new SimpleInOutDialog("A new customer");
//input
S = "Name customer: " + input.readString("Give in your name:");
WriteToFile();
S = "Adress: " + input.readString("Give your adress");
WriteToFile();
S = "Telephonenummber: " + input.readString("Give your telephonenumber");
WriteToFile();
//making a customerID
UUID idCustomer = UUID.randomUUID();
S = "CustomerID: " + customerID.toString();
WriteToFile();
}
public void WriteToFile(){
try{
FileWriter writer = new FileWriter("L:\\Documents/Informatica/6de jaar/GIP/Customer.txt", true);
BufferedWriter out = new BufferedWriter(writer);
//Wrting away your data
out.write(S + NEWLINE);
//Closing the writer
out.close();
}catch (Exception e){//Catch when there are errors
System.err.println("Error: " + e.getMessage());
}
}
}