Java Reference
In-Depth Information
static final int
NUMBER OF DAYS=1 0 ;
static final double
BASE PRICE = 10;
static final double
VARIATION = 5 ;
static final double
INITIAL CASH=100;
static double
cash = INITIAL CASH ;
static int
appleInventory = 0;
static int
pearInventory = 0;
static double
applePrice , pearPrice ;
public static void
main(String [] args)
{
for
(
int
day = 1; day
<
= NUMBER OF DAYS ; d a y++)
{
applePrice = computePrice(BASEPRICE , VARIATION) ;
pearPrice = computePrice(BASE PRICE , VARIATION) ;
System. out . println (
"Day: "
+day+
" out of 10"
);
int
choice ;
do
printMenu() ;
choice = getChoice() ;
switch
(choice)
{
case
1:
// Print cash balance and inventory
System. out . println (
"Cash: "
+ currencyFormatter(cash)) ;
System. out . println (
"Apple inventory: "
+ appleInventory) ;
System. out . println (
"Pear inventory: "
+ pearInventory) ;
break
;
case
2:
//Print today ' s prices
System. out . println (
"Price of apples is: "
+
currencyFormatter(applePrice)) ;
System. out . println (
"Price of pears is: "
+ currencyFormatter
(pearPrice)) ;
break
;
case
3:
{ //Buy apples
int
amount = getQuantity(
"apples"
,
"buy"
);
if
(! buyApples(amount) )
{
System. out . println (
"You don't have enough money"
);
break
;
case
4:
// Sell apples
int
amount = getQuantity(
"apples"
,
"sell"
);
if
(! sellApples(amount))
{
{
System. out . println (
"You don't have enough apples"
);
break
;
case
5:
{ // Buy Pears
int
amount = getQuantity(
"pears"
,
"buy"
);
if
(! buyPears(amount) )
{
System. out . println (
"You don't have enough money"
);
break
;
case
6:
{ // Se l l Pears
int
amount = getQuantity(
"pears"
,
"sell"
);