SlideShare a Scribd company logo
1 of 33
Download to read offline
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;
}
/**************************************************************/
/*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;
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();
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],
data[3],(Integer.parseInt(data[4])));
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(data[1], Integer.parseInt(data[0]), data[2],
data[3],(Integer.parseInt(data[4])));
temp.next = null;
first.next = temp;
break;
}
else if( curr.year > 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 = curr;
prev.next = temp;
break;
}
prev = curr;
curr = curr.next;
}
if( curr == null ){
curr = liststorm;
while( curr.next != null ){
curr = curr.next;
}
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;
curr.next = temp;
}
}
}
}
}
catch (FileNotFoundException F) {
System.out.println("Can not find file");
}
catch(InputMismatchException e) {
System.out.print("Inputnot found");
}
}
public void SearchStormName(String name) {
boolean found = false;
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");
}
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(){
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;
}
}
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;
}
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;
break;
}
else if( curr.year > 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 = curr;
prev.next = temp;
break;
}
prev = curr;
curr = curr.next;
}
if( curr == null ){
curr = liststorm;
while( curr.next != null ){
curr = curr.next;
}
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;
curr.next = temp;
}
}
}
return true;
}
}
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 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);
}
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.insert();
}
else if(choice==5) {
dbase.delete();
}
else if(choice==6) { //Exit
in.close();
System.exit(0);
}
else
System.out.println("Not available");
}
}
}
}
Solution
//Prog2.java
import java.io.File;
import java.util.Scanner;
public class Prog2 {
//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
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
{
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]);
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;
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 )
{
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;
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 )
{
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;
}
}
}
/*************************************************/
/*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 :");
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;
}
/*************************************************/
/*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;
}
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 )
{
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;
}
}
}
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() {
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 */
/*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));
}
}

More Related Content

Similar to javaFix in the program belowhandle incomplete data for text fil.pdf

Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartGabriele Lana
 
the next web now
the next web nowthe next web now
the next web nowzulin Gu
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
 
JQuery Presentation
JQuery PresentationJQuery Presentation
JQuery PresentationSony Jain
 
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.pdfAroraRajinder1
 
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...DEEPANSHU GUPTA
 
Csmr2012 bettenburg presentation
Csmr2012 bettenburg presentationCsmr2012 bettenburg presentation
Csmr2012 bettenburg presentationSAIL_QU
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxcgraciela1
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfmallik3000
 
Codestrong 2012 breakout session hacking titanium
Codestrong 2012 breakout session   hacking titaniumCodestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session hacking titaniumAxway Appcelerator
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
Building High Performance Web Applications and Sites
Building High Performance Web Applications and SitesBuilding High Performance Web Applications and Sites
Building High Performance Web Applications and Sitesgoodfriday
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Tsuyoshi Yamamoto
 

Similar to javaFix in the program belowhandle incomplete data for text fil.pdf (20)

srgoc
srgocsrgoc
srgoc
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
 
the next web now
the next web nowthe next web now
the next web now
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
JQuery Presentation
JQuery PresentationJQuery Presentation
JQuery Presentation
 
Sequelize
SequelizeSequelize
Sequelize
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
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
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
 
Csmr2012 bettenburg presentation
Csmr2012 bettenburg presentationCsmr2012 bettenburg presentation
Csmr2012 bettenburg presentation
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
 
Codestrong 2012 breakout session hacking titanium
Codestrong 2012 breakout session   hacking titaniumCodestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session hacking titanium
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
Building High Performance Web Applications and Sites
Building High Performance Web Applications and SitesBuilding High Performance Web Applications and Sites
Building High Performance Web Applications and Sites
 
IT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notesIT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notes
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 

More from birajdar2

public static ArrayListInteger doArrayListSearchSmallest(int nu.pdf
public static ArrayListInteger doArrayListSearchSmallest(int nu.pdfpublic static ArrayListInteger doArrayListSearchSmallest(int nu.pdf
public static ArrayListInteger doArrayListSearchSmallest(int nu.pdfbirajdar2
 
Project selection methods and the project portfolio play an importan.pdf
Project selection methods and the project portfolio play an importan.pdfProject selection methods and the project portfolio play an importan.pdf
Project selection methods and the project portfolio play an importan.pdfbirajdar2
 
James can row 14 km downstream in a river in 2 hours. He takes 7 hou.pdf
James can row 14 km downstream in a river in 2 hours. He takes 7 hou.pdfJames can row 14 km downstream in a river in 2 hours. He takes 7 hou.pdf
James can row 14 km downstream in a river in 2 hours. He takes 7 hou.pdfbirajdar2
 
In the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdfIn the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdfbirajdar2
 
How do hydrophobic and hydrophilic hormones differ in their speeds a.pdf
How do hydrophobic and hydrophilic hormones differ in their speeds a.pdfHow do hydrophobic and hydrophilic hormones differ in their speeds a.pdf
How do hydrophobic and hydrophilic hormones differ in their speeds a.pdfbirajdar2
 
Given below is an issue that you have identified as an issue in a ret.pdf
Given below is an issue that you have identified as an issue in a ret.pdfGiven below is an issue that you have identified as an issue in a ret.pdf
Given below is an issue that you have identified as an issue in a ret.pdfbirajdar2
 
Explain Aquinas 5 proofs of God, being sure to identify the Aris.pdf
Explain Aquinas 5 proofs of God, being sure to identify the Aris.pdfExplain Aquinas 5 proofs of God, being sure to identify the Aris.pdf
Explain Aquinas 5 proofs of God, being sure to identify the Aris.pdfbirajdar2
 
Exercise 7. Show that if C(0) (the punctured plane) and U C are conf.pdf
Exercise 7. Show that if C(0) (the punctured plane) and U C are conf.pdfExercise 7. Show that if C(0) (the punctured plane) and U C are conf.pdf
Exercise 7. Show that if C(0) (the punctured plane) and U C are conf.pdfbirajdar2
 
Consider the following segment table What are the physical addresse.pdf
Consider the following segment table  What are the physical addresse.pdfConsider the following segment table  What are the physical addresse.pdf
Consider the following segment table What are the physical addresse.pdfbirajdar2
 
Can you explain the movement of ions and ion channel activity during.pdf
Can you explain the movement of ions and ion channel activity during.pdfCan you explain the movement of ions and ion channel activity during.pdf
Can you explain the movement of ions and ion channel activity during.pdfbirajdar2
 
Calculate the implied stock price assuming an EBITDA multiple of 11..pdf
Calculate the implied stock price assuming an EBITDA multiple of 11..pdfCalculate the implied stock price assuming an EBITDA multiple of 11..pdf
Calculate the implied stock price assuming an EBITDA multiple of 11..pdfbirajdar2
 
Below is the graph of a polynomial function f with real coefficients.pdf
Below is the graph of a polynomial function f with real coefficients.pdfBelow is the graph of a polynomial function f with real coefficients.pdf
Below is the graph of a polynomial function f with real coefficients.pdfbirajdar2
 
Are higher than average sea surface temperatures associated with a g.pdf
Are higher than average sea surface temperatures associated with a g.pdfAre higher than average sea surface temperatures associated with a g.pdf
Are higher than average sea surface temperatures associated with a g.pdfbirajdar2
 
A table of values of an increasing function F is shown. Use the table.pdf
A table of values of an increasing function F is shown. Use the table.pdfA table of values of an increasing function F is shown. Use the table.pdf
A table of values of an increasing function F is shown. Use the table.pdfbirajdar2
 
A polygenic trait is determined by a single gene with many different.pdf
A polygenic trait is determined by a single gene with many different.pdfA polygenic trait is determined by a single gene with many different.pdf
A polygenic trait is determined by a single gene with many different.pdfbirajdar2
 
4. Phil is conducting a seed germination experiment. He places 3 gro.pdf
4. Phil is conducting a seed germination experiment. He places 3 gro.pdf4. Phil is conducting a seed germination experiment. He places 3 gro.pdf
4. Phil is conducting a seed germination experiment. He places 3 gro.pdfbirajdar2
 
21. What is the relationship between the maximum size of aggregates a.pdf
21. What is the relationship between the maximum size of aggregates a.pdf21. What is the relationship between the maximum size of aggregates a.pdf
21. What is the relationship between the maximum size of aggregates a.pdfbirajdar2
 
Which of the following are organizer molecules in the avian PMZ is a.pdf
Which of the following are organizer molecules in the avian PMZ is a.pdfWhich of the following are organizer molecules in the avian PMZ is a.pdf
Which of the following are organizer molecules in the avian PMZ is a.pdfbirajdar2
 
What are the five stages of team development Describe each stage an.pdf
What are the five stages of team development Describe each stage an.pdfWhat are the five stages of team development Describe each stage an.pdf
What are the five stages of team development Describe each stage an.pdfbirajdar2
 
What kinds of molecules can be used as metabolic fuel to produce ATP.pdf
What kinds of molecules can be used as metabolic fuel to produce ATP.pdfWhat kinds of molecules can be used as metabolic fuel to produce ATP.pdf
What kinds of molecules can be used as metabolic fuel to produce ATP.pdfbirajdar2
 

More from birajdar2 (20)

public static ArrayListInteger doArrayListSearchSmallest(int nu.pdf
public static ArrayListInteger doArrayListSearchSmallest(int nu.pdfpublic static ArrayListInteger doArrayListSearchSmallest(int nu.pdf
public static ArrayListInteger doArrayListSearchSmallest(int nu.pdf
 
Project selection methods and the project portfolio play an importan.pdf
Project selection methods and the project portfolio play an importan.pdfProject selection methods and the project portfolio play an importan.pdf
Project selection methods and the project portfolio play an importan.pdf
 
James can row 14 km downstream in a river in 2 hours. He takes 7 hou.pdf
James can row 14 km downstream in a river in 2 hours. He takes 7 hou.pdfJames can row 14 km downstream in a river in 2 hours. He takes 7 hou.pdf
James can row 14 km downstream in a river in 2 hours. He takes 7 hou.pdf
 
In the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdfIn the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdf
 
How do hydrophobic and hydrophilic hormones differ in their speeds a.pdf
How do hydrophobic and hydrophilic hormones differ in their speeds a.pdfHow do hydrophobic and hydrophilic hormones differ in their speeds a.pdf
How do hydrophobic and hydrophilic hormones differ in their speeds a.pdf
 
Given below is an issue that you have identified as an issue in a ret.pdf
Given below is an issue that you have identified as an issue in a ret.pdfGiven below is an issue that you have identified as an issue in a ret.pdf
Given below is an issue that you have identified as an issue in a ret.pdf
 
Explain Aquinas 5 proofs of God, being sure to identify the Aris.pdf
Explain Aquinas 5 proofs of God, being sure to identify the Aris.pdfExplain Aquinas 5 proofs of God, being sure to identify the Aris.pdf
Explain Aquinas 5 proofs of God, being sure to identify the Aris.pdf
 
Exercise 7. Show that if C(0) (the punctured plane) and U C are conf.pdf
Exercise 7. Show that if C(0) (the punctured plane) and U C are conf.pdfExercise 7. Show that if C(0) (the punctured plane) and U C are conf.pdf
Exercise 7. Show that if C(0) (the punctured plane) and U C are conf.pdf
 
Consider the following segment table What are the physical addresse.pdf
Consider the following segment table  What are the physical addresse.pdfConsider the following segment table  What are the physical addresse.pdf
Consider the following segment table What are the physical addresse.pdf
 
Can you explain the movement of ions and ion channel activity during.pdf
Can you explain the movement of ions and ion channel activity during.pdfCan you explain the movement of ions and ion channel activity during.pdf
Can you explain the movement of ions and ion channel activity during.pdf
 
Calculate the implied stock price assuming an EBITDA multiple of 11..pdf
Calculate the implied stock price assuming an EBITDA multiple of 11..pdfCalculate the implied stock price assuming an EBITDA multiple of 11..pdf
Calculate the implied stock price assuming an EBITDA multiple of 11..pdf
 
Below is the graph of a polynomial function f with real coefficients.pdf
Below is the graph of a polynomial function f with real coefficients.pdfBelow is the graph of a polynomial function f with real coefficients.pdf
Below is the graph of a polynomial function f with real coefficients.pdf
 
Are higher than average sea surface temperatures associated with a g.pdf
Are higher than average sea surface temperatures associated with a g.pdfAre higher than average sea surface temperatures associated with a g.pdf
Are higher than average sea surface temperatures associated with a g.pdf
 
A table of values of an increasing function F is shown. Use the table.pdf
A table of values of an increasing function F is shown. Use the table.pdfA table of values of an increasing function F is shown. Use the table.pdf
A table of values of an increasing function F is shown. Use the table.pdf
 
A polygenic trait is determined by a single gene with many different.pdf
A polygenic trait is determined by a single gene with many different.pdfA polygenic trait is determined by a single gene with many different.pdf
A polygenic trait is determined by a single gene with many different.pdf
 
4. Phil is conducting a seed germination experiment. He places 3 gro.pdf
4. Phil is conducting a seed germination experiment. He places 3 gro.pdf4. Phil is conducting a seed germination experiment. He places 3 gro.pdf
4. Phil is conducting a seed germination experiment. He places 3 gro.pdf
 
21. What is the relationship between the maximum size of aggregates a.pdf
21. What is the relationship between the maximum size of aggregates a.pdf21. What is the relationship between the maximum size of aggregates a.pdf
21. What is the relationship between the maximum size of aggregates a.pdf
 
Which of the following are organizer molecules in the avian PMZ is a.pdf
Which of the following are organizer molecules in the avian PMZ is a.pdfWhich of the following are organizer molecules in the avian PMZ is a.pdf
Which of the following are organizer molecules in the avian PMZ is a.pdf
 
What are the five stages of team development Describe each stage an.pdf
What are the five stages of team development Describe each stage an.pdfWhat are the five stages of team development Describe each stage an.pdf
What are the five stages of team development Describe each stage an.pdf
 
What kinds of molecules can be used as metabolic fuel to produce ATP.pdf
What kinds of molecules can be used as metabolic fuel to produce ATP.pdfWhat kinds of molecules can be used as metabolic fuel to produce ATP.pdf
What kinds of molecules can be used as metabolic fuel to produce ATP.pdf
 

Recently uploaded

Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

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],
  • 8. data[3],(Integer.parseInt(data[4]))); 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(data[1], Integer.parseInt(data[0]), data[2], data[3],(Integer.parseInt(data[4]))); temp.next = null; first.next = temp; break; } else if( curr.year > 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 = curr; prev.next = temp; break; }
  • 9. prev = curr; curr = curr.next; } if( curr == null ){ curr = liststorm; while( curr.next != null ){ curr = curr.next; } 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; curr.next = temp; } } } } } catch (FileNotFoundException F) { System.out.println("Can not find file"); } catch(InputMismatchException e) { System.out.print("Inputnot found"); } } public void SearchStormName(String name) { boolean found = false;
  • 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;
  • 15. break; } else if( curr.year > 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 = curr; prev.next = temp; break; } prev = curr; curr = curr.next; } if( curr == null ){ curr = liststorm; while( curr.next != null ){ curr = curr.next; } 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; curr.next = temp; } } } return true; } } import java.io.File; import java.util.Scanner;
  • 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); }
  • 17. 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.insert(); } else if(choice==5) { dbase.delete(); } else if(choice==6) { //Exit in.close(); System.exit(0); } else System.out.println("Not available"); } } } } Solution //Prog2.java import java.io.File; import java.util.Scanner; public class Prog2 {
  • 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)); } }