AAS 390 Chapter Notes - Chapter 1: Subderivative, Propositional Formula, Random Variable
Section 3 - Programming Questions 7. Role playing video games (RPGs) form a loosely defined genre of video games in which the player controls a small number of game characters. These characters form a group of adventurers whose purpose is to fulfill one or many quests. A common feature of RPGs is that the group of adventurers can collect various items and keep them for future me, sach items are added to the player's inventory. In this question, you will write classes which could be used to manage a player's inventory in an RPG. Part 1 Write a class called Item. An Item object represents an entire category of items carried by a group of adventurers, and each Item object has the following attributes: • The description of the items in this category (a String) The quantity of tems in this category that the group of adventurers is currently carrying can int). For example, suppose the group of adventurers is carrying 50 Heal Potions and 10 Life Potions. The SO Heal Pations would he represented by a single Item object, the value of the description attribute of this item object would be the string "Heal Potion, and the value of the quantity attribute of this Item object woukl be 50. The 10 Life Potions would also be represented by a single Item object, which is different from the Ttem object representing the Heal Potions. The value of the description attribute of this second Ttem object would he Life Potion", and the value of the quantity attribute of this second liem object would be 10. The Item class MUST provide the following INSTANCE methods, note that in the method descrip tions below, the phrase "this Item" means the item on which the method in question is called • A constructor, which takes as its only parameter a string representing the description attribute of the newly created Item. This constructor sets the quantity attribute of the newly created Item to 1. • A method called get Description(), which takes no parameters and returns a string representing the value of the description attribute of this Item • A method called getQuantity O. which takes no parameters and returns an int represent ing the value of the quantity attribute of this Item • A method called set Quantity), which takes a value of type int as its only parameter and returns nothing. This method changes the value of the quantity attribute of this Item so that its new value is equal to the int value this method accepts as parameter, this happens regardless of what the value of the int parameter is, even if it represents a sensical value Note that you MUST respect proper encapsulation practices that is, the attributes and methods of your class MUST he declared using the proper visibility modifiers. Part 2 Write a class called Inventory, which represents the inventory of a group of adventures. An Inventory object has only one attributes a collection of items, which specifies all the types of items that a group of adventurers is currently carrying along with the mumber of items of each type that the group is carrying Inventory objects MUST keep track of the items being carried by adventurers using a PLAIN ARRAY of Items, you MUST NOT se ArrayLists (or any other class which is part of the the Java Collection Framework such as Linkedin.ist) within the Inventory class under ANY circumstances. Each position in the array contains cither • The address of an Item object in memory, an Item is considered to be in the Inventory if and only if its address in memory is stored in the array . null Fach Item object in the inventory MUST appear exactly once in this array, in other words, there MUST NOT be any duplicate elements in the array under ANY circumstances, whether these dupli cates are deep copies or aliases The Inventory class MUST provide the following INSTANCE methods, note that an actual im plementation used in an RPG would provide additional methods, in particular methods to add an item to the Inventory. Also note that in the method descriptions below, the phrase "this inventory" means "the Inventory on which the method in question is called • A constructor, which takes a value of type int as its only parameter, and initializes the newly created Inventory so that the number of item types it can store is equal to the value of the parameter. The number of item types which can be stored in the Inventory is fixed during instantiation, and can never change during the lifetime of the Inventory object • A method called get.Capacity (), which takes no parameters and returns a value of type int representing the capacity of this Inventory (that is, the number of different item types which can be stored in this Inventory). • A method called getItem(), which takes a value of type int as its only parameter, and returns the Item Nered at the commenpanding position in the array holding the Items stond in this Inventory, this method returns null if the element at the position specified by the parameter value is null or if the parameter represents an invalid index in this array. • A method called consumeOne(), which takes as its only parameter a string represent ing the description of an item, and returns a value of type boolean. The method searches the inventory for an item whose description is equal to the parameter String, with the comparison being performed in a case-INSENSITIVE manner. If no such Ttem exists in the inventory, the method returns false, and the state of the Inventory does not change. On the other hand, if such an Item exist in the inventory, the method returns true and modifies the state of the Inventory as follows: -If the quantity attribute of the item is greater than or equal to 2, then its value is reduced by 1. -If the quantity attribute of the Item is equal to 1, then the item is removed from the Inventory. Note that removing an Item can be done by simply assigning null to the amay position that contains it. The state of the array before and after calling this method can consist of addresses of Item objects interspersed with null elements. For example, in an Inventory whose capacity is 20, it is possible that the array contains the addresses of Item objects al positions 3 and 17. while the other amay position contains null. This implies that the method does NOT have to "compact the array so that the addresses of all the actual tem objects appear at the beginning of the array while all the null elements appear at the end. You MAY assume that the string parameter is not null; in other words, your method does not have to handle cases in which the string parameter is indeed null Akmal notes • You MUST respect proper encapulation practices, that is the attributes and methods of your class MUST be declared using the proper visibility modifiers. • Y MUNT call the methods you were asked to write in the previous part to retrieve the descrip tion and quantity attributes of an Item object, or to change the quantity attribute of an Item object. You MAY me that the item class has been implemented correctly, even if you did not successfully complete the previous part WRITE YOUR Inventory CLASS IN THE SPACE BELOW:
Hi. You should write a Java program to meet the specification shown below.
In this game(dice poker), the computer rolls two standard six-sided dice and you bet on the outcome. The outcome is the configuration of the numbers rolled (explanation below). The input/output should utilise a graphical user interface (input and message boxes).
1.1 Game flow
You start with some money in your bank. You play a number of rounds, where for each round you place a bet and the computer rolls the dice, checks results and modifies your bank balance. After certain conditions, the game ends and you're presented with some final information shown as a message box.
1.2 Placing bets
Before the computer rolls the dice, you can bet some money from your bank.
ˆ If the numbers are sequential (e.g. 1 and 2, 5 and 4, etc. Not 6 and 1), you earn double your bet.
ˆ If the numbers are identical (rolling doubles), you earn triple your bet.
ˆ Otherwise, you win nothing therefore you lose the amount of money you bet.
Before placing a bet, the computer should inform you of your current bank balance.
1.3 Starting Game- Game rules
When the game starts you are given £6 in your bank. Each bet costs £1 and you are allowed to make up to five bets before the game ends. The game will end if you run out of money, or you have no more attempts left (you made all five bets). At the end of the game, you will be told which of these conditions has ended the game.
1.4 Results display
Once the game has finished (all bets have been placed or you ran out of money) the computer will collate and display the results in a single message box, comprised by:
ˆ On row per bet, displaying your bet, the numbers rolled, the amount of money earned or lost for that bet.
ˆ One row at the end, displaying the amount of money that you have remaining in your bank at the end of the game.
1.5..Variable bet amount
Allow the user to change how much they would like to bet and change the amount you win accordingly. Allow bets between £1 and 4£ (integers only)
1.6.High score table
Create a high score table. The more money you have remaining in your bank at the end of the game the higher up the table you will be. In order to implement this, players will have to enter their name before they play. The high score table should be displayed as a separate message box after the results have been displayed at the end of the game(1.4)
Not1: Please use JoptionPane class instead of scanner class.
Not2: Also If possible explain the description of your classes: what each does and how they relate to each other. And if possible, program should be extensible. E.g. Is it easy to change the number of dice? The number of rounds to play? The sides of the dice?Etc.
Objective: Take a sample feed, parse it, augment it, and output individual JSON objects for each product in it.
- The file contains several fields of basic product information for 1000 products.
- Data for each product is on one line, with fields separated by a vertical pipe character.
This particular retailer classifies products into a particular store, department, category, and subcategory.
- A Blender might have the following "taxonomy" or category classification.
Home & Garden > Kitchen & Dining > Appliances > Blenders
These IDs are also represented in a sort of shorthand.
- They should all be prefixed by the first three letters of their respective field name.
A store_id of 1 becomes sto1
A department_id of 2 becomes dep2
A category_id of 3 becomes cat3
A subcategory_id of 4 becomes sub4
- A system to keep track of these various classifications
- A store_id of sto40 maps to a “target value” of 187298 in PromoteIQ's system
The desired output for the first product is one line of JSON that when pretty-printed looks like:
"name": "Brainboxes ES-571 Brainboxes Es-571 Industrial Isolated Ethernet to Serial + Switch - 1 x Network (R",
"description": "Brainboxes ES-571 Brand New Includes Lifetime Warranty Product # ES-571 Factory floors can be harsh environments.",
The taxonomy IDs have been mapped to their long form and placed in the taxonomy property.
- Each taxonomy ID has also been mapped to its corresponding target value ID from the targets.txt file
- and that result is stored in the targetValues
- The priceList property is the product price as a JSON float, not a string