In Java: -Using a BST Interface (Binary Search Tree) -Create a class Disk. Disk contains four fields: model (String), size (int), measure (String, for GB or TB), and performance index (int). -Disk needs a constructor to initialize all fields, a toString method, and an equals. Make the class Comparable and write a compareTo method that compares Disks based on the size of the disk. Make sure your comparison accounts for the fact that some numbers are in GB and some are in TB. Write a method that will return true if the disk is the same size as the parms; parms are the size and measure("GB" or "TB"). Also write a method to create a Comparator which compares Disks based on the performance rating. -The client code should do the following: Write a function called build, which will open the disks.txt file, read in each disk and add it to the BST. For each disk the model is on the first line, and the second line contains the size, measure, and performance index. The BST is passed to build as a parameter. Write a function that prompts for size and measure and prints all disks of that size. In main create a BST of Disks which will order the Disks by size. Pass this BST to your build function. Then create an iterator to visit the disks in preorder, and use this iterator to print all the disks. Create another iterator to visit the disks in inorder and use this iterator to print all the disks. Call your function to print all Disks of a given size. Create another BST that is ordered by performance rating. Create an iterator for your first BST (ordered by size). Create a loop and in the loop body add each Disk returned by next() to your new BST (ordered by performance rating). Create an iterator to traverse your new BST (ordered by performance rating) in order, and use it to print all the Disks in a BST disks.txt file attached.
In Java:
-Using a BST Interface (Binary Search Tree)
-Create a class Disk. Disk contains four fields: model (String), size (int), measure (String, for GB or TB), and performance index (int).
-Disk needs a constructor to initialize all fields, a toString method, and an equals. Make the class Comparable and write a compareTo method that compares Disks based on the size of the disk. Make sure your comparison accounts for the fact that some numbers are in GB and some are in TB. Write a method that will return true if the disk is the same size as the parms; parms are the size and measure("GB" or "TB"). Also write a method to create a Comparator which compares Disks based on the performance rating.
-The client code should do the following:
- Write a function called build, which will open the disks.txt file, read in each disk and add it to the BST. For each disk the model is on the first line, and the second line contains the size, measure, and performance index. The BST is passed to build as a parameter.
- Write a function that prompts for size and measure and prints all disks of that size.
- In main create a BST of Disks which will order the Disks by size. Pass this BST to your build function. Then create an iterator to visit the disks in preorder, and use this iterator to print all the disks. Create another iterator to visit the disks in inorder and use this iterator to print all the disks.
- Call your function to print all Disks of a given size.
- Create another BST that is ordered by performance rating. Create an iterator for your first BST (ordered by size). Create a loop and in the loop body add each Disk returned by next() to your new BST (ordered by performance rating).
- Create an iterator to traverse your new BST (ordered by performance rating) in order, and use it to print all the Disks in a BST
disks.txt file attached.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images