In: Computer Science
JAVA - I am asking for the user to input their firstName and lastName but I want the method myMethod() to be able to print it when it is called. Is that possible? I'm new to Java and i'm not too sure what I should do to fix this. Also if I were to create a IF statement would I have to declare int amountDeposited; , int accountBalance; , 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 your
account information? Yes or No?");
String outputInfo = input.nextLine();
if (outputInfo.equals("yes")){
System.out.println("Name: " + firstName + " " +
lastName + " \n Account TYpe: " + accountType + " \n Account
Number: " +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 current
date
//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();
}
import java.util.Scanner;
import java.util.Arrays;
import java.time.LocalDate;
public class UserData {
static String firstName,lastName,accountType;
static int accountNumber;
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 your account information? Yes or No?");
String outputInfo = input.nextLine();
if (outputInfo.equals("yes")) {
System.out.println("Name: " + firstName + " " + lastName + " \n Account TYpe: " + accountType
+ " \n Account Number: " + 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 : ");
accountNumber = input.nextInt();
LocalDate myObj = LocalDate.now(); // Create a date object
System.out.println("Date: " + myObj); // Display the current date
//makes sure the next line isnt skipped
input.nextLine();
//Asking user for first and last name
System.out.println("Enter your first name: ");
firstName = input.nextLine();
System.out.println("Enter your last name: ");
lastName = input.nextLine();
// Asking for account number, account type, todays date
System.out.println("Enter your account type savings or checking : ");
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.equalsIgnoreCase("deposit")) {
myMethod();
}
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me