java
Fix in the program below:
handle incomplete data for text file and allow to search multiple items at once
and let it sort duplicate values
and most importantly let it use get and set methods on the Nodes
New Internal Requirements :
For this assignment, you should replace your Database class with another implementation which
uses instances of the Java Collections java.util.LinkedList class to replace your hand-crafted
LinkedList classes. Note the following:
• LinkedList is a generic type; you must instantiate it with concrete class types. Thus, your
Database object will contain several LinkedList objects; you will need to organize these lists into
another instance of LinkedList. (Consider creating a Year object to help with this.)
• You are still required to maintain your lists in sorted order. The pre-built LinkedList methods
do not directly support relative insertion into a linked list; you will need to find ways to
accomplish this with the tools available to you. (There are at least a couple of ways to do this.)
New function to add:
• A new command should be implemented which allows the user to edit a storm from the main
menu. If selected, the program should prompt the user for the year and storm name to be edited.
If a matching storm is found, the corresponding record should be displayed and the user
prompted for new information to be placed in the record. Users may not change the year or storm
name, but may change any of the other information. If no matching storm is found, no action
should be taken. The user should be informed of the outcome in any case.
this is what the txt file the program is reading from looks like:
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
#######################################Java
Program#######################################################################
###
/*****************************************************************************
***************/
/*This program takes a a file and gives infomation to the user using a LinkedList */
/*****************************************************************************
***************/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
//setting variables to string or int
public class Storm {
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;
}
/*******************************.
javaFix in the program belowhandle incomplete data for text fil.pdf
1. java
Fix in the program below:
handle incomplete data for text file and allow to search multiple items at once
and let it sort duplicate values
and most importantly let it use get and set methods on the Nodes
New Internal Requirements :
For this assignment, you should replace your Database class with another implementation which
uses instances of the Java Collections java.util.LinkedList class to replace your hand-crafted
LinkedList classes. Note the following:
• LinkedList is a generic type; you must instantiate it with concrete class types. Thus, your
Database object will contain several LinkedList objects; you will need to organize these lists into
another instance of LinkedList. (Consider creating a Year object to help with this.)
• You are still required to maintain your lists in sorted order. The pre-built LinkedList methods
do not directly support relative insertion into a linked list; you will need to find ways to
accomplish this with the tools available to you. (There are at least a couple of ways to do this.)
New function to add:
• A new command should be implemented which allows the user to edit a storm from the main
menu. If selected, the program should prompt the user for the year and storm name to be edited.
If a matching storm is found, the corresponding record should be displayed and the user
prompted for new information to be placed in the record. Users may not change the year or storm
name, but may change any of the other information. If no matching storm is found, no action
should be taken. The user should be informed of the outcome in any case.
this is what the txt file the program is reading from looks like:
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
#######################################Java
Program#######################################################################
###
2. /*****************************************************************************
***************/
/*This program takes a a file and gives infomation to the user using a LinkedList */
/*****************************************************************************
***************/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
//setting variables to string or int
public class Storm {
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;
}
3. /**************************************************************/
/*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
*/
4. 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;
}
5. /**************************************************************/
/*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;
6. import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
class Database
{
// node store linked liststorm
private class Node
{
Storm storm;
Node next;
}
// node to store heads
private class HeadNode{
int year;
Node head;
HeadNode next;
}
// storing the liststorm of storms by the year of the storm
private HeadNode liststorm;
int count;
// Constructor
public Database(File fileName) {
liststorm = null;
count = 0;
//Readig the text file
try {
Scanner in = new Scanner(new File("/Users/anasmorsi/Downloads/cs102a2/stormdata.txt"));
while(in.hasNextLine()){
String line = in.nextLine();
7. String[] data = line.split("/");
if(data.length <5 || data.length>5)
System.out.println( line + "Format is incorrect" );
count++;
if( liststorm == null ){
liststorm = new HeadNode();
liststorm.year = Integer.parseInt(data[0]);
liststorm.head = new Node();
liststorm.head.storm = new Storm(data[1], Integer.parseInt(data[0]), data[2],
data[3],(Integer.parseInt(data[4])));
liststorm.head.next = null;
}
else {
int year = Integer.parseInt(data[0]);
if( year < liststorm.year ){
HeadNode temp = new HeadNode();
temp.year = year;
temp.head = new Node();
temp.head.storm = new Storm(data[1], Integer.parseInt(data[0]), data[2],
data[3],(Integer.parseInt(data[4])));
temp.head.next = null;
temp.next = liststorm;
liststorm = temp;
}
else if( year == liststorm.year ){
Node first = liststorm.head;
while( first.next != null ){
first = first.next;
}
Node temp = new Node();
temp.storm = new Storm(data[1], Integer.parseInt(data[0]), data[2],
10. HeadNode temp = liststorm;
while( temp != null ){
Node first = temp.head;
while( first != null ){
if( first.storm.getStormName().equalsIgnoreCase(name) ){
found = true;
System.out.print(first.storm);
break;
}
first = first.next;
}
temp = temp.next;
}
if(!found)
System.out.println("The name you entered was" + name + " was not found ");
}
public void SearchStormYear(int year) {
boolean found = false;
HeadNode temp = liststorm;
while( temp != null ){
if( temp.year == year ){
Node first = temp.head;
while( first != null ){
found = true;
System.out.print(first.storm);
first = first.next;
}
break;
}
temp = temp.next;
}
if(!found)
System.out.println("The year you enter was " + year + " which was not found");
11. }
public void printAll() {
if( liststorm == null)
System.out.println("This data is not available.");
else {
HeadNode temp = liststorm;
while( temp != null ){
Node first = temp.head;
while( first != null ){
System.out.print(first.storm);
first = first.next;
}
temp = temp.next;
}
}
}
private boolean find(int year,String name){
HeadNode temp = liststorm;
while( temp != null ){
Node first = temp.head;
while( first != null ){
if( first.storm.getStormName().equalsIgnoreCase(name) && temp.year == year ){
return true;
}
first = first.next;
}
temp = temp.next;
}
return false;
}
public boolean delete(){
12. Scanner s = new Scanner(System.in);
System.out.print("Enter the name of the Storm :");
String name = s.next();
System.out.print("Enter the year of the Storm :");
int year = s.nextInt();
if( !find(year,name) ){
System.out.println("Storm with given name and year does not exists!");
return false;
}
count--;
HeadNode curr = liststorm;
while( curr != null ){
if( curr.year == year ){
Node first = curr.head;
if( first.storm.getStormName().equalsIgnoreCase(name)){
curr.head = first.next;
return true;
}
Node prev = curr.head;
first = prev.next;
while( first != null ){
if( first.storm.getStormName().equalsIgnoreCase(name)){
Node t = first.next;
prev.next = t;
return true;
}
prev = first;
first = first.next;
}
13. }
curr = curr.next;
}
return true;
}
public boolean insert(){
Scanner s = new Scanner(System.in);
System.out.print("Enter Storm Name:");
String name = s.next();
System.out.print("Enter Storm Year:");
int year = s.nextInt();
if( find(year,name) ){
System.out.println("That exists");
return false;
}
System.out.print("Enter when storm started mmddm :");
String start = s.next();
System.out.print("Enter when storm ended mmdd :");
String end = s.next();
System.out.print("Enter magnitude of the Storm 1-6:");
int magnitude = s.nextInt();
count++;
if( liststorm == null ){
liststorm = new HeadNode();
liststorm.year = year;
liststorm.head = new Node();
liststorm.head.storm = new Storm(name,year,start,end,magnitude);
liststorm.head.next = null;
14. }
else{
if( year < liststorm.year ){
HeadNode temp = new HeadNode();
temp.year = year;
temp.head = new Node();
temp.head.storm = new Storm(name,year,start,end,magnitude);
temp.head.next = null;
temp.next = liststorm;
liststorm = temp;
}
else if( year == liststorm.year ){
Node first = liststorm.head;
while( first.next != null ){
first = first.next;
}
Node temp = new Node();
temp.storm = new Storm(name,year,start,end,magnitude);
temp.next = null;
first.next = temp;
}
else{
HeadNode prev = liststorm;
HeadNode curr = liststorm.next;
while( curr != null ){
if( curr.year == year ){
Node first = liststorm.head;
while( first.next != null ){
first = first.next;
}
Node temp = new Node();
temp.storm = new Storm(name,year,start,end,magnitude);
temp.next = null;
first.next = temp;
16. class Prog2{
public static void main(String args[]) {
final int SearchStormName=1;
final int SearchStormYear=2;
final int Print=3;
final int Close=6;
File file = new File("/Users/anasmorsi/Desktop/cs102a2/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. add a storm");
System.out.println("5. Delete a storm");
System.out.println("6. Exit");
choice = in.nextInt();
in.nextLine();
if (choice==1){
System.out.println("Enter storm name ");
String name = in.nextLine();
dbase.SearchStormName(name);
}
18. //Main method
public static void main(String args[]) {
final int SearchByName = 1;
final int SearchByYear = 2;
final int Print = 3;
final int Insert=4;
final int delete=5;
final int Close = 6;
//File file = new File("/Users/abdelmagidsiddig/Desktop/Tropicalstorms.txt");
File file = new File("Tropicalstorms.txt");
if (!file.exists()) // Check if file is available
System.out.println("Input file does not exist.");
else {
Database dbase = new Database(file);
Scanner in = new Scanner(System.in);
int choice = 0;
System.out.println("Welcome to the CS-102 Storm Tracker Program ");
//Start interactive session
System.out.println("Please choose what you would like to do");
while (true) {
System.out.println("1-Search for storm by name");
System.out.println("2-Search for storm by year");
System.out.println("3-Print out all storms");
System.out.println("4-Insert a storm");
System.out.println("5-Delete a storm");
System.out.println("6-Close menu");
choice = in.nextInt();
in.nextLine();
switch (choice) {
case 1: //Search storm by name
System.out.println("Enter storm name ");
String name = in.nextLine();
dbase.SearchByName(name);
break;
case 2: //Search storm by year
19. System.out.println("Enter storm year: ");
int year = in.nextInt();
dbase.SearchByYear(year);
break;
case 3: //Print all storms
dbase.printAll();
break;
case 4: //Adds a storm
dbase.add();
break;
case 5://Remove a storm
dbase.remove();
break;
case 6: //Exit
in.close();
System.exit(0);
default:
System.out.println("Option not available");
}
System.out.println();
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Database.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
class Database
{
//Variables
// node for linked list
private class Node
20. {
Storm storm;
Node next;
}
// Store the heads of linked lists
private class HeadNode
{
int year; // year
Node head; // to store linked list for this head
HeadNode next;
}
// Stores list of storms by year
private HeadNode list;
int count;
// Constructor
public Database(File fileName) {
list = null;
count = 0;
try {
// Scanner in = new Scanner(new
File("/Users/abdelmagidsiddig/Desktop/Tropicalstorms.txt"));
Scanner in = new Scanner(new File("Tropicalstorms.txt"));
while(in.hasNextLine())
{
String line = in.nextLine();
String[] data = line.split("/");
if(data.length <5 || data.length>5)
System.out.println("Entry is in an incorrect format " + line);
count++;
// Following functions handle the importing of the textfile and the cse in which the data format
could
// be an issue
if( list == null )
{
list = new HeadNode();
list.year = Integer.parseInt(data[0]);
21. list.head = new Node();
list.head.storm = new Storm(data[1], Integer.parseInt(data[0]), data[2],
data[3],(Integer.parseInt(data[4])));
list.head.next = null;
}
else
{
int year = Integer.parseInt(data[0]);
if( year < list.year )
{
HeadNode alt = new HeadNode();
alt.year = year;
alt.head = new Node();
alt.head.storm = new Storm(data[1], Integer.parseInt(data[0]), data[2],
data[3],(Integer.parseInt(data[4])));
alt.head.next = null;
alt.next = list;
list = alt;
}
else if( year == list.year )
{
Node first = list.head;
while( first.next != null )
{
first = first.next;
}
Node alt = new Node();
alt.storm = new Storm(data[1], Integer.parseInt(data[0]), data[2],
data[3],(Integer.parseInt(data[4])));
alt.next = null;
first.next = alt;
}
else
{
HeadNode previous = list;
HeadNode current = list.next;
22. while( current != null )
{
if( current.year == year )
{
Node first = list.head;
while( first.next != null )
{
first = first.next;
}
Node alt = new Node();
alt.storm = new Storm(data[1], Integer.parseInt(data[0]), data[2],
data[3],(Integer.parseInt(data[4])));
alt.next = null;
first.next = alt;
break;
}
else if( current.year > year )
{
HeadNode alt = new HeadNode();
alt.year = year;
alt.head = new Node();
alt.head.storm = new Storm(data[1], Integer.parseInt(data[0]), data[2],
data[3],(Integer.parseInt(data[4])));
alt.head.next = null;
alt.next = current;
previous.next = alt;
break;
}
previous = current;
current = current.next;
}
if( current == null )
{
current = list;
while( current.next != null )
23. {
current = current.next;
}
HeadNode alt = new HeadNode();
alt.year = year;
alt.head = new Node();
alt.head.storm = new Storm(data[1], Integer.parseInt(data[0]), data[2],
data[3],(Integer.parseInt(data[4])));
alt.head.next = null;
current.next = alt;
}
}
}
}
} catch (FileNotFoundException F) {
System.out.println("File not found");
}
catch(InputMismatchException e) {
System.out.print("Input was not found");
}
}
/*************************************************/
/*Method:SearchByName */
/*Purpose: search through the array for */
/* the name entered */
/*Parameters:String name */
/*Return: N/A */
/*************************************************/
public void SearchByName(String name)
{
boolean found = false;
HeadNode alt = list;
24. while( alt != null )
{
Node first = alt.head;
while( first != null )
{
if( first.storm.getNameOfStorm().equalsIgnoreCase(name) )
{
found = true;
System.out.print(first.storm);
break;
}
first = first.next;
}
alt = alt.next;
}
if(!found)
System.out.println( name + " was not found in the database ");
}
/*************************************************/
/*Method:SearchByYear */
/*Purpose: search through the array for */
/* the year entered */
/*Parameters:int year */
/*Return: N/A */
/*************************************************/
public void SearchByYear(int year)
{
boolean found = false;
HeadNode alt = list;
while( alt != null )
{
if( alt.year == year )
{
Node first = alt.head;
while( first != null )
{
25. found = true;
System.out.print(first.storm);
first = first.next;
}
break;
}
alt = alt.next;
}
if(!found)
System.out.println("Storm " + year + " was not found");
}
/*************************************************/
/*Method:printAll */
/*Purpose: Print the array of storms */
/*Parameters:N/A */
/*Return: N/A */
/*************************************************/
public void printAll()
{
if( list == null)
System.out.println("No data available.");
else {
HeadNode alt = list;
while( alt != null )
{
Node first = alt.head;
while( first != null )
{
System.out.print(first.storm);
first = first.next;
}
alt = alt.next;
}
}
}
/*************************************************/
26. /*Method:Find */
/*Purpose: Checks if the storm is available */
/* to avoid duplicate entries */
/*Parameters:Head node alt */
/*Return: Boolean */
/*************************************************/
private boolean find(int year,String name)
{
HeadNode alt = list;
while( alt != null )
{
Node first = alt.head;
while( first != null )
{
if( first.storm.getNameOfStorm().equalsIgnoreCase(name) && alt.year == year )
{
return true;
}
first = first.next;
}
alt = alt.next;
}
return false;
}
/*************************************************/
/*Method:Remove */
/*Purpose: Removes the storm entered */
/*Parameters: N/A */
/*Return: Boolean */
/*************************************************/
public boolean remove()
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter name of the Storm :");
String name = scan.next();
System.out.print("Enter year of the Storm :");
27. int year = scan.nextInt();
if( !find(year,name) )
{
System.out.println("Storm with given name and year does not exists!");
return false;
}
count--;
HeadNode current = list;
while( current != null )
{
if( current.year == year )
{
Node first = current.head;
if( first.storm.getNameOfStorm().equalsIgnoreCase(name))
{
current.head = first.next;
return true;
}
Node previous = current.head;
first = previous.next;
while( first != null )
{
if( first.storm.getNameOfStorm().equalsIgnoreCase(name))
{
Node t = first.next;
previous.next = t;
return true;
}
previous = first;
first = first.next;
}
}
current = current.next;
System.out.println( "Storm " + name + " has been deleted");
}
return true;
28. }
/*************************************************/
/*Method:Add */
/*Purpose: Adds the storm entered */
/*Parameters: N/A */
/*Return: Boolean */
/*************************************************/
public boolean add ()
{
Scanner s = new Scanner(System.in);
System.out.print("Enter the name of the Storm :");
String name = s.next();
System.out.print("Enter the year of the Storm :");
int year = s.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 (mmdd):");
String start = s.next();
System.out.print("Enter the end of the Storm (mmdd) :");
String end = s.next();
System.out.print("Enter the strength of the Storm (1-6):");
int strength = s.nextInt();
count++;
//The functions below ensure the newly added storm is placed in the right place to keep the list
sorted.
if( list == null )
{
list = new HeadNode();
list.year = year;
list.head = new Node();
list.head.storm = new Storm(name,year,start,end,strength);
list.head.next = null;
}
29. else
{
if( year < list.year )
{
HeadNode alt = new HeadNode();
alt.year = year;
alt.head = new Node();
alt.head.storm = new Storm(name,year,start,end,strength);
alt.head.next = null;
alt.next = list;
list = alt;
}
else if( year == list.year )
{
Node first = list.head;
while( first.next != null )
{
first = first.next;
}
Node alt = new Node();
alt.storm = new Storm(name,year,start,end,strength);
alt.next = null;
first.next = alt;
}
else
{
HeadNode previous = list;
HeadNode current = list.next;
while( current != null )
{
if( current.year == year )
{
Node first = list.head;
while( first.next != null )
{
30. first = first.next;
}
Node alt = new Node();
alt.storm = new Storm(name,year,start,end,strength);
alt.next = null;
first.next = alt;
break;
}
else if( current.year > year )
{
HeadNode alt = new HeadNode();
alt.year = year;
alt.head = new Node();
alt.head.storm = new Storm(name,year,start,end,strength);
alt.head.next = null;
alt.next = current;
previous.next = alt;
break;
}
previous = current;
current = current.next;
}
if( current == null )
{
current = list;
while( current.next != null )
{
current = current.next;
}
HeadNode alt = new HeadNode();
alt.year = year;
alt.head = new Node();
alt.head.storm = new Storm(name,year,start,end,strength);
alt.head.next = null;
current.next = alt;
}
31. }
}
return true;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
//Storm.java
public class Storm {
//Variables
private String NameOfStorm, StartOfStorm, EndOfStorm;
private int YearOfStorm, StrengthOfStorm;
//Storm Constructor
public Storm(String NameOfStorm, int YearOfStorm, String StartOfStorm, String EndOfStorm,
int StrengthOfStorm) {
this.NameOfStorm = NameOfStorm;
this.YearOfStorm = YearOfStorm;
this.StartOfStorm = StartOfStorm;
this.EndOfStorm = EndOfStorm;
this.StrengthOfStorm = StrengthOfStorm;
}
/*************************************************/
/*Method:Get functions */
/*Purpose: Retrieve value of parameters required */
/*Parameters:NameOfStorm,YearOfStorm,StartOfStorm*/
/* EndOfStorm, StrengthOfStorm */
/*Return:NameOfStorm,YearOfStorm,StartOfStorm */
/* EndOfStorm, StrengthOfStorm */
/*************************************************/
public String getNameOfStorm() {
return NameOfStorm;
}
public int getNameOfYear() {
return YearOfStorm;
}
public String getStartOfStorm() {
32. return StartOfStorm;
}
public String getEndOfStorm() {
return EndOfStorm;
}
public int getStrengthOfStorm() {
return StrengthOfStorm;
}
/*************************************************/
/*Method:Set functions */
/*Purpose: set value of parameters of a class */
/*Parameters:NameOfStorm,YearOfStorm,StartOfStorm*/
/* EndOfStorm, StrengthOfStorm */
/*Return: N/A */
/*************************************************/
public void setNameOfStorm(String NameOfStorm) {
this.NameOfStorm = NameOfStorm;
}
//Set method for storm year
public void setNameOfYear(int YearOfStorm) {
this.YearOfStorm = YearOfStorm;
}
//Set method for starting month of storm
public void setStartOfStorm(String StartOfStorm) {
this.StartOfStorm = StartOfStorm;
}
//Set method for ending month of storm
public void setEndOfStorm(String EndOfStorm) {
this.EndOfStorm = EndOfStorm;
}
//Set method for Stength of storm
public void setStrengthOfStorm(int StrengthOfStorm) {
this.StrengthOfStorm = StrengthOfStorm;
}
/*************************************************/
/*Method:ToString */
33. /*Purpose: set value of parameters of a class */
/*Parameters:NameOfStorm,YearOfStorm,StartOfStorm*/
/* EndOfStorm, StrengthOfStorm */
/*Return: N/A */
/*************************************************/
// toString method returning the data as a String
public String toString() {
return " " + getNameOfYear() + ":" + getNameOfStorm() + "-" +
((getStrengthOfStorm() == -1) ? "(N/A)" : ((getStrengthOfStorm() == 0) ? "(tropical storm)" :
"(hurricane level " + getStrengthOfStorm() + ")")) + "- " +
((getStartOfStorm().equals("")) ? "(no start)" : getStartOfStorm().substring(0, 2) + "/" +
getStartOfStorm().substring(2)) +
" - " + ((getEndOfStorm().equals("")) ? "(no end)" : getEndOfStorm().substring(0, 2) + "/"
+ getEndOfStorm().substring(2));
}
}