Question
Asked by:
devweez
devweez from SM Senior
Rating : No Rating
Questions Asked: 5
Questions Answered: 0
 

$10.00 Java Questions Need Response

Q:
1. (Refer to class diagram 6-1.) Declare the Account class and its instance variables. Then, code a constructor that assigns default values to these variables. The default value you assign to the customer variable should prevent a NullPointerException. Write this code as concisely as possible.









2. (Refer to class diagram 6-1.) Code a constructor for the Account class that assigns values to the instance variables based on the values that are passed to it. The parameters of this constructor should be given the same names as the instance variables.





3. (Refer to class diagram 6-1.) Code a constructor for the Account class that assigns values to the instance variables based on the values that are passed to it. The parameters of this constructor should be given the names n, c, t, and b respectively. Write this code as concisely as possible.









4. (Refer to class diagram 6-1.) Code a constructor for the Account class that assigns values to the number, type, and balance instance variables based on the values that are passed to it, and assigns a value to the customer instance variable by calling the getCustomer method. The parameters of this constructor should be given the same names as the instance variables. The getCustomer method should accept the number variable as a parameter and return a Customer object. Write this code as concisely as possible.





5. (Refer to class diagram 6-1.) Write the code for the getType method. This method should simply return the value of the type instance variable.





6. (Refer to class diagram 6-1.) Write the code for the setType method. This method should simply set the value of the type instance variable to the value that’s passed to it.





7. (Refer to class diagram 6-1.) Write the code for the getCustomerName method. This method should get a customer’s name from the customer instance variable by calling a method of the Customer class named getName that returns the name instance variable of the Customer object. Write this method as concisely as possible.





8. (Refer to class diagram 6-1.) Write the code for the getFormattedBalance method. This method should return the value of the balance instance variable formatted as currency with two decimal places.





9. (Refer to class diagram 6-1.) Write the code for the creditAccount and debitAccount methods. The creditAccount method should add the amount that’s passed to it to the balance instance variable, and the debitAccount method should subtract the amount that’s passed to it from the balance instance variable.





10. (Refer to class diagram 6-1.) Assume that the Account class includes an additional instance variable named lastTranDate. Write two methods that overload the creditAccount and debitAccount methods that accept and update this instance variable. (Hint: You can use a variable created from the Date class to store a date.)





11. (Refer to class diagram 6-1.) Given a constructor that accepts values for the number, type, and balance instance variables and assigns those values to the instance variables, code another constructor that calls this constructor and passes default values to it.





12. (Refer to class diagram 6-1.) Code a statement that creates an instance of the Account class using the constructor that doesn’t accept any parameters. Store the object that’s created in a variable named account.

 



This question has attachments:
class diagram 6-1.gif (8K)
 
Available Solutions to this Question
Posted by:
modulo51
modulo51 from University of California, Berkeley
Rating (22): A+
Questions Asked: 0
Questions Answered: 176, earned $309.37
 

$10.00 Account.java w/ comments & UseNotes file...

  • This solution hasn't been purchased yet.
  • Posted on Jul 13, 2008 at 9:49:28PM
A:
Preview: ... ######0.00");
return df.format(this.balance);

}
// 9) add to account:
public void creditAccount(double amount) {
this.balance += amount;

}
// 9) subtract from account:
public void debitAccount(double amount) {
this.balance -= amount;

}
// 10) overload debit & credit methods for transaction date:
public void creditAccount(double amount, Date date) {
this.creditAccount(amount);
this.lastTransDate = date;
}

public void debitAccount(double amount, Date date) {
//
this.debitAccount(amount);
this.lastTransDate = date;
}
// 11) this constructor passes default values to the
// construc ...

The full solution is about 809 words long.

Attachments:
Account.java (3K) (Preview Available)
UseNotes.txt (1K) (Preview Available)
Posted by:
b_h
b_h from U. in B.
Rating (347): A+
Questions Asked: 0
Questions Answered: 695, earned $11,835.01
 

$10.00 Java Account Questions

  • This solution hasn't been purchased yet.
  • Posted on Jul 13, 2008 at 10:06:33PM
A:
Preview: ... = 0;
customer = new Customer();
type = "";
balance = 0.0;
}
}
</pre>


2. (Refer to class diagram 6-1.) Code a constructor for the Account class that assigns values to the instance variables based on the values that are passed to it. The parameters of this constructor should be given the same names as the instance variables.


<pre>
// constructor that assigns values to the instance variables that are passed in
public Account(int number, Customer customer, String type, double balance) {
this.number = number;
this.customer = customer;
this.type = type;
this.balance = balance;
}
</pre>


3. (Refer to class diagram 6-1.) Code a constructor for the Account class that assigns values to the instance variables based on the values that are passed to it. The parameters of this constructor should be given the names n, c, t, and b respectively. Write this code as concisely as possible.


<pre>
// constructor that assigns values to the instance variables that are passed in
public Account(int n, Customer c, String t, double b) {
number = n;
c ...

The full solution is about 711 words long.
   
Join Now or Log In
Get Answers
Get Paid