Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.
SavingsAccount
class
.
SavingsAccount objects?
SavingsAccount objects most likely have?
String
objects mutable or immutable?
String university;
university = "jmu";
university.toUpperCase();
System.out.println(university);
SavingsAccount objects mutable or immutable?
SavingsAccount
class?
SavingsAccount?
double and int primitive types or
reference types?
String a primitive type or a reference type?
SavingsAccount a primitive type or a reference type?
Be careful! When a question begins with "What is printed by" you are starting a fragment from scratch. When a question begins with "Add the following" you are continuing an existing fragment.
String university;
university = "jmu";
System.out.println(university == "jmu");
String university;
university = "jmu";
university = university.toUpperCase();
System.out.println(university);
String university;
university = "jmu";
System.out.println(university.toUpperCase() == "JMU");
SavingsAccount wilma;
wilma = new SavingsAccount("WF");
System.out.printf("%2s\n", wilma.getID());
System.out.printf("%2s\n", wilma.getID() == "WF");
What is printed by the additional statements?
System.out.printf("%2s\n", wilma.getID().equals("WF"));
What is printed by the additional statements?
SavingsAccount wilma;
wilma = new SavingsAccount("WF");
wilma.deposit(100.00);
System.out.printf("%2s % 8.2f\n", wilma.getID(), wilma.getBalance());
wilma.deposit(200.00);
wilma.withdraw(50.00);
System.out.printf("%2s % 8.2f\n", wilma.getID(), wilma.getBalance());
What is printed by the additional statements?
wilma = new SavingsAccount("BR");
wilma.deposit(50.00);
System.out.printf("%2s % 8.2f\n", wilma.getID(), wilma.getBalance());
What is printed by the additional statements?
wilma
object changed?
SavingsAccount object with the ID of "WF".
How would you do it, or would it be impossible?
SavingsAccount wilma;
SavingsAccount oldWilma;
wilma = new SavingsAccount("WF");
wilma.deposit(100.00);
System.out.printf("wilma: %2s % 8.2f\n", wilma.getID(), wilma.getBalance());
oldWilma = wilma;
System.out.printf("oldWilma: %2s % 8.2f\n", oldWilma.getID(), oldWilma.getBalance());
What is printed by the additional statements?
wilma.deposit(100);
System.out.printf("wilma: %2s % 8.2f\n", wilma.getID(), wilma.getBalance());
What is printed by the additional statements?
System.out.printf("oldWilma: %2s % 8.2f\n", oldWilma.getID(), oldWilma.getBalance());
What is printed by the additional statements?
oldWilma.deposit(100);
System.out.printf("wilma: %2s % 8.2f\n", wilma.getID(), wilma.getBalance());
System.out.printf("oldWilma: %2s % 8.2f\n", oldWilma.getID(), oldWilma.getBalance());
What is printed by the additional statements?
SavingsAccount wilma;
SavingsAccount oldWilma;
wilma = new SavingsAccount("WF");
wilma.deposit(100.00);
oldWilma = wilma;
System.out.printf("wilma: %2s % 8.2f\n", wilma.getID(), wilma.getBalance());
System.out.printf("oldWilma: %2s % 8.2f\n", oldWilma.getID(), oldWilma.getBalance());
wilma = new SavingsAccount("BR");
wilma.deposit(500.00);
System.out.printf("wilma: %2s % 8.2f\n", wilma.getID(), wilma.getBalance());
System.out.printf("oldWilma: %2s % 8.2f\n", oldWilma.getID(), oldWilma.getBalance());
What is printed by the additional statements?
oldWilma.withdraw(100.00);
System.out.printf("wilma: %2s % 8.2f\n", wilma.getID(), wilma.getBalance());
System.out.printf("oldWilma: %2s % 8.2f\n", oldWilma.getID(), oldWilma.getBalance());
What is printed by the additional statements?
wilma = oldWilma;
System.out.printf("wilma: %2s % 8.2f\n", wilma.getID(), wilma.getBalance());
System.out.printf("oldWilma: %2s % 8.2f\n", oldWilma.getID(), oldWilma.getBalance());
What is printed by the additional statements?
SavingsAccount object with the ID of "BR".
How would you do it, or would it be impossible?
wilma = null;
System.out.printf("wilma: %2s % 8.2f\n", wilma.getID(), wilma.getBalance());
What will happen when you execute the application?
final. Some questions in this
part of the lab use the following Range class (which
has public attributes for convenience, not because it
is good practice).
public class Range
{
public int max, min;
}
final String theBestUniversity;
theBestUniversity = "JMU";
theBestUniversity = "UVA";
Range) won't compile (if any)?
Range cool = new Range();
final Range warm = new Range();
Range) won't compile (if any)?
Range cool = new Range();
final Range warm = new Range();
cool = new Range();
warm = new Range();
Range) won't compile (if any)?
Range cool = new Range();
final Range warm = new Range();
cool.min = 41;
cool.max = 55;
warm.min = 56;
warm.max = 65;
SavingsAccount) won't compile (if any)?
final SavingsAccount betty = new SavingsAccount("BR");
betty.deposit(100.00);
Be careful! When a question begins with "What is printed by" you are starting a fragment from scratch. When a question begins with "Add the following" you are continuing an existing fragment.
public class Driver
{
public static void main(String[] args)
{
SavingsAccount wilma;
wilma = new SavingsAccount("WF");
wilma.deposit(100.00);
System.out.printf("Before process(): %2s % 8.2f\n",
wilma.getID(), wilma.getBalance());
process(wilma);
System.out.printf("After process(): %2s % 8.2f\n",
wilma.getID(), wilma.getBalance());
}
public static void process(SavingsAccount account)
{
System.out.printf("In process(): %2s % 8.2f\n",
account.getID(), account.getBalance());
}
}
process() method (i.e., before the call to
printf() in the process() method).
account.deposit(50.00);
What is printed now?
wilma still refers to the
same object and a copy of the reference, not the original
reference, was passed).
process() method
to the following. (In other words, delete the existing body
and replace it with the following.)
account = new SavingsAccount("BR");
account.deposit(200);
System.out.printf("In process(): %2s % 8.2f\n",
account.getID(), account.getBalance());
What is printed now?
SavingsAccount class is in the banking
package.
Copyright 2024