27.7k views
0 votes
Objects of the BankAccount class require a name (string) and a social security number (string) be specified (in that order)upon creation. Declare two strings corresponding to a name and a social security number and read values into them from standard input (in that order). Use these values to define an object of type BankAccount named newAccount.

User Rudker
by
3.6k points

1 Answer

7 votes

Answer:

import java.util.Scanner;

class BankAccountTest {

public static void main(String[] args) {

String name;

String ssn;

Scanner in = new Scanner(System.in);

// Receive User input

System.out.println("Enter Your Name");

name = in.nextLine();

System.out.println("Enter Your Social Security Number");

ssn = in.nextLine();

//Creating an object class BankAccount

BankAccount newAccount = new BankAccount(name,ssn);

}

}

Step-by-step explanation:

Using Java Programming Language

Use Scanner class to read values for name and social security numbers and store in the respective varibles

Make an object of the class BankAccount and supply to values to constructor call

Assume that the class BankAccount exists with the member feilds for name and ssn as below:

public class BankAccount{

//Class member variables

private String name;

private String ssn;

//Constructor

public BankAccount(String name, String ssn) {

this.name = name;

this.ssn = ssn;

}

}

User Thorben Janssen
by
4.7k points