Write a program that executes the following steps: Create a new bank account. Sh
ID: 3869219 • Letter: W
Question
Write a program that executes the following steps:
Create a new bank account.
Show the balance of the bank account.
If the balance of the bank account is >= 20 dollars, do the following steps:
Print "Purchasing movie ticket." including the full stop at the end of the sentence.
Withdraw $20 from the account.
Show the balance of the bank account again.
Otherwise, print "You need more money to buy a movie ticket." including the full stop at the end of the sentence.
The following sample I/O shows how your program should behave when the account has at least $20:
Otherwise, your program should behave as follows:
public class Exercise6 {
public static void main(String[] args) {
// INSERT YOUR CODE HERE
}
}
Explanation / Answer
class Person { public Person() { name = "YetToBeNamed"; birthdayYear = 1999; // my default } public Person(String givenName, int yearOfBirth) { name = givenName; birthdayYear = yearOfBirth; } public String getName() { return name; } public String changeName(String name) { String aux; aux = this.name; this.name = name; return aux; } public int getAgeInYears(int currentYear) { return currentYear - birthdayYear; } private String name; private int birthdayYear; public static void main(String[] args) { Person a = new Person(); Person b = new Person("Richard P. Feynman", 1918); String name = a.changeName("The Next Richard Feynman"); System.out.println( "Physicist " + name + " makes big " + "discovery, touted as " + a.getName() ); System.out.println( b.getName() + " was " + b.getAgeInYears(1945) + " in 1945, in May. " ); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.