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

***IN JAVA*** Write a program contained a class Student which has firstName, lastName, mark, grade. The...
***IN JAVA*** Write a program contained a class Student which has firstName, lastName, mark, grade. The program should allow creation an array of object instances to assign firstName, lastName and mark from input user and perform and assign grade based on mark’s criteria displayed below. MARKS INTERVAL 95 - 100 90 - <95 85 - <90 80 - <85 75 - <80 70 - <75 65 - <70 60 - <65 0 - <60 LETTER GRADE A+ A B+ B...
I need to draw a cylinder in java with user input, and I can't seem to...
I need to draw a cylinder in java with user input, and I can't seem to get my lines to line up with my ovals correctly from the users input... I know I will have to either add or subtract part of the radius or height but I'm just not getting it right, here is how I'm looking to do it.            g.drawOval(80, 110, radius, height);            g.drawLine(?, ?, ?, ?); g.drawLine(?, ?, ?, ?);   ...
I am creating a program in Python that allows the user to input a credit card...
I am creating a program in Python that allows the user to input a credit card number, and determine if the card is valid. This should be done by taking every other number, starting from the right, and adding them together. The doubling each of the other digits, and adding them together as single digits, and then adding the two sums together. For example, if the number 4833 1200 3412 3456 is used, the first sum should be 6+4+2+4+0+2+3+8=29, the...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input system for a university student, where they put the season and year of when they started their uni course. For example the system will ask "What year did you start your degree?", the user will input "Autumn/2022" as a string. Now from a string format as shown, it should take that user input and calculate for example +2 or +3 years to the date....
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...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
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 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!
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)
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT