Question: Video Game Inventory: Video Game Class VideoGame.java Video game Collection GameCollection.java Video Game Driver VGDriver.java Video Game Inventory You will need to perform the following
Video Game Inventory:
Video Game Class VideoGame.java
Video game Collection GameCollection.java
Video Game Driver VGDriver.java
Video Game Inventory
You will need to perform the following steps
Using the DVD class as a template:
Create a class called VideoGame that has the following private members:
Game title (String)
Game publisher (String)
Year the game was released (int)
Platform the game is played on (String)
Price of the game (double)
Completed status (boolean)
Modify the constructor so that it sets up a VideoGame object
Modify the toString so that it displays the contents of the VideoGame object
Modify the if statement so that if the status is true, add the string Finished to the data.
Using the DVDCollection class as a template:
Create a class called GameCollection that has the following private members:
An array of VideoGame objects
Amount of games (int)
total cost of games (double)
Modify the constructor so that it creates a VideoGame array of size 100
Keep the initial values of count and totalValues from the template
Modify the addDVD method (call it addGame) so that it accepts the 6 corresponding parameters for a video game to set up a VideoGame object
Modify the toString method to Display information for the VideoGame collection
Modify the increaseSize method so that it doubles the size of the VideoGame array if needed
Using the Movie class is as template:
Create a driver program called GameDriver, that tests your VideoGame Array object
Use the addGame method to add at least three games to the array
Check the contents of the array
Add at least one more game to the array using the addGame method
Check the updated contents of the array
A sample of the output is shown below:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ My Video Game Collection Number of Games: 3 Total cost: $60.97 Average cost: $20.32 Video Game List: $15.99 1997 Final Fantasy VII Square Enix PlayStation Finished! $19.99 2004 Ninja Gaiden Ubisoft Xbox $24.99 2005 Kingdom Hearts II Square Enix PlayStation 2 Finished! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ My Video Game Collection Number of Games: 4 Total cost: $82.92 Average cost: $20.73 Video Game List: $15.99 1997 Final Fantasy VII Square Enix PlayStation Finished! $19.99 2004 Ninja Gaiden Ubisoft Xbox $24.99 2005 Kingdom Hearts II Square Enix PlayStation 2 Finished! $21.95 2013 Tomb Raider Square Enix PlayStation 3
CODE USED IN THE FOLLOWING LAB THAT NEEDS MODIFIED
//********************************************************************
// DVD.java Author: Lewis/Loftus
//
// Represents a DVD video disc.
//********************************************************************
import java.text.NumberFormat;
public class DVD
{
private String title, director;
private int year;
private double cost;
private boolean bluRay;
//-----------------------------------------------------------------
// Creates a new DVD with the specified information.
//-----------------------------------------------------------------
public DVD(String title, String director, int year, double cost, boolean bluRay)
{ this.title = title;
this.director = director;
this.year = year;
this.cost = cost;
this.bluRay = bluRay;
}
//-----------------------------------------------------------------
// Returns a string description of this DVD.
//----------------------------------------------------------------- public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String description;
description = fmt.format(cost) + "\t" + year + "\t";
description += title + "\t" + director;
if (bluRay)
description += "\t" + "Blu-Ray";
return description;
}
}
Class Definition DVD.Collection.java
//********************************************************************
// DVDCollection.java Author: Lewis/Loftus
// Represents a collection of DVD movies.
//********************************************************************
import java.text.NumberFormat;
public class DVDCollection
{
private DVD [] collection;
private int count;
private double totalCost;
//-----------------------------------------------------------------
// Constructor: Creates an initially empty collection.
//-----------------------------------------------------------------
public DVDCollection()
{
collection = new DVD[100]; count = 0; totalCost = 0.0;
}
//----------------------------------------------------------------- //
Adds a DVD to the collection, increasing the size of the collection array if necessary.
//----------------------------------------------------------------- //
public void addDVD(String title, String director, int year, double cost, boolean bluRay)
{
if (count == collection.length) increaseSize();
collection[count] = new DVD(title, director, year, cost, bluRay);
totalCost += cost;
count++;
}
//-----------------------------------------------------------------
// Returns a report describing the DVD collection.
//-----------------------------------------------------------------
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ";
report += "My DVD Collection ";
report += "Number of DVDs: " + count + " ";
report += "Total cost: " + fmt.format(totalCost) + " ";
report += "Average cost: " + fmt.format(totalCost/count);
report += " DVD List: ";
for (int dvd = 0; dvd < count; dvd++)
report += collection[dvd].toString() + " ";
return report;
}
//-----------------------------------------------------------------
// Increases the capacity of the collection by creating a // larger array and copying the existing collection into it. //-----------------------------------------------------------------
private void increaseSize()
{
DVD[] temp = new DVD[collection.length * 2];
for (int dvd = 0; dvd < collection.length; dvd++)
temp[dvd] = collection[dvd];
collection = temp;
}
}
Driaver Program Movies.jav
//********************************************************************
// Movies.java Author: Lewis/Loftus
// Demonstrates the use of an array of objects.
//********************************************************************
public class Movies
{
//-----------------------------------------------------------------
// Creates a DVDCollection object and adds some DVDs to it. Prints
// reports on the status of the collection.
//----------------------------------------------------------------- public static void main(String[] args)
{
DVDCollection movies = new DVDCollection();
movies.addDVD("The Godfather", "Francis Ford Coppala", 1972, 24.95, true);
movies.addDVD("District 9", "Neill Blomkamp", 2009, 19.95, false);
movies.addDVD("Iron Man", "Jon Favreau", 2008, 15.95, false);
movies.addDVD("All About Eve", "Joseph Mankiewicz", 1950, 17.50, false);
movies.addDVD("The Matrix", "Andy & Lana Wachowski", 1999, 19.95, true);
System.out.println(movies);
movies.addDVD("Iron Man 2", "Jon Favreau", 2010, 22.99, false);
movies.addDVD("Casablanca", "Michael Curtiz", 1942, 19.95, false);
System.out.println(movies);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
