JAVA - I am asking for the user to input their firstName and lastName but I...

60.1K

Verified Solution

Question

Programming

JAVA - I am asking for the user to input their firstName andlastName but I want the method myMethod() to be able to print itwhen it is called. Is that possible? I'm new to Java and i'm nottoo sure what I should do to fix this. Also if I were to create aIF statement would I have to declare int amountDeposited; , intaccountBalance; , int newBalance; in the new if statement.


import java.util.Scanner;
import java.util.Arrays;
import java.time.LocalDate;

public class UserData {
   static void myMethod(){
   Scanner input = new Scanner(System.in);
   System.out.println(\"Amount you want to deposit :\");
   int amountDeposited = input.nextInt();
   int accountBalance = 0;
   int newBalance = accountBalance +amountDeposited;
   input.nextLine();
   System.out.println(\"DO you wish you print out youraccount information? Yes or No?\");
   String outputInfo = input.nextLine();
   if (outputInfo.equals(\"yes\")){
   System.out.println(\"Name: \" + firstName + \" \" +lastName + \" \n Account TYpe: \" + accountType + \" \n AccountNumber: \" +accountNumber + \" \n Balance : \" + newBalance);
}
   if(outputInfo.equals(\"no\")){
   System.out.println(\"Ok! Have a nice day!Goodbye!\");
}

   }
   public static void main(String[] args){

Scanner input = new Scanner(System.in);


System.out.println(\"Bank Menu\");
System.out.println(\"Enter your account number : \");
int accountNumber = input.nextInt();

LocalDate myObj = LocalDate.now(); // Create a date object
System.out.println(\"Date: \" + myObj); // Display the currentdate

//makes sure the next line isnt skipped
input.nextLine();

//Asking user for first and last name
System.out.println(\"Enter your first name: \");
String firstName = input.nextLine();

System.out.println(\"Enter your last name: \");
String lastName = input.nextLine();

// Asking for account number, account type, todays date
System.out.println(\"Enter your account type savings or checking :\");
String accountType = input.nextLine();



//Type of transaction
System.out.println(\"What type of transaction: Deposit , Withdraw,Cash Check, Account Balance : \");
String transactionType = input.nextLine();
//Deposit
if (transactionType.equals(\"deposit\") ||
transactionType.equals(\"Deposit\")){
int amountDeposited;
int accountBalance;
int newBalance;
myMethod();
}

Answer & Explanation Solved by verified expert
4.2 Ratings (856 Votes)
import javautilScanner import javautilArrays import javatimeLocalDate public class UserData static String firstNamelastNameaccountType static int accountNumber static void myMethod Scanner input new ScannerSystemin SystemoutprintlnAmount you want to deposit int amountDeposited inputnextInt int accountBalance 0 int newBalance    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students