SlideShare a Scribd company logo
1 of 14
Download to read offline
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 stormMag the stormMag to set
*/
public void setStormMag(int stormMag) {
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;
}
}
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) {
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");
}
}
//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));
}
}
//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;
}
}
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));
}
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();
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) + " : ");
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())
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) {
dbase.add();
}
else if(choice==6) {
dbase.delete();
}
else if(choice==7) { //Exit
in.close();
System.exit(0);
}
else
System.out.println("Not available");
}
}
}
}
Solution

More Related Content

Similar to JavaI have the full code complete i just need it to be replace th.pdf

public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
arjuncp10
 
[10] Write a Java application which first reads data from the phoneb.pdf
[10] Write a Java application which first reads data from the phoneb.pdf[10] Write a Java application which first reads data from the phoneb.pdf
[10] Write a Java application which first reads data from the phoneb.pdf
archiespink
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
ravikapoorindia
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdf
fashioncollection2
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
in c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfin c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdf
stopgolook
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
Codecamp Romania
 
Applying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data GridApplying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data Grid
Hazelcast
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
arishmarketing21
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdf
sharnapiyush773
 
package length; A Length is an object that has a length and .pdf
package length; A Length is an object that has a length and .pdfpackage length; A Length is an object that has a length and .pdf
package length; A Length is an object that has a length and .pdf
anupamselection
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
JUSTSTYLISH3B2MOHALI
 
Keep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdfKeep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdf
AroraRajinder1
 

Similar to JavaI have the full code complete i just need it to be replace th.pdf (20)

public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
 
[10] Write a Java application which first reads data from the phoneb.pdf
[10] Write a Java application which first reads data from the phoneb.pdf[10] Write a Java application which first reads data from the phoneb.pdf
[10] Write a Java application which first reads data from the phoneb.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
FNT 2015 PDIS CodeEU - Zanimljiva informatika - 02 Djordje Pavlovic - Live_ch...
FNT 2015 PDIS CodeEU - Zanimljiva informatika - 02 Djordje Pavlovic - Live_ch...FNT 2015 PDIS CodeEU - Zanimljiva informatika - 02 Djordje Pavlovic - Live_ch...
FNT 2015 PDIS CodeEU - Zanimljiva informatika - 02 Djordje Pavlovic - Live_ch...
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdf
 
Write a program that reads a graph from a file and determines whether.docx
 Write a program that reads a graph from a file and determines whether.docx Write a program that reads a graph from a file and determines whether.docx
Write a program that reads a graph from a file and determines whether.docx
 
130717666736980000
130717666736980000130717666736980000
130717666736980000
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
in c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfin c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdf
 
WOTC_Import
WOTC_ImportWOTC_Import
WOTC_Import
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Applying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data GridApplying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data Grid
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdf
 
package length; A Length is an object that has a length and .pdf
package length; A Length is an object that has a length and .pdfpackage length; A Length is an object that has a length and .pdf
package length; A Length is an object that has a length and .pdf
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
Keep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdfKeep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdf
 

More from jeeteshmalani1

How can you define the traits below and what are your thoughts on th.pdf
How can you define the traits below and what are your thoughts on th.pdfHow can you define the traits below and what are your thoughts on th.pdf
How can you define the traits below and what are your thoughts on th.pdf
jeeteshmalani1
 
Can someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdfCan someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdf
jeeteshmalani1
 
atify and describe the cult alue dimensions that help ural profile of.pdf
atify and describe the cult alue dimensions that help ural profile of.pdfatify and describe the cult alue dimensions that help ural profile of.pdf
atify and describe the cult alue dimensions that help ural profile of.pdf
jeeteshmalani1
 
Write a two- to three- page paper responding to the questions at the.pdf
Write a two- to three- page paper responding to the questions at the.pdfWrite a two- to three- page paper responding to the questions at the.pdf
Write a two- to three- page paper responding to the questions at the.pdf
jeeteshmalani1
 
Which of the following was true about the Great Depression in th.pdf
Which of the following was true about the Great Depression in th.pdfWhich of the following was true about the Great Depression in th.pdf
Which of the following was true about the Great Depression in th.pdf
jeeteshmalani1
 
What are the major concerns for corporations in developing and re.pdf
What are the major concerns for corporations in developing and re.pdfWhat are the major concerns for corporations in developing and re.pdf
What are the major concerns for corporations in developing and re.pdf
jeeteshmalani1
 
What basic auditing policy logs attempts to authenticate a user thro.pdf
What basic auditing policy logs attempts to authenticate a user thro.pdfWhat basic auditing policy logs attempts to authenticate a user thro.pdf
What basic auditing policy logs attempts to authenticate a user thro.pdf
jeeteshmalani1
 
What is a warrant in Toulmins model of a syllogismA) A legal do.pdf
What is a warrant in Toulmins model of a syllogismA) A legal do.pdfWhat is a warrant in Toulmins model of a syllogismA) A legal do.pdf
What is a warrant in Toulmins model of a syllogismA) A legal do.pdf
jeeteshmalani1
 
What are the main methods anthropologists use Give an example of ho.pdf
What are the main methods anthropologists use Give an example of ho.pdfWhat are the main methods anthropologists use Give an example of ho.pdf
What are the main methods anthropologists use Give an example of ho.pdf
jeeteshmalani1
 
The polarization of the CMB detected in the WMAP data is evidence fo.pdf
The polarization of the CMB detected in the WMAP data is evidence fo.pdfThe polarization of the CMB detected in the WMAP data is evidence fo.pdf
The polarization of the CMB detected in the WMAP data is evidence fo.pdf
jeeteshmalani1
 

More from jeeteshmalani1 (20)

How can you define the traits below and what are your thoughts on th.pdf
How can you define the traits below and what are your thoughts on th.pdfHow can you define the traits below and what are your thoughts on th.pdf
How can you define the traits below and what are your thoughts on th.pdf
 
frank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdf
frank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdffrank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdf
frank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdf
 
Does law provide liberty What is law How does law tend to be perve.pdf
Does law provide liberty What is law How does law tend to be perve.pdfDoes law provide liberty What is law How does law tend to be perve.pdf
Does law provide liberty What is law How does law tend to be perve.pdf
 
Consider two n times n matrices C and D that commute under matrix mul.pdf
Consider two n times n matrices C and D that commute under matrix mul.pdfConsider two n times n matrices C and D that commute under matrix mul.pdf
Consider two n times n matrices C and D that commute under matrix mul.pdf
 
Can someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdfCan someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdf
 
atify and describe the cult alue dimensions that help ural profile of.pdf
atify and describe the cult alue dimensions that help ural profile of.pdfatify and describe the cult alue dimensions that help ural profile of.pdf
atify and describe the cult alue dimensions that help ural profile of.pdf
 
21. Assume that mutations in the transformer (tra) and the male- spec.pdf
21. Assume that mutations in the transformer (tra) and the male- spec.pdf21. Assume that mutations in the transformer (tra) and the male- spec.pdf
21. Assume that mutations in the transformer (tra) and the male- spec.pdf
 
Write one Conditional Signal Assignment VHDL code statement in the b.pdf
Write one Conditional Signal Assignment VHDL code statement in the b.pdfWrite one Conditional Signal Assignment VHDL code statement in the b.pdf
Write one Conditional Signal Assignment VHDL code statement in the b.pdf
 
Write a two- to three- page paper responding to the questions at the.pdf
Write a two- to three- page paper responding to the questions at the.pdfWrite a two- to three- page paper responding to the questions at the.pdf
Write a two- to three- page paper responding to the questions at the.pdf
 
1. Match the following. DOE is pursuing the demonstration of one suc.pdf
1. Match the following. DOE is pursuing the demonstration of one suc.pdf1. Match the following. DOE is pursuing the demonstration of one suc.pdf
1. Match the following. DOE is pursuing the demonstration of one suc.pdf
 
Which of the following involve an increase in the entropy of the sys.pdf
Which of the following involve an increase in the entropy of the sys.pdfWhich of the following involve an increase in the entropy of the sys.pdf
Which of the following involve an increase in the entropy of the sys.pdf
 
Which of the following was true about the Great Depression in th.pdf
Which of the following was true about the Great Depression in th.pdfWhich of the following was true about the Great Depression in th.pdf
Which of the following was true about the Great Depression in th.pdf
 
What are the major concerns for corporations in developing and re.pdf
What are the major concerns for corporations in developing and re.pdfWhat are the major concerns for corporations in developing and re.pdf
What are the major concerns for corporations in developing and re.pdf
 
Which factors might account for the specificity of certain viruses f.pdf
Which factors might account for the specificity of certain viruses f.pdfWhich factors might account for the specificity of certain viruses f.pdf
Which factors might account for the specificity of certain viruses f.pdf
 
What basic auditing policy logs attempts to authenticate a user thro.pdf
What basic auditing policy logs attempts to authenticate a user thro.pdfWhat basic auditing policy logs attempts to authenticate a user thro.pdf
What basic auditing policy logs attempts to authenticate a user thro.pdf
 
What is a warrant in Toulmins model of a syllogismA) A legal do.pdf
What is a warrant in Toulmins model of a syllogismA) A legal do.pdfWhat is a warrant in Toulmins model of a syllogismA) A legal do.pdf
What is a warrant in Toulmins model of a syllogismA) A legal do.pdf
 
What are the main methods anthropologists use Give an example of ho.pdf
What are the main methods anthropologists use Give an example of ho.pdfWhat are the main methods anthropologists use Give an example of ho.pdf
What are the main methods anthropologists use Give an example of ho.pdf
 
Arrange the following parts and processes of eukaryotic gene expressi.pdf
Arrange the following parts and processes of eukaryotic gene expressi.pdfArrange the following parts and processes of eukaryotic gene expressi.pdf
Arrange the following parts and processes of eukaryotic gene expressi.pdf
 
The polarization of the CMB detected in the WMAP data is evidence fo.pdf
The polarization of the CMB detected in the WMAP data is evidence fo.pdfThe polarization of the CMB detected in the WMAP data is evidence fo.pdf
The polarization of the CMB detected in the WMAP data is evidence fo.pdf
 
Technical Performance Measures are quantitative measures that must be.pdf
Technical Performance Measures are quantitative measures that must be.pdfTechnical Performance Measures are quantitative measures that must be.pdf
Technical Performance Measures are quantitative measures that must be.pdf
 

Recently uploaded

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 

Recently uploaded (20)

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
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) {
  • 14. dbase.add(); } else if(choice==6) { dbase.delete(); } else if(choice==7) { //Exit in.close(); System.exit(0); } else System.out.println("Not available"); } } } } Solution