Java:
I have the full code complete i just need it to be replace the Database class with another
implementation which uses a linked list of binary search trees to organize the information. That
is, your Database class will have a linked list of years; each year will have within it a binary
search tree of Storms. The sort orders for the binary search trees and linked lists is the same as
those used in previous assignments (i.e., the upper list of years is ordered numerically, and the
lower binary search trees of storms are ordered by name in standard dictionary order). You
should use your hand-crafted linked lists for the list of years, not the built-in linked lists used in
Programming Assignment 3. As before, you may use any variations on binary search trees
(dummy head nodes, extra pointers, etc.) which you might find useful.
The textfile this program is reading from looks like this:
2000/Alex/0110/0120/0
2001/Bill/0210/0220/0
2002/Chris/0310/0320/0
2003/Devon/0140/0420/0
2004/Eli/0510/0520/1
2005/Fred/0610/0620/2
2006/Gilbert/0710/0820/3
2007/Herbert/0910/0920/4
2008/Kim/1010/1020/5
#####################program under######################
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Storm { //setting variables to string or int
private int stormYear;
private int stormMag;
private String stormStart;
private String stormEnd;
private String stormName;
/**
* Constructor
* Storing all variables from text file
* @param stormName
* @param stormYear
* @param stormStart
* @param stormEnd
* @param stormMag
*/
public Storm(String stormName, int stormYear, String stormStart, String stormEnd, int
stormMag) {
this.stormName = stormName;
this.stormYear = stormYear;
this.stormStart = stormStart;
this.stormEnd = stormEnd;
this.stormMag = stormMag;
}
/**************************************************************/
/*Method: Get and Set */
/*Purpose: They serve to set&get values from class variables */
/*Parameters: */
/*String target: Storm Name */
/*Return: Storm Name */
/**************************************************************/
public String getStormName() {
return stormName;
}
/**
* @param stormName the stormName to set
*/
public void setStormName(String stormName) {
this.stormName = stormName;
}
/**
* @return the stormYear
*/
public int getStormYear() {
return stormYear;
}
/**
* @param stormYear the stormYear to set
*/
public void setStormYear(int stormYear) {
this.stormYear = stormYear;
}
/**
* @return the stormStart
*/
public String getStormStart() {
return stormStart;
}
/**
* @param stormStart the stormStart to set
*/
public void setStormStart(String stormStart) {
this.stormStart = stormStart;
}
//return the stormEnd
public String getStormEnd() {
return stormEnd;
}
//param stormEnd the stormEnd to set
public void setStormEnd(String stormEnd) {
this.stormEnd = stormEnd;
}
//return the stormMag
public int getStormMag() {
return stormMag;
}
/**
* @param sto.
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
JavaI have the full code complete i just need it to be replace th.pdf
1. Java:
I have the full code complete i just need it to be replace the Database class with another
implementation which uses a linked list of binary search trees to organize the information. That
is, your Database class will have a linked list of years; each year will have within it a binary
search tree of Storms. The sort orders for the binary search trees and linked lists is the same as
those used in previous assignments (i.e., the upper list of years is ordered numerically, and the
lower binary search trees of storms are ordered by name in standard dictionary order). You
should use your hand-crafted linked lists for the list of years, not the built-in linked lists used in
Programming Assignment 3. As before, you may use any variations on binary search trees
(dummy head nodes, extra pointers, etc.) which you might find useful.
The textfile this program is reading from looks like this:
2000/Alex/0110/0120/0
2001/Bill/0210/0220/0
2002/Chris/0310/0320/0
2003/Devon/0140/0420/0
2004/Eli/0510/0520/1
2005/Fred/0610/0620/2
2006/Gilbert/0710/0820/3
2007/Herbert/0910/0920/4
2008/Kim/1010/1020/5
#####################program under######################
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Storm { //setting variables to string or int
private int stormYear;
private int stormMag;
private String stormStart;
private String stormEnd;
private String stormName;
/**
* Constructor
* Storing all variables from text file
* @param stormName
2. * @param stormYear
* @param stormStart
* @param stormEnd
* @param stormMag
*/
public Storm(String stormName, int stormYear, String stormStart, String stormEnd, int
stormMag) {
this.stormName = stormName;
this.stormYear = stormYear;
this.stormStart = stormStart;
this.stormEnd = stormEnd;
this.stormMag = stormMag;
}
/**************************************************************/
/*Method: Get and Set */
/*Purpose: They serve to set&get values from class variables */
/*Parameters: */
/*String target: Storm Name */
/*Return: Storm Name */
/**************************************************************/
public String getStormName() {
return stormName;
}
/**
* @param stormName the stormName to set
*/
public void setStormName(String stormName) {
this.stormName = stormName;
}
/**
* @return the stormYear
*/
public int getStormYear() {
return stormYear;
3. }
/**
* @param stormYear the stormYear to set
*/
public void setStormYear(int stormYear) {
this.stormYear = stormYear;
}
/**
* @return the stormStart
*/
public String getStormStart() {
return stormStart;
}
/**
* @param stormStart the stormStart to set
*/
public void setStormStart(String stormStart) {
this.stormStart = stormStart;
}
//return the stormEnd
public String getStormEnd() {
return stormEnd;
}
//param stormEnd the stormEnd to set
public void setStormEnd(String stormEnd) {
this.stormEnd = stormEnd;
}
//return the stormMag
public int getStormMag() {
return stormMag;
}
/**
* @param stormMag the stormMag to set
*/
public void setStormMag(int stormMag) {
4. this.stormMag = stormMag;
}
/**************************************************************/
/*Method:String toString */
/*Purpose: convert to a string */
/*Parameters: */
/*String target: Storm Name */
/*Return: Storm Name */
/**************************************************************/
public String toString() {
String s = " " + getStormYear() + "/ " + getStormName() + " " ;
if(getStormMag() == -1){
s= s + "(no info)";
}
else {
if((getStormMag() == 0)){
s = s + "(tropical storm)";
}
else{
s = s + "(hurricane level " + getStormMag() + ")";
}
if(getStormStart().equals("")){
s = s + "(no start)";
}
else{
s = s + getStormEnd().substring(0, 2) + "/" + getStormEnd().substring(2)+" - " ;
}
if(getStormEnd().equals("")){
s = s + "(no end)" ;
}
else{
s = s + getStormEnd().substring(0, 2) + "/" + getStormEnd().substring(2);
}
}
return s;
}
5. }
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.LinkedList;
class Database {
//Variables
// node to store linked list
private LinkedList < Storm > list;
int count;
// Constructor
public Database(File fileName) {
list = null;
count = 0;
//Scanner used to read file
try {
Scanner in = new Scanner(new File("stormdata.txt"));
while ( in .hasNextLine()) {
String line = in .nextLine();
String[] data = line.split("/");
if (data.length < 2 || data.length > 5) {
System.out.println("Entry is in an incorrect format " + line);
continue;
}
Storm storm = null;
System.out.println(line);
if (data.length < 2)
continue;
if (data.length == 2) {
storm = new Storm(data[1], Integer.parseInt(data[0]), "", "", 0);
}
else if (data.length == 3) {
storm = new Storm(data[1], Integer.parseInt(data[0]), data[2], "", 0);
}
else if (data.length == 4) {
6. storm = new Storm(data[1], Integer.parseInt(data[0]), data[2], data[3], 0);
}
else {
storm = new Storm(data[1], Integer.parseInt(data[0]), data[2], data[3],
(Integer.parseInt(data[4])));
}
count++;
if (list == null) {
list = new LinkedList < Storm > ();
list.add(storm);
}
else {
int year = Integer.parseInt(data[0]);
int size = list.size();
int current;
for (current= 0; current< size; current++) {
if (list.get(current).getStormYear() < year)
continue;
list.add(current, storm);
break;
}
if (current== size) {
list.add(storm);
}
}
}
in .close();
}
catch (FileNotFoundException F) {
System.out.println("File not found");
}
catch (InputMismatchException e) {
System.out.print("Input was not found");
}
7. }
//Searching the storm by namee
//looking up name
public void SearchStormName(String name) {
boolean found = false;
for (int current= 0; current< list.size(); current++) {
if (list.get(current).getStormName().toLowerCase().indexOf(name.toLowerCase()) == 0) {
found = true;
System.out.print(list.get(current));
}
}
if (!found)
System.out.println(name + " was not found in the database ");
}
//Searching storm by year
//looking up year
public void SearchStormYear(int year) {
boolean found = false;
for (int current= 0; current< list.size(); current++) {
if (list.get(current).getStormYear() == year) {
found = true;
System.out.print(list.get(current));
}
}
if (!found)
System.out.println("Storm " + year + " was not found");
}
//printing all data saved
public void printAll() {
for (int current= 0; current< list.size(); current++) {
System.out.print(list.get(current));
}
}
8. //finds storm by year name
private boolean find(int year, String name) {
for (int current= 0; current< list.size(); current++) {
if (list.get(current).getStormYear() == year &&
list.get(current).getStormName().equalsIgnoreCase(name)) {
return true;
}
}
return false;
}
//finds index of storm year and name
private int getIndex(int year, String name) {
for (int current= 0; current< list.size(); current++) {
if (list.get(current).getStormYear() == year &&
list.get(current).getStormName().equalsIgnoreCase(name)) {
return current;
}
}
return -1;
}
//deletes data from text file
public boolean delete() {
Scanner in = new Scanner(System.in);
System.out.print("Enter the name of the Storm :");
String name = in.next();
System.out.print("Enter the year of the Storm :");
int year = in.nextInt();
if (!find(year, name)) {
System.out.println("Storm with given name and year does not exists!");
return false;
}
for (int current= 0; current< list.size(); current++) {
if (list.get(current).getStormYear() == year &&
list.get(current).getStormName().equalsIgnoreCase(name)) {
list.remove(current);
return true;
9. }
}
return false;
}
//add storm to the data
public boolean add() {
Scanner in = new Scanner(System.in);
System.out.print("Enter the name of the Storm :");
String name = in.next();
System.out.print("Enter the year of the Storm :");
int year = in.nextInt();
if (find(year, name)) {
System.out.println("Storm with given name and year already exists!");
return false;
}
System.out.print("Enter the start of the Storm :");
String start = in.next();
System.out.print("Enter the end of the Storm :");
String end = in.next();
System.out.print("Enter the strength of the Storm :");
int strength = in.nextInt();
int size = list.size();
int current;
for (current= 0; current< size; current++) {
if (list.get(current).getStormYear() < year)
continue;
list.add(current, new Storm(name, year, start, end, strength));
break;
}
if (current== size) {
list.add(new Storm(name, year, start, end, strength));
}
10. return true;
}
//editing data already saved
public boolean edit() {
Scanner in = new Scanner(System.in);
System.out.print("Enter the name of the Storm :");
String name = in.next();
System.out.print("Enter the year of the Storm :");
int year = in.nextInt();
if (!find(year, name)) {
System.out.println("Storm with given name and year does not exist!");
return false;
}
System.out.println("Enter choice to edit :");
System.out.println("1. Start of storm");
System.out.println("2. End of storm");
System.out.println("3. Level of storm");
System.out.print("Enter choice : ");
int choice = in.nextInt();
if (choice == 1) {
System.out.println("Enter the start of the Storm :");
in.nextLine();
String start = in.nextLine();
for (int current= 0; current< list.size(); current++) {
if (list.get(current).getStormYear() == year &&
list.get(current).getStormName().equalsIgnoreCase(name)) {
list.get(current).setStormStart(start);
break;
}
}
}
else if (choice == 2) {
System.out.println("Enter the end of the Storm :");
in.nextLine();
String end = in.nextLine();
11. for (int current= 0; current< list.size(); current++) {
if (list.get(current).getStormYear() == year &&
list.get(current).getStormName().equalsIgnoreCase(name)) {
list.get(current).setStormEnd(end);
break;
}
}
}
else if (choice == 3) {
in.nextLine();
System.out.print("Enter the strength of the Storm :");
int strength = in.nextInt();
for (int current= 0; current< list.size(); current++) {
if (list.get(current).getStormYear() == year &&
list.get(current).getStormName().equalsIgnoreCase(name)) {
list.get(current).setStormMag(strength);
break;
}
}
}
return true;
}
//user can search multiple different storms
public boolean searchMultiple() {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of storms to search : ");
int numberOfStorms = in.nextInt();
int[] years = new int[numberOfStorms];
String[] names = new String[numberOfStorms];
boolean found = true;
for (int current= 0; current< numberOfStorms; current++) {
System.out.print("Enter year for storm number " + (current+ 1) + " : ");
years[current] = in.nextInt();
in.nextLine();
System.out.println("Enter name for storm number " + (current+ 1) + " : ");
12. names[current] = in.nextLine();
}
for (int current= 0; current< numberOfStorms; current++) {
if (find(years[current], names[current])) {
System.out.println("Found!");
System.out.println(list.get(getIndex(years[current], names[current])));
}
else {
System.out.println("No storm found with name : " + names[current] + " and year : " +
years[current]);
found = false;
}
}
if (found) {
System.out.println("All storms were found!");
}
else {
System.out.println("Not all storms were found!");
}
return found;
}
}
import java.io.File;
import java.util.Scanner;
class Prog2{
public static void main(String args[]) {
final int SearchStormName=1;
final int SearchStormYear=2;
final int Print=3;
final int edit=4;
final int add=5;
final int delete=6;
final int Close=7;
File file = new File("stormdata.txt");
if (!file.exists())
13. System.out.println("File for input not there.");
else {
Database dbase = new Database(file);
Scanner in = new Scanner(System.in);
int choice = 0;
//What the user will seee
System.out.println("Welcome to the CS-102 Storm Tracker Program ");
System.out.println("Please choose what you would like to do");
while (true) {
System.out.println(" 1. Search for a storm name");
System.out.println("2. Search for a storm year");
System.out.println("3. Print all storms");
System.out.println("4. Edit storm");
System.out.println("5. Add a storm");
System.out.println("6. Delete a storm");
System.out.println("7. Exit");
choice = in.nextInt();
in.nextLine();
if (choice==1){
System.out.println("Enter storm name ");
String name = in.nextLine();
dbase.SearchStormName(name);
}
else if(choice==2) {
System.out.println("Enter storm year");
int year = in.nextInt();
dbase.SearchStormYear(year);
}
else if(choice==3) {
dbase.printAll();
}
else if(choice==4) {
dbase.edit();
}
else if(choice==5) {