Hello, Please help write a program in JAVA where the user is asked to enter his/
ID: 3830493 • Letter: H
Question
Hello,
Please help write a program in JAVA where the user is asked to enter his/her firstname, lastname, amount of money they want to withdraw separated by spaces. Using string manipulation functions, you need to display a welcome message and the amount they want to withdraw with the correct formatting.
Your display should look something like this:
Hi John Smith! You would like to withdraw $250.00. Thanks!
With the input string being:
John Smith 250
(Notice these are separated by spaces)
SPECIFIC REQUIREMENTS:
Use string manipulation methods (indexOf, substring) as well as parseFloat() and nextLine() methods
GENERAL RESTRICTIONS:
No break statements to exit loops
Here is working program flow:
Enter firstname, lastname amount of money you want to withdraw separated by sp a CeSExplanation / Answer
DisplyWelcomeMsg.java
import java.util.Scanner;
public class DisplyWelcomeMsg {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter firstName, lastName, amount of money you want to withdraw separated by spaces: ");
String line = scan.nextLine();
String name = line.substring(0,line.lastIndexOf(" ")).trim();
float money = Float.parseFloat(line.substring(line.lastIndexOf(" "), line.length()).trim());
System.out.println("Hi "+name+"! You would like to withdraw $"+money+". Thanks!");
}
}
Output:
Enter firstName, lastName, amount of money you want to withdraw separated by spaces:
John Smith 250
Hi John Smith! You would like to withdraw $250.0. Thanks!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.