Question: sing your existing Game.java class. Create a new class called Inventory.java that will keep track of all the Game inventory. The Inventory class will maintain
sing your existing Game.java class. Create a new class called Inventory.java that will keep track of all the Game inventory. The Inventory class will maintain a list of games that are available for sale. Available operations are as below.
- Constructor
- void add(Game)
- void remove(Game)
- Game findCheapestGame()
- Game findMostHighlyRatedGame()
- void printAveragePriceOfAllGames()
You can use the List provided by the Java API: List Interface and ArrayList class (implements List) Take a look at the provided methods and decide which ones could be of use to you.
Write JUnit tests to test the Inventory.java class. Follow the guidelines as discussed in class:
- Use AAA (Arrange-Act-Assert) style of testing
- Have good code coverage (test at the minimum every method excluding simple getters and setters, every branches inside a method, test with boundary values, etc)
- Have happy cases (at a minimum), and failure cases when a failure can happen
import java.math.BigDecimal; import java.time.LocalDate; import java.util.ArrayList; import java.util.Date; import java.util.List; public class Game { private ArrayList platform; private String name; private LocalDate releaseDate; private String developer; private List genre; private BigDecimal price; private String rating; public Game(List platform, String Game, LocalDate of, String Developer, boolean Genre, double price, String rating) { } public ArrayList getPlatform() { return platform; } public void setPlatform(ArrayList platform) { this.platform = platform; } public String getName() { return name; } public void setName(String name) { this.name = name; } public LocalDate getReleaseDate() { return releaseDate; } public void setReleaseDate(LocalDate releaseDate) { this.releaseDate = releaseDate; } public String getDeveloper() { return developer; } public void setDeveloper(String developer) { this.developer = developer; } public List getGenre() { return genre; } public void setGenre(List genre) { this.genre = genre; } public double getPrice() { return price.doubleValue(); } public void setPrice(double price) { this.price = new BigDecimal(price + ""); } public String getRating() { return rating; } public void setRating(String rating) { this.rating = rating; } @Override public String toString() { return "Game{" + "platform=" + platform + ", name='" + name + '\'' + ", releaseDate=" + releaseDate + ", developer='" + developer + '\'' + ", genre=" + genre + ", price=" + price + ", rating='" + rating + '\'' + '}'; } public void printGame() { System.out.println(platform); System.out.println(name); System.out.println(releaseDate); System.out.println(developer); System.out.println(genre); System.out.println(price); System.out.println(rating); } }
import org.junit.Test; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; public class GameTest { @Test public void testGames() { List platform = new ArrayList<>(); platform.add("PC"); Game diablo = new Game(platform,"Diablo", LocalDate.of(1997, 1, 3), "Blizzard North", new ArrayList<>().add("Action RPG"), 59.99, "M"); System.out.println(diablo); platform.add("PC"); Game Minecraft = new Game(platform,"Minecraft", LocalDate.of(2011, 11, 18), "Mojang Studios,", new ArrayList<>().add("Sandbox, survival"), 29.99, "E"); System.out.println(diablo); platform.add("PC"); Game LeagueOfLegends = new Game(platform,"LeagueOfLegends", LocalDate.of(2009, 10, 27), "Riot Games ", new ArrayList<>().add("Moba"), 00.00, "T"); System.out.println(LeagueOfLegends); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
