Skip to content

Instantly share code, notes, and snippets.

@isauravmanitripathi
Created March 26, 2019 19:06
Show Gist options
  • Save isauravmanitripathi/fab936cd2d3d0276c6050f1cf9c173c8 to your computer and use it in GitHub Desktop.
Save isauravmanitripathi/fab936cd2d3d0276c6050f1cf9c173c8 to your computer and use it in GitHub Desktop.
// AccountTest.java
// creating and manipulate an Account object.
import java.util.Scanner;
public class AccountTest {
public static void main(String[] args) {
// create a Scanner object to obtain input from the command window
Scanner input = new Scanner(System.in);
// create an Account object and assign it to myAccount
Account myAccount = new Account();
// display initial value of name (null)
System.out.printf("Initial name is: %s%n%n ", myAccount.getName());
// prompt for and read name
System.out.println("Please enter your name: ");
String theName = input.nextLine(); // read a line of text
myAccount.setName(theName); // put theName in myAccount
System.out.println(); // outputs a blank line
// display the name stored in object myAccount
System.out.printf("Name in object myAccount is: %n%s%n ", myAccount.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment