0
我已經創建了一個用戶添加值的text.file。這是用戶數據被讀取和驗證的部分。我的努力是,當用戶在提示時添加值時,它不會返回任何數據。它顯示爲零。我不能在某處返回值。公共靜態方法返回問題
以下是本節的說明。
「詢問用戶是否有任何更多的金額補充,不是在文本文件Ifso: 使用靜態方法來讀取和驗證金額類型和數量 使用實例方法將金額添加到總計「
這裏是我到目前爲止。感謝任何方向和幫助。
public static char readValidateAmountType()
{
System.out.println("Enter the amount type(T, D, E) you would like to enter: ");
Scanner keyboard = new Scanner(System.in);
char amountType = keyboard.next().charAt(0);
amountType = Character.toUpperCase(amountType);
do
{
if(amountType !='T' && amountType !='D' && amountType !='E')
{
System.out.println("Invalid amount type!");
System.out.println("Enter the amount type(T, D, E) you would like to enter: ");
amountType = keyboard.next().charAt(0);
amountType = Character.toUpperCase(amountType);
}
else
{
return amountType;
}
}
while(amountType !='T' && amountType !='D' && amountType !='E');
return amountType;
}
public static double readValidateAmount()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a dollar amount: ");
amount = keyboard.nextDouble();
if(amount <=0)
{
do
{
System.out.println("Invalid amount!");
System.out.println("Please enter a dollar amount: ");
amount = keyboard.nextDouble();
}
while(amount <=0);
return amount;
}
else
{
return amount;
}
主要:
public static void main (String[] args) throws IOException
{
HenwoodEventClass event = new HenwoodEventClass();
System.out.println("This program will tell you the financial details of"
+ " your event. \nAnd allow you to change or add input.\n\n");
String userFile = "Event.txt";
try
{
File inputFile = new File (userFile);
Scanner CheckFile = new Scanner (inputFile);
if(CheckFile.hasNextLine())
{
while (CheckFile.hasNextLine())
{
try
{
System.out.println(CheckFile.nextLine());
}
catch (IllegalArgumentException exception)
{
System.out.println("Does not exist!");
}
}
CheckFile.close();
event.gettotalTicketSales();
event.gettotalMoneyDonated();
event.gettotalExpenses();
}
System.out.println("Are ther anymore amounts to add that were not in the textfile?: ");
Scanner keyboard = new Scanner(System.in);
char choice = keyboard.next().charAt(0);
choice = Character.toUpperCase(choice);
do
{
if(choice == 'Y')
{
readValidateAmountType();
readValidateAmount();
System.out.println("Are ther anymore amounts to add that were not in the textfile?: ");
choice = keyboard.next().charAt(0);
choice = Character.toUpperCase(choice);
}
event.displayFinalResults();
}
while(choice =='Y');
}
catch (FileNotFoundException exception)
{
System.out.println("File "+ userFile +" does not exist!\n\n");
}
}
}
請張貼'main' – Motes
加入我的主要@Motes – Luke8h