Home Java Java-tips Oop Q-hammurabi Fill-in: Hammurabi I

Ask Questions?

View Latest Questions

Advertisement


 
 

Fill-in: Hammurabi I
Posted on: July 26, 2006 at 12:00 AM
Fill in the blanks in these programs.

Java Notes

Fill-in: Hammurabi I

Name ______________________________

Fill in the blanks in these programs. Each blank represents ONE keyword, variable, operator, etc.

The Hammurabi class

  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
import javax.swing.*;

public _____________ Hammurabi {

    //============================================================= main
    public _____________ void main(String[] args) {
        Kingdom akkad = new _____________();
        
        _____________ (akkad.getYear() <= 5) {
            JOptionPane._____________(null, akkad.toString());

            int food = 0;

            String plantStr = JOptionPane.showInputDialog(null,
                    "Exalted Ruler, how much of the remaining "
                    + (_____________.getGrain()-food) + " bushels should be planted?");
            int seeds = Integer._____________(plantStr);
            
            akkad._____________(food, seeds);
        }
        
        JOptionPane.showMessageDialog(null, "At end " + akkad._____________());
    }
}

The Kingdom class

  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 
 26 
 27 
 28 
 29 
 30 
 31 
 32 
 33 
 34 
 35 
 36 
 37 
 38 
 39 
class Kingdom {
    private _____________ static int SEED_REQUIRED_PER_ACRE = 2;

    //================================================= instance variables
    _____________ int myGrain = 4000;
    private int myYear  = 0;
    private int _____________ = 0;

    //=========================================================== getGrain
    public int getGrain() {
        return _____________;
    }

    //============================================================ getYear
    public _____________ getYear() {
        return myYear;
    }

    //=========================================================== toString
    public _____________ toString() {
        _____________ "Kingdom status at year " + myYear
               + ", last harvest = " + myHarvest
               + ", total grain = " + myGrain;
    }

    //==================================================== simulateOneYear
    public _____________ simulateOneYear(int _____________, int _____________) {
    
        myGrain = myGrain - food - seed;
        
        int acresPlanted _____________ seed / SEED_REQUIRED_PER_ACRE;
        
        int yieldPerAcre = 2 + (int)(5 * _____________.random());
        myHarvest        = yieldPerAcre * acresPlanted;
        myGrain += myHarvest; 

        myYear_____________;              // Another year has passed.
    _____________
}
Advertisement


DMCA.com