0
can anyone help me to solve this? how do i print out this result?
Enter Employeeâs Name: Sorry, the name cannot be empty. Enter Employeeâs Name: Jacky Enter Employeeâs Salary ($): A Sorry, salary is invalid. Enter Employeeâs Salary ($): 2,509.40 Continue (Y/N)? Y Enter Employee's Name:
2 Answers
+ 1
thanks~ i will try
0
I would use a couple methods. a getName() method and a salary() method
I would loop until my condition is met inside of my methods..
public String getName(){
String newname="";
while(newname==""){
System.out.println("Enter Your Name-");
Scanner in = new Scanner();
newname=in.nextLine(System.in);
}
return newname;
Just an example.. I didn't test this I just wanted to give you an idea of how I might loop it. you can work out the specifics.
I would do similar for a getSalary() method.
then I would wrap it all in another loop.
boolean run=true;
while(run){
getName();
getSalary();
Scanner s = new Scanner();
System.out.println("Continue Y/N");
String again=s.nextLine(System.in);
if(again=="N"){
run=false;
}
}
Again, the specifics of the code are up to you, This is just an example of how I would layout some loops if I wanted to repeat some code.