Projects

Description

Write a program that is composed of three classes: Dodecahedron, DodecahedronList, and DodecahedronListMenuApp. DodecahedronListMenuApp presents a menu to the user with eight options and implements them. The program needs to read input from a file (which creates a DodecahedronList object), print report, print summary, add a Dodecahedron object to the DodecahedronList object, delete a Dodecahedron object from the DodecahedronList object, find a Dodecahedron object in the DodecahedronList object, Edit a Dodecahedron in the DodecahedronList object, and quit the program.

Dowloads

Links

Dodecahedron.java

Assuming that you successfully created this class in Project 4, just copy the file to your new Project 6 folder and go on to DodecahedronList.java

DodecahedronList.java

Assuming that you successfully created this class in Project 5, just copy DodecahedronList.java to your new Project 6 folder. DodecahedronList is extended from Project 5 by adding six new methods.

  • getList:

    Returns the ArrayList of Dodecahedron objects.
  • readFile:

    Takes a String parameter representing the file name, reads in the file stores the list name and creates an ArrayList of Dodecahedron objects, then uses the list name and the ArrayList to create a DodecahedronList object and return it.
  • addDodecahedron:

    Returns nothing but takes three parameters label, color, and edge. creates a new Dodecahedron object, and adds it to the DodecahedronList object
  • findDodecahedron:

    Takes a label of a Dodecahedron as the String parameter and returns the corresponding Dodecahedron object if found in the DodecahedronList; otherwise returns null. Case should be ignored when attempting to match the label.
  • deleteDodecahedron:

    Takes a String as a parameter that represents the label of the Dodecahedron and returns the Dodecahedron if it is found in the DodecahedronList object and deleted; otherwise returns null. Case should be ignored when attempting to match the label. consider using the findDodecahedron method.
  • editDodecahedron:

    Takes three parameters label, color, and edge. Uses the label to find the corresponding the Dodecahedron object. If found, sets the color and edge to the values passed in as parameters, and returns true else returns false

Remember to import java.util.ArrayList, java.util.Scanner, java.io.File, java.io.IOException.

DodecahedronListMenuApp.java

Requirements:

Create a DodecahedronListMenuApp class with a main method that presents the user with a menu with eight options. read input from a file, print report, print summary, add a Dodecahedron object to the DodecahedronList object, delete a Dodecahedron object from the DodecahedronList object, find a Dodecahedron object in the DodecahedronList object, Edit a Dodecahedron in the DodecahedronList object, and quit the program

Design:

The main method should print a list of options with the action code and a short description followed by a line with just the action codes prompting the user to select an action. After the user enters an action code, the action is performed. Then the line with just the action codes prompting the user to select an action is printed again to accept the next code. The user may continue to perform actions until ‘Q’ is entered to quit the program. Your program should accept both uppercase and lowercase action codes.

Explanation

Place Holder.

Description

The objective is to modify your Project 6 to use arrays instead of ArrayList objects. Write a program that is composed of three classes: Dodecahedron, DodecahedronList2, and DodecahedronList2MenuApp. DodecahedronListMenuApp presents a menu to the user with eight options and implements them. the program needs to read input from a file (which creates a DodecahedronList object), print report, print summary, add a Dodecahedron object to the DodecahedronList object, delete a Dodecahedron object from the DodecahedronList object, find a Dodecahedron object in the DodecahedronList object, Edit a Dodecahedron in the DodecahedronList object, and quit the program.

Dodecahedron.java

Assuming that you successfully created this class in Project 4, 5, or 6 just copy the file to your new Project 8 folder and go on to DodecahedronList2.java

DodecahedronList2.java

You must use arrays instead of ArrayList objects. Assuming that you successfully created this class in Project 6, just copy DodecahedronList.java to your new Project 8 folder and then open in jGRASP and rename as DodecahedronList2.

Requirements:

Create a DodecahedronList2 class that stores the name of the list and an array of Dodecahedron objects. It includes methods that return the name of the list, number of Dodecahedron objects in the DodecahedronList2, total surface area, total volume, average surface area, average volume, and average surface to volume ratio for all Dodecahedron objects in the DodecahedronList2. The toString method returns a String containing the name of the list followed by each Dodecahedron in the array, and a summaryInfo method returns summary information about the list.

Design:

The DodecahedronList2 class has three fields, a constructor, and methods as outlined below

  1. Fields
    a String representing the name of the list. An array of Dodecahedron objects. an int representing the number of elements in the array of Dodecahedron objects.
  2. Constructor
    Your DodecahedronList2 class must contain a constructor that accepts a parameter of type String representing the name of the list, a parameter of type Dodecahedron[ ], and a parameter of type int representing the number of elements in the Dodecahedron array.
  3. Methods
    • getName:

      Returns a String representing the name of the list.
    • numberOfDodecahedrons:

      Returns an int representing the number of Dodecahedron objects in the DodecahedronList2.
    • totalSurfaceArea:

      Returns a double representing the total surface areas for all Dodecahedron objects in the list.
    • totalVolume:

      Returns a double representing the total volumes for all Dodecahedron objects in the list.
    • averageSurfaceArea:

      Returns a double representing the average surface area for all Dodecahedron objects in the list.
    • averageVolume:

      Returns a double representing the average volume for all Dodecahedron objects in the list.
    • averageSurfaceToVolumeRatio:

      Returns a double representing the average surface to volume ratio for all Dodecahedron objects in the list.
    • toString:

      Returns a String (does not begin with \n) containing the name of the list followed by each Dodecahedron in the list. In the process of creating the return result, this toString() method should include a while loop that calls the toString() method for each Dodecahedron object in the list (adding a \n before and after each).
    • summaryInfo:

      Returns a String (does not begin with \n) containing the name of the list followed by various summary items: number of Dodecahedrons, total surface area, total volume, average surface area, average volume, and average surface to volume ratio. Use "#,##0.0##" as the pattern to format the double values.
    • getList:

      Returns the array of Dodecahedron objects.
    • readFile:

      Takes a String parameter representing the file name, reads in the file, storing the list name and creating an array of Dodecahedron objects, uses the list name, the array, and number of Dodecahedron objects in the array to create a DodecahedronList2 object, and then returns the DodecahedronList2 object.
    • addDodecahedron:

      Returns nothing but takes three parameters label, color, and edge. creates a new Dodecahedron object, and adds it to the DodecahedronList2 object.
    • findDodecahedron:

      Takes a label of a Dodecahedron as the String parameter and returns the corresponding Dodecahedron object if found in the DodecahedronList2 object else returns null. Case should be ignored when attempting to match the label.
    • deleteDodecahedron:

      Takes a String as a parameter that represents the label of the Dodecahedron and returns the Dodecahedron if it is found in the DodecahedronList2 object and deleted else returns null. consider using findDodecahedron
    • editDodecahedron:

      Takes three parameters label, color, and edge. uses the label to find the corresponding the Dodecahedron object in the list. If found, sets the color and edge to the values passed in as parameters, and returns true. if not found returns false

DodecahedronList2MenuApp.java

Requirements:

Create a DodecahedronList2MenuApp class with a main method that presents the user with a menu with eight options. read input from a file, print report, print summary, add a Dodecahedron object to the DodecahedronList object, delete a Dodecahedron object from the DodecahedronList object, find a Dodecahedron object in the DodecahedronList object, Edit a Dodecahedron in the DodecahedronList object, and quit the program

Design:

The main method should print a list of options with the action code and a short description followed by a line with just the action codes prompting the user to select an action. After the user enters an action code, the action is performed. Then the line with just the action codes prompting the user to select an action is printed again to accept the next code. The user may continue to perform actions until ‘Q’ is entered to quit the program. Your program should accept both uppercase and lowercase action codes.

Explanation

So for this project we are tasked with replacing ArrayList with Arrays. The only two classes that we will edit from project 6 are DodeacahedronList and DodecahedronListMenuApp. First you need to rename the classes to DodeacahedronList2 and DodecahedronList2MenuApp. Then you need to change the names of all of the thinks that reference the class from project 6. I found the best way to do this is to compile it as is with the class name changes and look at the compile errors. After you fix the most of the compile time errors you need to start changing the ArrayList variables to Arrays. This is not all to hard because the syntax for arrays is fairly simple.

// for example I changed the ArrayList at the begining of the DodecahedronList2.java
ArrayList<Dodecahedron> dodObjList;
// to
Dodecahedron[] dodObjList;

Continue this until you change all of the ArrayList objects to Arrays, then compile it. For the readFile method its simple if you know why you are doing it. So we are returning the constructor for the class we are writing in. So we need to create a listName, a list, and the number of objects in the array. We need to delare all of the variables we will use at the top and then we will create a while loop that goes through the file and asigns the label, color, and edge to the varaibales we created using the Scanner class. Then we will create an object of type Dodecahedron and fill in its respective constructor. Then we should assign that object to the list you created at the begining of the file.

Dodecahedron object = new Dodecahedron(label, color, edge);
objectList[arraySize] = object;

Then we need to increment the arraySize variable and to end our while loop simply add a " } ", the loop should terminate when it runs out of lines to parse. Now we need to fill out the constructor of the class and then return that object. For the deleteDodecahedron method I highly recomend looking at the example files, they are extreamly helpfull in writing this method. The goal for the method is to delete and return an object found in an array. So first we declare a null object to eventually copy the found object in the array. Then we must itterate though the array until we find the desired object, or use the findDodecahedron method you should have made earlier in the class. Copy the object to the copy variable you created earlier and set them equal, now you need to delete the object from the array. This can be done by overwriting the folowing objects in a index below them. Dont forget to set the final object to null or you will have two of the same object in the array. Now your object should be 'deleted' from the array, now make sure decriment the size variable that you should have created at the begining of the class, and return the copied object. For the editDodecahedron method I have a for loop that goes through the list, this can also be done by using the findDodecahedron method and checking if its label is equal to the input label. Then I created a statment that checks the label name and if thats true it edits the object by calling the setColor and seEdge methods and returning true, else returning false.