Your task is to develop classes to model a world involving Citizens and Traders, where Citizens...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Your task is to develop classes to model a world involving Citizens and Traders, where Citizens are able to exchange gems for Goods including bread, wool, armour, weapons, and building materials. All of those goods are provided by Traders in exchange for gems. Every Trader supports one or more Trades, where a Trade includes the following information: - The price in gems The specific goods that are for sale How much of that goods is available for the price The following is an example of a Trade: - Trade 1 gem for 3 Bread Every Citizen has an amount of gems along with an amount of Goods of each type (which may be zero). When a Citizen successfully executes a Trade, the following happens: -The relevant amount of gems is removed - The relevant amount of Goods is added For example, if a Citizen initially has 5 gems and an empty inventory, after executing the above trade, they would have 4 gems and 3 Bread in their inventory. If a Citizen does not have enough gems to complete a trade, they cannot execute it. Trades are provided by Traders. When a new Trader is created, they only have one Trade available. Each time a Trader makes a trade with a Citizen, a new (randomly-chosen) Trade is added to their set. So if a Trader starts with the sample Trade above, after three successful trades with Citizens, the Trader might have the following Trades in their list: - Trade 1 gem for 3 Bread Trade 2 gems for 1 Helmet Trade 1 gem for 1 Bread Trade 2 gems for 4 Wool (Note that this trader has two Trades for the same item of Goods - Bread. This is not a problem in the system-you do not need to check for duplicates.) Java Task 1: Goods (3 marks) Note about implementation: all classes created in this exam should be put in the trading package. You must create an enumerated type Goods with the following values: BREAD, COAL, FISH, HELMET, IRON, PAPER, SHIELD, SWORD, WOOD, WOOL Java Task 2: Trade (7 marks) You must create a class Trade representing a single trade, including the following properties: • gems: the number of gems involved in the trade (an integer) • amount: the amount of goods involved in the trade (an integer) • goods: the type of goods involved in the trade (an object of type Goods) For example, the trade "1 gem for 3 BREAD" would be represented as: gems: 1 amount: 3 goods: Goods.BREAD The Trade class should have a public constructor that initialises all of the fields, and should also include the following methods: • A complete set of get methods, but no set methods • Appropriate implementations of equals() and hashCode()-note that equality should be based on the values of all three fields. • An implementation of toString() that produces a string representation of the Trade similar to the example above ("1 gem for 3 BREAD"). Not that you can use automatically-generated code for the get methods and equals()/hashCode(), but you will need to write the toString() method by hand to meet the specification. Java Task 3: Citizen (6 marks) Next, create a class Citizen representing a citizen in the game. The internal details of this class are up to you; here is the required behaviour. The constructor for Citizen should take a single parameter, an integer representing the number of gems, and should create a new Citizen with that many gems and an empty inventory. Citizen should have the following public methods: public int getGems()-returns the current amount of gems public int getAmount (Goods goods) - returns the current amount of the indicated Goods type in the inventory. Should return 0 if the Citizen does not have any of the indicate Goods. public boolean executeTrade (Trade trade) - should check whether the given trade is possible (i.e., whether the Citizen has enough gems) o If the amount of gems is not enough, return false and do not change anything Otherwise, update the amount of gems and the inventory based on the details of the Trade and return true o Java Task 4: Trader (4 marks) Create a class Trader representing a trader in the world. As with Citizen, the internal details of this class are up to you; here is the required behaviour. The constructor for Trader should take no parameters, and should create a Trader with a single, randomly-chosen Trade. Trader should have the following public methods: public List<Trade> getTrades () - returns the current list of Trades supported by this Trader public void addRandomTrade() - adds a new, randomly-chosen Trade to the list. The Trade should be generated with the following constraints: o The value for gems should be between 1 and 5 (inclusive) o The value for amount should be between 1 and 5 (inclusive) o The value for Goods should be randomly chosen from the values of the Goods enum To generate a random number, you can use the java.util.Random class, as follows: Creating an object: Random rand = new Random(); Later on in the code, when you need a number: int value = rand.nextInt(n); will return a number between 0 and (n-1), inclusive Task 5: Trade.execute() (4 marks) In your Trade class, implement one additional public method, as follows: public void execute(Trader trader, Citizen citizen) This method should behave as follows: • If the current Trade is not included in the list of trades supported by trader, this method should throw an IllegalArgmentException • Otherwise, it should call citizen.executeTrade() with the current trade o If executeTrade() returns true, the method should also call trader.addRandom Trade() Java submission Ensure your submission files are named appropriately: Goods.java Trade.java Citizen.java Trader.java Your task is to develop classes to model a world involving Citizens and Traders, where Citizens are able to exchange gems for Goods including bread, wool, armour, weapons, and building materials. All of those goods are provided by Traders in exchange for gems. Every Trader supports one or more Trades, where a Trade includes the following information: - The price in gems The specific goods that are for sale How much of that goods is available for the price The following is an example of a Trade: - Trade 1 gem for 3 Bread Every Citizen has an amount of gems along with an amount of Goods of each type (which may be zero). When a Citizen successfully executes a Trade, the following happens: -The relevant amount of gems is removed - The relevant amount of Goods is added For example, if a Citizen initially has 5 gems and an empty inventory, after executing the above trade, they would have 4 gems and 3 Bread in their inventory. If a Citizen does not have enough gems to complete a trade, they cannot execute it. Trades are provided by Traders. When a new Trader is created, they only have one Trade available. Each time a Trader makes a trade with a Citizen, a new (randomly-chosen) Trade is added to their set. So if a Trader starts with the sample Trade above, after three successful trades with Citizens, the Trader might have the following Trades in their list: - Trade 1 gem for 3 Bread Trade 2 gems for 1 Helmet Trade 1 gem for 1 Bread Trade 2 gems for 4 Wool (Note that this trader has two Trades for the same item of Goods - Bread. This is not a problem in the system-you do not need to check for duplicates.) Java Task 1: Goods (3 marks) Note about implementation: all classes created in this exam should be put in the trading package. You must create an enumerated type Goods with the following values: BREAD, COAL, FISH, HELMET, IRON, PAPER, SHIELD, SWORD, WOOD, WOOL Java Task 2: Trade (7 marks) You must create a class Trade representing a single trade, including the following properties: • gems: the number of gems involved in the trade (an integer) • amount: the amount of goods involved in the trade (an integer) • goods: the type of goods involved in the trade (an object of type Goods) For example, the trade "1 gem for 3 BREAD" would be represented as: gems: 1 amount: 3 goods: Goods.BREAD The Trade class should have a public constructor that initialises all of the fields, and should also include the following methods: • A complete set of get methods, but no set methods • Appropriate implementations of equals() and hashCode()-note that equality should be based on the values of all three fields. • An implementation of toString() that produces a string representation of the Trade similar to the example above ("1 gem for 3 BREAD"). Not that you can use automatically-generated code for the get methods and equals()/hashCode(), but you will need to write the toString() method by hand to meet the specification. Java Task 3: Citizen (6 marks) Next, create a class Citizen representing a citizen in the game. The internal details of this class are up to you; here is the required behaviour. The constructor for Citizen should take a single parameter, an integer representing the number of gems, and should create a new Citizen with that many gems and an empty inventory. Citizen should have the following public methods: public int getGems()-returns the current amount of gems public int getAmount (Goods goods) - returns the current amount of the indicated Goods type in the inventory. Should return 0 if the Citizen does not have any of the indicate Goods. public boolean executeTrade (Trade trade) - should check whether the given trade is possible (i.e., whether the Citizen has enough gems) o If the amount of gems is not enough, return false and do not change anything Otherwise, update the amount of gems and the inventory based on the details of the Trade and return true o Java Task 4: Trader (4 marks) Create a class Trader representing a trader in the world. As with Citizen, the internal details of this class are up to you; here is the required behaviour. The constructor for Trader should take no parameters, and should create a Trader with a single, randomly-chosen Trade. Trader should have the following public methods: public List<Trade> getTrades () - returns the current list of Trades supported by this Trader public void addRandomTrade() - adds a new, randomly-chosen Trade to the list. The Trade should be generated with the following constraints: o The value for gems should be between 1 and 5 (inclusive) o The value for amount should be between 1 and 5 (inclusive) o The value for Goods should be randomly chosen from the values of the Goods enum To generate a random number, you can use the java.util.Random class, as follows: Creating an object: Random rand = new Random(); Later on in the code, when you need a number: int value = rand.nextInt(n); will return a number between 0 and (n-1), inclusive Task 5: Trade.execute() (4 marks) In your Trade class, implement one additional public method, as follows: public void execute(Trader trader, Citizen citizen) This method should behave as follows: • If the current Trade is not included in the list of trades supported by trader, this method should throw an IllegalArgmentException • Otherwise, it should call citizen.executeTrade() with the current trade o If executeTrade() returns true, the method should also call trader.addRandom Trade() Java submission Ensure your submission files are named appropriately: Goods.java Trade.java Citizen.java Trader.java
Expert Answer:
Answer rating: 100% (QA)
Here are the Java classes to model the world involving Citizens Traders Goods and Trades java packag... View the full answer
Related Book For
Management Science The Art of Modeling with Spreadsheets
ISBN: 978-1118582695
4th edition
Authors: Stephen G. Powell, Kenneth R. Baker
Posted Date:
Students also viewed these general management questions
-
May Company has five salaried employees. Your task is to use the following information to calculate net pay for each employee: Assume the following: 1. FICA OASDI is 6.2% on $106,800; FICA Medicare...
-
Your task is to prepare isopropyl methyl ether by one of the following reactions. Which reaction would give the better yield? Explain your answer. (1) Isopropyl methyl ether Or (2) Isopropyl methyl...
-
Your task is to create a society or culture that fosters all of the support foundations of Maslow's pyramid to permit individuals to strive for the pinnacle. You will develop the essay in three...
-
Muskoka Boys Shaving Co. (MBSC") is a GST/HST registrant operating an online store in Ontario's cottage country region. The company specializes in selling fine grooming products for men. It is June...
-
Which U.S. government body has the legal power to determine generally accepted accounting principles?
-
The supply of loanable funds increases ________. A. when the demand for loanable funds increases B. when people increase saving as the real interest rate rises C. when disposable income increases or...
-
Find a video on deposition preparation that is available online. As a paralegal, how can you assist in preparing a client for deposition?
-
Nuke-It-Now manufactures microwave ovens. The following represents the financial information from one of its manufacturing plants for two years. Required a. Classify these items into prevention (P),...
-
Special Tea Products (STP) has an exclusive contract with Tea Distributors. Two brands of Teas are imported, Strong and Mild, and sold to retail outlets. The monthly budget for the contract is based...
-
Forrest runs Y Not Flowers, Inc. (YNF), a wholesale flower distributor with stores in several major metropolitan areas of the U.S. He is considering expanding his business, but he thinks his current...
-
The FCFF is expected to be $200,000 for t=1 and t=2. The FCFF is expected to grow at a rate of g = 5% per year starting in year t=3. a) The company's WACC = 10% and its market capitalization is k =...
-
Runge-Kutta methods find the approximate solutions of a. algebraic equations b. differential equations c. matrix equations
-
Fill in the Blank. For a thin beam element, the shape functions are assumed to be polynomials of degree _________ .
-
True or False. A limit cycle denotes a steady-state periodic oscillation.
-
True or False. Time does not appear explicitly in a trajectory plotted in the phase plane.
-
True or False. An isocline is the locus of points at which the trajectories passing through them have a constant slope.
-
Given: Price Quantity TR MR MC TC Profit $15,000 0 0 ---- ---- 20000 -$20,000 14,000 1 14000 14000 $2,000 22000 -8000 13,000 2 26000 12000 1000 $23,000 3000 12,000 3 36000 10000 1000 $24,000 12000...
-
Assume you are the accountant for Catalina Industries. John Catalina, the owner of the company, is in a hurry to receive the financial statements for the year ended December 31, 20X1, and asks you...
-
In the previous problem, suppose that vendor A provides a new price-discount schedule for component 3. This one is an "incremental" discount, as opposed to an "all-units" discount, as follows: Unit...
-
Refer to the Icebergs for Kuwait case. Review the problem statement and influence chart that were generated for this case in conjunction with the corresponding exercises in Chapter 2. (If this has...
-
The database Spambase.xlsx** contains detailed in for mation on the words used in a large number of emails. The emails are classified as Spam or Not Spam. The goal is to create a Nave Bayes model to...
-
Recording effects of transactions in T-accounts Record the transactions below for Amena Company by recording debit and credit amounts directly in the following T-accounts: Cash; Accounts Receivable;...
-
Identifying type and normal balances of accounts For each of the following (1) identify the type of account as an asset, liability, equity, revenue, or expense, (2) enter debit (Dr.) or credit (Cr.)...
-
Preparing a trial balance After recording the transactions of Exercise 3-2 in T-accounts and calculating the ending balance of each account, prepare a trial balance. Use May 31, 2008, as its report...
Study smarter with the SolutionInn App