Hello. I was just wondering how I got two out of four on the assignment? Does the scribe get two usually? Why did I get only 13 out of 14? Had no lab Partner and this didnt show up in my grades so im re-submitting it
andyly25@yahoo.com jason900412@gmail.com johanhestenes@gmail.com nicholasbettencourt@yahoo.com Ryandpg@gmail.com tulan94@gmail.com velasquezariel92@gmail.com
Counter tally = new Counter(); tally.count(); tally.count(); int result = tally.getValue(); // Sets result to 2
public class Counter
{
private int value;
...
}
public void count()
{
value = value + 1;
}
public int getValue()
{
return value;
}
Consider the Counter class, that Coder Carla refines over time. Suppose Programmer Paul's code uses that class, and in his code, the statement
System.out.println(someCounter.getValue())
prints a negative number. Which of the following statements applies?
Behavior of bank account (abstraction):
Methods of BankAccount class:
We want to support method calls such as the following:
harrysChecking.deposit(2000); harrysChecking.withdraw(500); System.out.println(harrysChecking.getBalance());
public void deposit(double amount) { implementation - filled in later }
Examples:
public BankAccount()
{
// body--filled in later }
The public constructors and methods of a class form the public interface of the class:
public class BankAccount { // private variables--filled in later // Constructors public BankAccount() { // body--filled in later } public BankAccount(double initialBalance) { // body--filled in later } // Methods public void deposit(double amount) { // body--filled in later } public void withdraw(double amount) { // body--filled in later } public double getBalance() { // body--filled in later } }
What does the following code print?
BankAccount harrysChecking = new BankAccount(10000); harrysChecking.withdraw(harrysChecking.getBalance()); harrysChecking.deposit(harrysChecking.getBalance()); System.out.println(harrysChecking.getBalance());
Suppose you want a more powerful bank account abstraction that keeps track of an account number in addition to the balance. The following are proposed to accommodate this enhancement?
getAccountNumber
methodgetBalance
methodWhich should be adopted?
/** Withdraws money from the bank account. @param amount the amount to withdraw */ public void withdraw(double amount) { //implementation filled in later } /** Gets the current balance of the bank account. @return the current balance */ public double getBalance() { //implementation filled in later }
/** A bank account has a balance that can be changed by deposits and withdrawals. */ public class BankAccount { . . . }
Provide documentation comments for the Counter class of Section 3.1.
/** This class models a tally counter. */ public class Counter { private int value; /** Gets the current value of this counter. @return the current value */ public int getValue() { return value; } /** Advances the value of this counter by 1. */ public void count() { value = value + 1; } }
Why is the following documentation comment questionable?
/** Each account has an account number. @return the account number of this account */ public int getAccountNumber()