Use the following class to respond to questions on the next page.
a.) public class investmentAccount
{
private int numShares;
private int stockValue;
private int accountBalance;
b.) public
investmentAccount(int openingBalance)
{
accountBalance = openingBalance;
numShares = 0;
stockValue = 0;
}
c.) public
void depositFunds(int depositAmount)
{
accountBalance += depositAmount;
}
d.) public
void buyStock(int numberToBuy,
int cost) {
numShares += numberToBuy;
stockValue += (cost * numberToBuy);
accountBalance -= (cost * numberToBuy);
}
e.) public
int getBalance () {
return accountBalance;
}
f.) public int getStockValue()
{
return stockValue;
}
g.) public void sellStock
(int numberToSell, int stockPrice) {
if
((stockValue) >= (numberToSell
* stockPrice)) {
stockValue
-= (numberToSell*stockPrice);
accountBalance
+= (numberToSell * stockPrice);
}else{
System.out.println
(“You do not own enough stock.”);
}//end if
}//end sellStock
}//end investmentAccount
Refer to the
class above to answer the following.
public
_________ withdrawFunds(________________) {
}
public
void addNumbers(int firstNumber) {
int secondNumber = 3.
System.out.println(firstNumber + secondNumber);
}
(Hint:
getPayDue will have a return type and a parameter.)
public
class payroll
{
//fields
//constructor
//methods
}
Answer Key
public void withdrawFunds (int amount) {
accountBalance -= amount;
System.out.println(“New Balance: “ + accountBalance + “.”);
}
public class payroll
{
//fields
String employeeName;
int salaryAmount;
//constructor
public payroll(String name, int salary) {
employeeName = name;
salaryAmount = salary;
}
//methods
public int getPayDue(int hours) {
int pay;
pay = hours * salaryAmount;
return
pay;
}
}