Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 CeS

Explanation / 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!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote