Question

In: Computer Science

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

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();
}

Solutions

Expert Solution

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


Related Solutions

I am creating a crop watering "simulator" in Python. I have the user input an array...
I am creating a crop watering "simulator" in Python. I have the user input an array and then must compare the placement of water and crops to determine if all the crops in the array are watered. The user will either input a "w" for water or "c" for crop when creating the array. A w cell can water 8 cells around it, including itself. My end result must determine if all the crops will be watered or not. How...
Java Programming I need an application that collects the user input numbers into an array and...
Java Programming I need an application that collects the user input numbers into an array and after that calls a method that sums all the elements of this array. and display the array elements and the total to the user. The user decides when to stop inputting the numbers. Thanks for your help!
A person has a firstname, lastname, ID, and email. A phone number is of the form...
A person has a firstname, lastname, ID, and email. A phone number is of the form countrycode, number. A person may have several related telephone numbers, and a telephone number may be associated with multiple people. The possible relationships are: home, work, and mobile. A person may have at most one phone number for each type of relationship. Draw schema diagram and define and create the tables that implement the model and enforce the given constraints.
JAVA Take in a user input. if user input is "Leap Year" your program should run...
JAVA Take in a user input. if user input is "Leap Year" your program should run exercise 1 if user input is "word count" your program should run exercise 2 Both exercises should run in separate methods Exercise 1: write a java method to check whether a year(integer) entered by the user is a leap year or not. Exercise 2: Write a java method to count all words in a string.
Step by step in python Write a program that will keep asking for a user input...
Step by step in python Write a program that will keep asking for a user input (until a blank line is entered) and will inform me whether what I entered was a valid number or not (without crashing). The program should use at least one try/except loop The program should include at least two custom written functions (a main() function can count as one of the two)
I am working on making a simple grade book that will take user input like name...
I am working on making a simple grade book that will take user input like name and grade and then return the name and grade of multiple inputs when the person quits the program. Here is the code that I have been working on. This is in Python 3. I can get one line to work but it gives me an error. Here is what it is supposed to look like: These are just examples billy 100 greg 60 jane...
- Write a function with no input parameter which keeps asking the user to enter positive...
- Write a function with no input parameter which keeps asking the user to enter positive numbers until the user enters an invalid input. (An invalid input is an input which includes at least one alphabet, like 123d4). The program should print the Max and Min of the numbers the user had entered as well as the distance between the Max and Min. (Remember to calculate the absolute distance). The function does not return anything
How would I setup this dictionary for Python 3? class Student(object): def __init__(self, id, firstName, lastName,...
How would I setup this dictionary for Python 3? class Student(object): def __init__(self, id, firstName, lastName, courses = None): The “id”, “firstName” and “lastName” parameters are to be directly assigned to member variables (ie: self.id = id) The “courses” parameter is handled differently. If it is None, assign dict() to self.courses, otherwise assign courses directly to the member variable. Note: The “courses” dictionary contains key/value pairs where the key is a string that is the course number (like “course1”) and...
Build an app to enter a user’s contact information that contains entry fields for firstname, lastname,...
Build an app to enter a user’s contact information that contains entry fields for firstname, lastname, phone number, email, and address. Pick a background color (other than the default) or an image displayed in the app background. Display an image (pick any free image) to display as a banner across the top of the app. Create a button named “Save” that when clicked displays a message “Data has been saved” and clears out the text boxes. Written in C#
Write a short, java program that interacts with the user asking them to buy an xbox...
Write a short, java program that interacts with the user asking them to buy an xbox series x or PS5 and does the following: create at least 2 double variables create at least 1 constant get at least 1 string input from the user get at least 1 int/double input from the user include both, incorporating the input you got from the user: 1 multiway if-else with at least 3 "else if" 1 nested if Your program should combine all...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT