Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Any help is much appreciated! 3 classes with an input file from excel. I'll add a picture of the excel file below. Just let me

Any help is much appreciated! 3 classes with an input file from excel. I'll add a picture of the excel file below. Just let me know if you need anything else!

image text in transcribed

/** * Driver class that passes in the name of a csv file to UtilityBelt to parse. The csv file is a list of equipments. * The data is then displayed. */ public class Driver { public static void main(String[] args) throws IOException { // When you submit, you should only read in from "InputOfficial.csv". // You may test by using different .csv files, however. UtilityBelt utilityBelt = new UtilityBelt("InputOfficial.csv"); // TODO: test your code here: utilityBelt.writeEquipment("BeltInfo.txt"); utilityBelt.writeStatistics("BeltStats.txt"); // TODO: modify the Input.csv file to allow proper testing of playersFromState() and writePlayers(). Currently, // Input.csv has only equipments from the same state. writePlayers() with two parameters should only write // out information about a subset of equipments, not all equipments. This functionality needs to be tested. } }

/** * A class to represent items stored in Batman's utility belt. Several copies of an item may appear * in the Utility belt (e.g. 5 batarangs), so the Equipment class keeps a count variable tracking * the number of copies of the item. I.e. there would be one equipment object for "batarangs", for * which the count variable would be equal to 5. */ public class Equipment { /** * The name of the items. */ private String name; /** * The number of copies of the item stored in the belt. */ private int count; /** * The total weight of the items. */ private double totalWeight; /** * The total price of the items. */ private double totalPrice; /** * The description of the items. */ private String description; /** * Constructor for Equipment. Takes in information on the Equipment as a comma delimited string, * stores info on name, count, totalWeight, totalPrice, and its description. Note that the name and count * are separated by a comma, not a forward slash. * * @param strg Information about the Equipment in the format: * "name/count,totalWeight,totalPrice,description" * The description will not contain any commas or forward-slashes. * The count is an integer value. */ public Equipment(String strg) { // TODO: complete method } /** * toString override. Gives all information about the Equipment. * * @return All information about the Equipment formatted as (replacing parentheses with member variables): * "Name: (name), Number: (count), Weight: (weight, to 2 decimal places) lbs, Price: $(price, to 2 decimal places) - (description)" * * e.g. * "Name: Batarang, Number: 5, Weight: 3.22 lbs, Price: $700.75 - bat-shaped boomerangs" */ @Override public String toString() { // TODO: complete method } // TODO: create getters... } }

/** * Class that represents Batman's utility belt. Stores the list of all equipment * in the belt and computes statistics about the equipment. * * Reads in equipment information from files and outputs stats to other files. * */ public class UtilityBelt { /** * The list of equipment in the utility belt. * Don't worry about the "protected" for now; this is done to make tests easier. */ protected ArrayList equipment = new ArrayList(); /** * THIS METHOD IS PROVIDED TO YOU. * YOU SHOULD NOT MODIFY IT! * * Constructor, takes in a csv file of Equipment and stores them in a list. * * @param filename The name of the csv file containing a list of Equipment, one Equipment on each line. * Assumes that the csv file is at the top level of the project * (not within any folders; at the same level as src and TODO.json - this will be handled automatically * in Zylabs). */ public UtilityBelt(String filename) { // Attempt to read a csv file, catch an error if something goes wrong: try { read(filename); } catch(IOException e) { System.out.println("Error reading from file! "); e.printStackTrace(); } } /** * Loads a list of equipment from a CSV file. Each line of the csv represents a single Equipment. * The first line of the csv denotes the order of the fields, you should not * construct a player from the first line. * * @param filename The file to read from. * @throws IOException Throw this exception if a major issue with the file occurs. */ public void read(String filename) throws IOException { // Use a buffered Reader on the file: BufferedReader br = new BufferedReader(new FileReader(filename)); String strg; // TODO: complete method... // TODO: close reader... } /** * Writes out information about the Equipment in the UtilityBelt. * Specifically, loop through the list of equipments write out each equipment's toString(). * A newline is added after each toString (using BufferedWriter's newLine() method). * * @param filename the file to write out to (should be a .txt file). * When you run this method locally this file may not load into eclipse. You should use * File>Refresh on the project to view the files in eclipse. */ public void writeEquipment(String filename) throws IOException { // Set up the writer: BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); // Write out each equipment, adding a newline between toStrings: // TODO: complete method // Close the writer: // TODO: close writer } /** * Formats and writes out information about the statistics of a UtilityBelt. * Specifically, write out information in the following format: * * "Total Weight: (total weight) Most Expensive Equipment: (name of the most expensive equipment) "" * * @param filename the file to write out to (should be a .txt file). * When you run this method locally this file may not load into eclipse. You should use * File>Refresh on the project to view the files in eclipse. */ public void writeStatistics(String filename) throws IOException { // TODO: complete method } /** * Gives the total weight of the UtilityBelt. * * @return Sum of the weights of the Equipment in the UtilityBelt. */ public double computeTotalWeight() { // TODO: complete method } /** * Find equipment with the same name. * * @param name The name to compare to. * @return The equipment with the same name, ignoring case. Return null if * no equipment has the same name. */ public Equipment getNamedEquipment(String name) { // TODO: complete method } /** * Calculates the subset of equipments which have a count above a certain amount. * * @param state Equipment with a count variable above the input amount should be aggregated and returned. * @return An arraylist containing all equipments whose count is above the input variable "count". */ public ArrayList equipmentAboveCount(int count) { // TODO: complete method } /** * Finds the most expensive Equipment (highest total price variable). * * @return A Equipment object that has the highest total price variable out of all Equipment recorded. * If there are no equipment in the utility belt, return null. */ public Equipment findMostExpensiveEquipment() { // TODO: complete method } }

totalWeight totalPrice description 5 A boomerang for bats 3 Shark repelling bat spray Bat Shark Repellent/3 Bomb/1 50.6 70.6 Something you sometimes just can't get rid of 6 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions