私はEclipse IDEを使ってjavaをプログラミングしています。 名前がCuncurrentHashMapにあるかどうかを示すためのクラスを作成しましたが、私のIDEは私にエラーを表示しませんでしたが、私のプログラムを実行するときは、私の希望する出力は、クエリ名 "Jerry"を大文字にすることです。私はJavaでの先進的な原則を学んでいるだけです。私は基本的なコンセプトに精通していますが、私はあなたが私のコーディングスタイルに対して持っている訂正や批判を受け付けています。Stringパラメータに対してtoUpperCase()メソッドを使用できないのはなぜですか?
package learnJavaPackages;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;
public class AddEmployee {
private String newEmployeeName;
private int empID=0;
ConcurrentHashMap<String, String> hashHandler = new ConcurrentHashMap<String, String>();
Scanner inputHere = new Scanner(System.in);
public void AddNewEmployee(){
System.out.print("Enter a new employee here: ");
newEmployeeName = inputHere.nextLine();
empID++;
String empIDstring = Integer.toString(empID);
newEmployeeName = newEmployeeName+empIDstring;
hashHandler.put(newEmployeeName, empIDstring);
}
public void showAddStatus(){
System.out.println(newEmployeeName +", has been added to the company");
}
public void showIsEmployeeIn(String isEmployee) {
isEmployee.toUpperCase();
if(hashHandler.containsKey(isEmployee)){
System.out.println(isEmployee +" is in the Company.");
}
else{
System.out.println(isEmployee +" is not in the company");
}
}
}
主な方法:出力
AddEmployee addEmpRef = new AddEmployee();
addEmpRef.AddNewEmployee();
addEmpRef.showAddStatus();
addEmpRef.showIsEmployeeIn("Jerry");
:
Enter a new employee here: Isaac
Isaac1, has been added to the company
Jerry is not in the company
こんにちは@Thilo。この質問をお読みいただきありがとうございます。正直な誠実さで、私は似たような(重複した)質問を見つけることができませんでした。たぶん私はまだ物事がここで働く方法に新しい、私を許している。 –
複製物へのリンクは、このページの上部の黄色いボックスの右側にある「リンクされた」セクションに含まれています。 – Thilo