このコードでは、メイン以外の3つの異なるタイプのメソッドを使用する必要があります。私が問題を抱えているのは、9行目です。ここでは、1つの引数を持ち、voidを返すメソッドを作成する必要があります。別のファイルでは、メソッドの本体でヘッダー(String [] greetings)の括弧の内容を持つことで機能するようになりましたが、それは引数が必要な条件を満たしませんでした。この特定のメソッドを1つの引数でコンパイルし、JAVAでvoidを返すにはどうすればよいですか?
カスタムメソッドの目的は、実行時に私に4つのカスタムメッセージの1つを与える非常に単純な配列を作ることです。私はそれがアレイの最も実用的な使用ではないことを理解しますが、私は割り当てのためにそれを利用する必要があります。
できるだけ近くにカスタム配列の中に配列が必要なので、どうすれば正しい方法でコンパイルできますか?
私はコード全体が現在の状態で正しくコンパイルされないことを知っています。他の修正方法はわかります。私は本当にフォーマットエラーのために事前にお詫び申し上げます、これは私の最初の質問はこのウェブサイト上です。私は家庭教師でこれについて何時間も働いていましたが、時間がなくなりました。
import java.util.Scanner;
import java.util.Random;
import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class firstDraftFinal {
public static void simpleArray(String[] greetings) {
"Welcome To CWU BANK!", "Thank you for using CWU ATM!", "Please insert DEBIT card", "We value your business!"
};
int i = (int)(Math.random() * greetings.length);
System.out.println(greetings[i]);
}
static void printStartupMessage() {
System.out.println("Card accepted");
System.out.println("Enter PIN #: ****");
System.out.println("verifying...");
System.out.println("PIN acccepted");
}
public static double getRandomBalance() {
Random randomNumbers = new Random();
double randomBalance = 20.0 + (10000.0 - 20.0) * randomNumbers.nextDouble();
randomBalance = Math.round(randomBalance * 100);
randomBalance = randomBalance/100;
return randomBalance;
}
public static void main(String[] args) throws IOException {
String[] greetings = {"Welcome To CWU BANK!", "Thank you for using CWU ATM!", "Please insert DEBIT card", "We value your business!"};
double amountToWithdrawl;
double saveRandomBalance;
double remainingBalance;
printStartupMessage();
Scanner keyboard = new Scanner(System.in);
Scanner keyboardDouble = new Scanner(System.in);
saveRandomBalance = getRandomBalance();
System.out.println("CHECKING BALANCE**** $" + saveRandomBalance);
System.out.println("Would you like to withdrawl from CHECKING****? Y/N");
String proceedWithWithdrawl = keyboard.nextLine();
while (!proceedWithWithdrawl.equalsIgnoreCase("y") && !proceedWithWithdrawl.equalsIgnoreCase("n")
&& !proceedWithWithdrawl.equalsIgnoreCase("yes") && !proceedWithWithdrawl.equalsIgnoreCase("no"))
{
System.out.println("Invalid response. Enter [Y] or [N].");
proceedWithWithdrawl = keyboard.next();
}
switch(proceedWithWithdrawl)
{
case "N":
System.out.println("Returning card... please wait...");
System.out.println("Card returned. Thank you for using CWU Bank!");
break;
case "n":
System.out.println("Returning card... please wait...");
System.out.println("Card returned. Thank you for using CWU Bank!");
break;
case "NO":
System.out.println("Returning card... please wait...");
System.out.println("Card returned. Thank you for using CWU Bank!");
break;
case "no":
System.out.println("Returning card... please wait...");
System.out.println("Card returned. Thank you for using CWU Bank!");
break;
case "No":
System.out.println("Returning card... please wait...");
System.out.println("Card returned. Thank you for using CWU Bank!");
break;
case "Y":
System.out.println("Enter amount to withdrawl: ");
amountToWithdrawl = keyboardDouble.nextDouble();
remainingBalance = saveRandomBalance - amountToWithdrawl;
remainingBalance = Math.round(remainingBalance * 100);
remainingBalance = remainingBalance/100;
if (amountToWithdrawl % 20 == 0 && amountToWithdrawl <= saveRandomBalance)
{
System.out.println("Dispensing...");
System.out.println("ACCOUNT BALANCE: $" + remainingBalance);
System.out.println("$" + amountToWithdrawl + " has been withdrawn from CHECKING****");
System.out.println("Returning card... please wait...");
System.out.println("Card returned. Thank you for using CWU Bank!");
CallDollarBill.dollarBill();
break;
}
else if (amountToWithdrawl > saveRandomBalance)
{
System.out.println("Insufficient Balance.");
break;
}
}
}
}
どのようなヘルプや例も高く評価されています。
CWU銀行へ!」、「CWU ATMをご利用いただきありがとうございます!私の本を見て、4つの異なる出力としてString stを受け入れる方法を見つけようとしていますか? – Rkripp
全体の文章(文字列)ですか、それとも配列ですか? :)あなたは眉を歓迎する、私はいつもあまりにも間違いをするhaha –
( ")タグjavaの後にコンマを使用すると、あなたは新しい変数を開始すると思う。あなたはこれをString []にすることができる... –