Project 16: Questions about profit() method

3 views
Skip to first unread message

Jesse Howell

unread,
Jul 31, 2011, 12:26:06 AM7/31/11
to BYU 142 Summer 2011
First off, is the name important? If I make a getProfit() method,
will I get points taken away?

Second, I'm assuming that the difference between an abstract class
which fulfills the interface requirement from a normal class is the
abstract modifier on the profit() method. If this is giving away too
much info about the assignment, let me know.

Third, is there a way to use

public double profit()
{
NumberFormat dollarFormat = NumberFormat.getCurrencyInstance();
return dollarFormat.format(profit calculation);
}

Within a class and have the formatted double returned and printed
within the driver? Or would one have to

return (profit calculation);

in the profit method and then

NumberFormat dollarFormat = NumberFormat.getCurrencyInstance();
System.out.print("Profit is " +
dollarFormat.format(investment1.profit());

?

Sarah Morley

unread,
Jul 31, 2011, 1:09:13 AM7/31/11
to byu-142-s...@googlegroups.com
The name isn't important. As long as it's clear what its purpose is, it's fine.

Yes, you'd have an abstract modifier on the method as well as a modifier on the class:

public abstract class SomeClass{
}

The format method in the NumberFormat class returns a String, so if you wanted to return a formatted String, profit would need a String return type. I would suggest your second option of returning a double and formatting it in the driver.

Sarah

Jesse Howell

unread,
Jul 31, 2011, 2:31:07 AM7/31/11
to BYU 142 Summer 2011
Thank you. There also seems to be a typo for project 16...

--Stock has members called currentValue and purchasePrice. Profit =
purchasePrice - currentValue (1 pt)

Wouldn't the profit be currentValue - purchasePrice?

Jesse Howell

unread,
Jul 31, 2011, 2:43:26 AM7/31/11
to BYU 142 Summer 2011
And... wow. Apparently as soon as you buy a rental, the cost
automatically becomes your profit.

Profit = purchasePrice - monthlyRent * monthsRented - repairCost. (1
pt)

I'm guessing a "currentValue - " needs to be inserted before
purchasePrice... and then you would ADD (monthlyRent * monthsRented),
not subtract it.

Or you could just add the repair cost instead of subtract, pretend
that you'll never sell it, and then negate the whole thing!

Lorin Henricks

unread,
Jul 31, 2011, 10:18:41 AM7/31/11
to byu-142-s...@googlegroups.com
Rob has already said that the Stock was wrong, and I made the same changes for Rental as well.

What i did for the print statement was i didn't like the 
print(rental.profit())
- so i did
rentalprofit = rental.profit();
print(rentalprofit);

That looked better to me, but i didn't really change anything
Reply all
Reply to author
Forward
0 new messages