SlideShare a Scribd company logo
public class Storm {
//Attributes
private String stormName;
private int stormYear;
private String stormStart;
private String stormEnd;
private int stormMag;
/**
* Constructor
*
* @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;
}
/**
* @return the stormName
*/
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;
}
@Override
public String toString() {
return " " + getStormYear() + ": " + getStormName() + " " +
((getStormMag() == -1) ? "(no info)" :
((getStormMag() == 0) ? "(tropical storm)" : "(hurricane level " +
getStormMag() + ")")) + ": " +
((getStormStart().equals("")) ? "(no start)" : getStormStart().substring(0, 2) + "/"
+ getStormStart().substring(2)) +
" - " +
((getStormEnd().equals("")) ? "(no end)" : getStormEnd().substring(0, 2) + "/" +
getStormEnd().substring(2));
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Database {
private static final int MAX_SIZE = 50;
//Attributes
private Storm[] stormArr;
private int count;
/**
* Constructor
* Accepts a file and attempts to read it
* Fills the storm array with the data
*/
public Database(File fileName) {
//Initialize array
this.stormArr = new Storm[MAX_SIZE];
this.count = 0;
//Scanner to read from the file
Scanner in = null;
try {
in = new Scanner(fileName);
//Read data from the file
while(in.hasNextLine()) {
//Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude
of storm
String line = in.nextLine();
String[] data = line.replaceAll("/", "/ ").split("/");
if(data.length < 5)
System.out.println("Database entry not in the correct format: " + line);
//Add data to array
this.stormArr[this.count] = new Storm(data[1].trim(), Integer.parseInt(data[0].trim()),
data[2].trim(), data[3].trim(),
(data[4].trim().equals("")) ? -1 : Integer.parseInt(data[4].trim()));
this.count += 1;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
//Close scanner
if(in == null)
in.close();
}
}
/**
* Returns a storm array which matches the name
*
* @param name
*/
public void getStormsByName(String name) {
boolean found = false;
for (Storm storm : stormArr) {
if((storm != null ) && (storm.getStormName().equalsIgnoreCase(name))) {
found = true;
System.out.print(storm);
}
}
if(!found)
System.out.println("Could not find any storm named "" + name + "".");
}
/**
* Returns a storm array which matches the year
*
* @param year
*/
public void getStormsByYear(int year) {
boolean found = false;
for (Storm storm : stormArr) {
if((storm != null ) && (storm.getStormYear() == year)) {
found = true;
System.out.print(storm);
}
}
if(!found)
System.out.println("Could not find any storm in the year "" + year + "".");
}
/**
* Prints all storm details
*/
public void printAll() {
if(this.stormArr.length == 0)
System.out.println("No data.");
else {
for (Storm storm : stormArr) {
if(storm != null)
System.out.print(storm);
}
}
}
}
import java.io.File;
import java.util.Scanner;
public class Prog1 {
/**
* Displays a list of commands
*/
public static void printCommands() {
System.out.println(" Current available commands:");
System.out.println("1 --> Search for a storm name");
System.out.println("2 --> Search for a year");
System.out.println("3 --> Print all storms");
System.out.println("9 --> Exit");
}
public static void main(String args[]) {
if (args.length == 0) // Check if file name is provided in the command
// line
System.out.println("File name not specified");
else {
File f = new File(args[0]);
if (!f.exists()) // Check if file exists
System.out.println("Input file does not exist.");
else if (f.length() == 0) {
System.out.println("No data in the file");
} else {
// Create Database object
Database db = new Database(f);
// Scanner to get user input
Scanner in = new Scanner(System.in);
// Variable to get user command
int cmd = 0;
//Start
System.out.println("Welcome to the CS-102 Storm Tracker Program");
while (true) {
printCommands();
System.out.print("Your choice? ");
cmd = in.nextInt();
in.nextLine(); //Clear keyboard buffer
switch (cmd) {
case 1: //Search storm by name
System.out.println("Enter storm name prefix: ");
String name = in.nextLine();
db.getStormsByName(name);
break;
case 2: //Search storm by year
System.out.println("Enter storm year: ");
int year = in.nextInt();
db.getStormsByYear(year);
break;
case 3: //Print all storms
db.printAll();
break;
case 9: //Exit
in.close();
System.exit(0);
default:
System.out.println("Invalid command. Please try again.");
}
System.out.println();
}
}
}
}
}
SAMPLE INPUT:
2004/Ali///
2003/Bob///
1980/Sarah/0123/0312/0
1956/Michael/1211/1223/4
1988/Ryan/0926/1019/
1976/Tim/0318/1010/0
2006/Ronald/0919/1012/2
1996/Mona/0707/0723/1
2000/Kim/0101/0201/1
2000/Jim/1101//3
SAMPLE OUTPUT:
Welcome to the CS-102 Storm Tracker Program
Current available commands:
1 --> Search for a storm name
2 --> Search for a year
3 --> Print all storms
9 --> Exit
Your choice? 3
2004: Ali (no info): (no start) - (no end)
2003: Bob (no info): (no start) - (no end)
1980: Sarah (tropical storm): 01/23 - 03/12
1956: Michael (hurricane level 4): 12/11 - 12/23
1988: Ryan (no info): 09/26 - 10/19
1976: Tim (tropical storm): 03/18 - 10/10
2006: Ronald (hurricane level 2): 09/19 - 10/12
1996: Mona (hurricane level 1): 07/07 - 07/23
2000: Kim (hurricane level 1): 01/01 - 02/01
2000: Jim (hurricane level 3): 11/01 - (no end)
Current available commands:
1 --> Search for a storm name
2 --> Search for a year
3 --> Print all storms
9 --> Exit
Your choice? 1
Enter storm name prefix:
Ali
2004: Ali (no info): (no start) - (no end)
Current available commands:
1 --> Search for a storm name
2 --> Search for a year
3 --> Print all storms
9 --> Exit
Your choice? 2
Enter storm year:
2000
2000: Kim (hurricane level 1): 01/01 - 02/01
2000: Jim (hurricane level 3): 11/01 - (no end)
Current available commands:
1 --> Search for a storm name
2 --> Search for a year
3 --> Print all storms
9 --> Exit
Your choice? 9
Solution
public class Storm {
//Attributes
private String stormName;
private int stormYear;
private String stormStart;
private String stormEnd;
private int stormMag;
/**
* Constructor
*
* @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;
}
/**
* @return the stormName
*/
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;
}
@Override
public String toString() {
return " " + getStormYear() + ": " + getStormName() + " " +
((getStormMag() == -1) ? "(no info)" :
((getStormMag() == 0) ? "(tropical storm)" : "(hurricane level " +
getStormMag() + ")")) + ": " +
((getStormStart().equals("")) ? "(no start)" : getStormStart().substring(0, 2) + "/"
+ getStormStart().substring(2)) +
" - " +
((getStormEnd().equals("")) ? "(no end)" : getStormEnd().substring(0, 2) + "/" +
getStormEnd().substring(2));
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Database {
private static final int MAX_SIZE = 50;
//Attributes
private Storm[] stormArr;
private int count;
/**
* Constructor
* Accepts a file and attempts to read it
* Fills the storm array with the data
*/
public Database(File fileName) {
//Initialize array
this.stormArr = new Storm[MAX_SIZE];
this.count = 0;
//Scanner to read from the file
Scanner in = null;
try {
in = new Scanner(fileName);
//Read data from the file
while(in.hasNextLine()) {
//Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude
of storm
String line = in.nextLine();
String[] data = line.replaceAll("/", "/ ").split("/");
if(data.length < 5)
System.out.println("Database entry not in the correct format: " + line);
//Add data to array
this.stormArr[this.count] = new Storm(data[1].trim(), Integer.parseInt(data[0].trim()),
data[2].trim(), data[3].trim(),
(data[4].trim().equals("")) ? -1 : Integer.parseInt(data[4].trim()));
this.count += 1;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
//Close scanner
if(in == null)
in.close();
}
}
/**
* Returns a storm array which matches the name
*
* @param name
*/
public void getStormsByName(String name) {
boolean found = false;
for (Storm storm : stormArr) {
if((storm != null ) && (storm.getStormName().equalsIgnoreCase(name))) {
found = true;
System.out.print(storm);
}
}
if(!found)
System.out.println("Could not find any storm named "" + name + "".");
}
/**
* Returns a storm array which matches the year
*
* @param year
*/
public void getStormsByYear(int year) {
boolean found = false;
for (Storm storm : stormArr) {
if((storm != null ) && (storm.getStormYear() == year)) {
found = true;
System.out.print(storm);
}
}
if(!found)
System.out.println("Could not find any storm in the year "" + year + "".");
}
/**
* Prints all storm details
*/
public void printAll() {
if(this.stormArr.length == 0)
System.out.println("No data.");
else {
for (Storm storm : stormArr) {
if(storm != null)
System.out.print(storm);
}
}
}
}
import java.io.File;
import java.util.Scanner;
public class Prog1 {
/**
* Displays a list of commands
*/
public static void printCommands() {
System.out.println(" Current available commands:");
System.out.println("1 --> Search for a storm name");
System.out.println("2 --> Search for a year");
System.out.println("3 --> Print all storms");
System.out.println("9 --> Exit");
}
public static void main(String args[]) {
if (args.length == 0) // Check if file name is provided in the command
// line
System.out.println("File name not specified");
else {
File f = new File(args[0]);
if (!f.exists()) // Check if file exists
System.out.println("Input file does not exist.");
else if (f.length() == 0) {
System.out.println("No data in the file");
} else {
// Create Database object
Database db = new Database(f);
// Scanner to get user input
Scanner in = new Scanner(System.in);
// Variable to get user command
int cmd = 0;
//Start
System.out.println("Welcome to the CS-102 Storm Tracker Program");
while (true) {
printCommands();
System.out.print("Your choice? ");
cmd = in.nextInt();
in.nextLine(); //Clear keyboard buffer
switch (cmd) {
case 1: //Search storm by name
System.out.println("Enter storm name prefix: ");
String name = in.nextLine();
db.getStormsByName(name);
break;
case 2: //Search storm by year
System.out.println("Enter storm year: ");
int year = in.nextInt();
db.getStormsByYear(year);
break;
case 3: //Print all storms
db.printAll();
break;
case 9: //Exit
in.close();
System.exit(0);
default:
System.out.println("Invalid command. Please try again.");
}
System.out.println();
}
}
}
}
}
SAMPLE INPUT:
2004/Ali///
2003/Bob///
1980/Sarah/0123/0312/0
1956/Michael/1211/1223/4
1988/Ryan/0926/1019/
1976/Tim/0318/1010/0
2006/Ronald/0919/1012/2
1996/Mona/0707/0723/1
2000/Kim/0101/0201/1
2000/Jim/1101//3
SAMPLE OUTPUT:
Welcome to the CS-102 Storm Tracker Program
Current available commands:
1 --> Search for a storm name
2 --> Search for a year
3 --> Print all storms
9 --> Exit
Your choice? 3
2004: Ali (no info): (no start) - (no end)
2003: Bob (no info): (no start) - (no end)
1980: Sarah (tropical storm): 01/23 - 03/12
1956: Michael (hurricane level 4): 12/11 - 12/23
1988: Ryan (no info): 09/26 - 10/19
1976: Tim (tropical storm): 03/18 - 10/10
2006: Ronald (hurricane level 2): 09/19 - 10/12
1996: Mona (hurricane level 1): 07/07 - 07/23
2000: Kim (hurricane level 1): 01/01 - 02/01
2000: Jim (hurricane level 3): 11/01 - (no end)
Current available commands:
1 --> Search for a storm name
2 --> Search for a year
3 --> Print all storms
9 --> Exit
Your choice? 1
Enter storm name prefix:
Ali
2004: Ali (no info): (no start) - (no end)
Current available commands:
1 --> Search for a storm name
2 --> Search for a year
3 --> Print all storms
9 --> Exit
Your choice? 2
Enter storm year:
2000
2000: Kim (hurricane level 1): 01/01 - 02/01
2000: Jim (hurricane level 3): 11/01 - (no end)
Current available commands:
1 --> Search for a storm name
2 --> Search for a year
3 --> Print all storms
9 --> Exit
Your choice? 9

More Related Content

Similar to public class Storm {   Attributes    private String stormName;.pdf

Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
sooryasalini
 
(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf
rbjain2007
 
package reservation; import java.util.; For Scanner Class .pdf
 package reservation; import java.util.; For Scanner Class .pdf package reservation; import java.util.; For Scanner Class .pdf
package reservation; import java.util.; For Scanner Class .pdf
anitasahani11
 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdf
aquadreammail
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
anokhijew
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
Cross platform Objective-C Strategy
Cross platform Objective-C StrategyCross platform Objective-C Strategy
Cross platform Objective-C Strategy
Graham Lee
 
Please fix the java code (using eclipse)package hw4p1;import jav.pdf
Please fix the java code (using eclipse)package hw4p1;import jav.pdfPlease fix the java code (using eclipse)package hw4p1;import jav.pdf
Please fix the java code (using eclipse)package hw4p1;import jav.pdf
info961251
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
javaFix in the program belowhandle incomplete data for text fil.pdf
javaFix in the program belowhandle incomplete data for text fil.pdfjavaFix in the program belowhandle incomplete data for text fil.pdf
javaFix in the program belowhandle incomplete data for text fil.pdf
birajdar2
 
Listing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdfListing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdf
Ankitchhabra28
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
arjuncp10
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
SANDEEPARIHANT
 
I have the shell for this program already, I just need the two sub-f.pdf
I have the shell for this program already, I just need the two sub-f.pdfI have the shell for this program already, I just need the two sub-f.pdf
I have the shell for this program already, I just need the two sub-f.pdf
arhamnighty
 
PersonData.h#ifndef PersonData_h #define PersonData_h#inclu.pdf
 PersonData.h#ifndef PersonData_h #define PersonData_h#inclu.pdf PersonData.h#ifndef PersonData_h #define PersonData_h#inclu.pdf
PersonData.h#ifndef PersonData_h #define PersonData_h#inclu.pdf
annamalaiagencies
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
dbrienmhompsonkath75
 

Similar to public class Storm {   Attributes    private String stormName;.pdf (20)

Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
 
(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf
 
Dome3
Dome3Dome3
Dome3
 
package reservation; import java.util.; For Scanner Class .pdf
 package reservation; import java.util.; For Scanner Class .pdf package reservation; import java.util.; For Scanner Class .pdf
package reservation; import java.util.; For Scanner Class .pdf
 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdf
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Cross platform Objective-C Strategy
Cross platform Objective-C StrategyCross platform Objective-C Strategy
Cross platform Objective-C Strategy
 
Treatment, Architecture and Threads
Treatment, Architecture and ThreadsTreatment, Architecture and Threads
Treatment, Architecture and Threads
 
Please fix the java code (using eclipse)package hw4p1;import jav.pdf
Please fix the java code (using eclipse)package hw4p1;import jav.pdfPlease fix the java code (using eclipse)package hw4p1;import jav.pdf
Please fix the java code (using eclipse)package hw4p1;import jav.pdf
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
javaFix in the program belowhandle incomplete data for text fil.pdf
javaFix in the program belowhandle incomplete data for text fil.pdfjavaFix in the program belowhandle incomplete data for text fil.pdf
javaFix in the program belowhandle incomplete data for text fil.pdf
 
Listing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdfListing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdf
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
 
Design patterns
Design patternsDesign patterns
Design patterns
 
I have the shell for this program already, I just need the two sub-f.pdf
I have the shell for this program already, I just need the two sub-f.pdfI have the shell for this program already, I just need the two sub-f.pdf
I have the shell for this program already, I just need the two sub-f.pdf
 
PersonData.h#ifndef PersonData_h #define PersonData_h#inclu.pdf
 PersonData.h#ifndef PersonData_h #define PersonData_h#inclu.pdf PersonData.h#ifndef PersonData_h #define PersonData_h#inclu.pdf
PersonData.h#ifndef PersonData_h #define PersonData_h#inclu.pdf
 
zinno
zinnozinno
zinno
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
 

More from sharnapiyush773

“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf
sharnapiyush773
 
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdfThe Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
sharnapiyush773
 
The main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdfThe main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdf
sharnapiyush773
 
The expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdfThe expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdf
sharnapiyush773
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdf
sharnapiyush773
 
OSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdfOSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdf
sharnapiyush773
 
Note Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdfNote Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdf
sharnapiyush773
 
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdfOligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
sharnapiyush773
 
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdfMaroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
sharnapiyush773
 
In developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdfIn developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdf
sharnapiyush773
 
Bryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdfBryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdf
sharnapiyush773
 
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdfEthernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
sharnapiyush773
 

More from sharnapiyush773 (20)

“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf
 
Trueas each officer has fixed paroleelesratio = no of parollesn.pdf
Trueas each officer has fixed paroleelesratio = no of parollesn.pdfTrueas each officer has fixed paroleelesratio = no of parollesn.pdf
Trueas each officer has fixed paroleelesratio = no of parollesn.pdf
 
to upperSolutionto upper.pdf
to upperSolutionto upper.pdfto upperSolutionto upper.pdf
to upperSolutionto upper.pdf
 
there are several theory on defining acid and base, Lewis acids and .pdf
there are several theory on defining acid and base, Lewis acids and .pdfthere are several theory on defining acid and base, Lewis acids and .pdf
there are several theory on defining acid and base, Lewis acids and .pdf
 
The Statement is False. As there are many applications of hyperbo;ic.pdf
The Statement is False. As there are many applications of hyperbo;ic.pdfThe Statement is False. As there are many applications of hyperbo;ic.pdf
The Statement is False. As there are many applications of hyperbo;ic.pdf
 
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdfThe Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
 
The main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdfThe main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdf
 
The expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdfThe expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdf
 
picture is missingSolutionpicture is missing.pdf
picture is missingSolutionpicture is missing.pdfpicture is missingSolutionpicture is missing.pdf
picture is missingSolutionpicture is missing.pdf
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdf
 
OSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdfOSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdf
 
Note Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdfNote Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdf
 
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdfOligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
 
n = N 2^(rt)n = no of people at a given timeN = initial populat.pdf
n = N 2^(rt)n = no of people at a given timeN = initial populat.pdfn = N 2^(rt)n = no of people at a given timeN = initial populat.pdf
n = N 2^(rt)n = no of people at a given timeN = initial populat.pdf
 
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdfMaroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
 
It lacks the origin of replication which is most important for the i.pdf
It lacks the origin of replication which is most important for the i.pdfIt lacks the origin of replication which is most important for the i.pdf
It lacks the origin of replication which is most important for the i.pdf
 
In developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdfIn developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdf
 
Bryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdfBryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdf
 
givenSolutiongiven.pdf
givenSolutiongiven.pdfgivenSolutiongiven.pdf
givenSolutiongiven.pdf
 
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdfEthernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
 

Recently uploaded

Recently uploaded (20)

Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDF
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 

public class Storm {   Attributes    private String stormName;.pdf

  • 1. public class Storm { //Attributes private String stormName; private int stormYear; private String stormStart; private String stormEnd; private int stormMag; /** * Constructor * * @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; } /** * @return the stormName */ public String getStormName() { return stormName; } /** * @param stormName the stormName to set */
  • 2. 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 */
  • 3. 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; } @Override public String toString() { return " " + getStormYear() + ": " + getStormName() + " " + ((getStormMag() == -1) ? "(no info)" : ((getStormMag() == 0) ? "(tropical storm)" : "(hurricane level " + getStormMag() + ")")) + ": " + ((getStormStart().equals("")) ? "(no start)" : getStormStart().substring(0, 2) + "/" + getStormStart().substring(2)) + " - " + ((getStormEnd().equals("")) ? "(no end)" : getStormEnd().substring(0, 2) + "/" + getStormEnd().substring(2)); } } import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Database { private static final int MAX_SIZE = 50; //Attributes private Storm[] stormArr; private int count;
  • 4. /** * Constructor * Accepts a file and attempts to read it * Fills the storm array with the data */ public Database(File fileName) { //Initialize array this.stormArr = new Storm[MAX_SIZE]; this.count = 0; //Scanner to read from the file Scanner in = null; try { in = new Scanner(fileName); //Read data from the file while(in.hasNextLine()) { //Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude of storm String line = in.nextLine(); String[] data = line.replaceAll("/", "/ ").split("/"); if(data.length < 5) System.out.println("Database entry not in the correct format: " + line); //Add data to array this.stormArr[this.count] = new Storm(data[1].trim(), Integer.parseInt(data[0].trim()), data[2].trim(), data[3].trim(), (data[4].trim().equals("")) ? -1 : Integer.parseInt(data[4].trim())); this.count += 1; } } catch (FileNotFoundException e) { e.printStackTrace(); } finally { //Close scanner if(in == null)
  • 5. in.close(); } } /** * Returns a storm array which matches the name * * @param name */ public void getStormsByName(String name) { boolean found = false; for (Storm storm : stormArr) { if((storm != null ) && (storm.getStormName().equalsIgnoreCase(name))) { found = true; System.out.print(storm); } } if(!found) System.out.println("Could not find any storm named "" + name + ""."); } /** * Returns a storm array which matches the year * * @param year */ public void getStormsByYear(int year) { boolean found = false; for (Storm storm : stormArr) { if((storm != null ) && (storm.getStormYear() == year)) { found = true; System.out.print(storm); } }
  • 6. if(!found) System.out.println("Could not find any storm in the year "" + year + ""."); } /** * Prints all storm details */ public void printAll() { if(this.stormArr.length == 0) System.out.println("No data."); else { for (Storm storm : stormArr) { if(storm != null) System.out.print(storm); } } } } import java.io.File; import java.util.Scanner; public class Prog1 { /** * Displays a list of commands */ public static void printCommands() { System.out.println(" Current available commands:"); System.out.println("1 --> Search for a storm name"); System.out.println("2 --> Search for a year"); System.out.println("3 --> Print all storms"); System.out.println("9 --> Exit"); } public static void main(String args[]) { if (args.length == 0) // Check if file name is provided in the command // line System.out.println("File name not specified"); else {
  • 7. File f = new File(args[0]); if (!f.exists()) // Check if file exists System.out.println("Input file does not exist."); else if (f.length() == 0) { System.out.println("No data in the file"); } else { // Create Database object Database db = new Database(f); // Scanner to get user input Scanner in = new Scanner(System.in); // Variable to get user command int cmd = 0; //Start System.out.println("Welcome to the CS-102 Storm Tracker Program"); while (true) { printCommands(); System.out.print("Your choice? "); cmd = in.nextInt(); in.nextLine(); //Clear keyboard buffer switch (cmd) { case 1: //Search storm by name System.out.println("Enter storm name prefix: "); String name = in.nextLine(); db.getStormsByName(name); break; case 2: //Search storm by year System.out.println("Enter storm year: "); int year = in.nextInt(); db.getStormsByYear(year); break; case 3: //Print all storms db.printAll(); break; case 9: //Exit in.close();
  • 8. System.exit(0); default: System.out.println("Invalid command. Please try again."); } System.out.println(); } } } } } SAMPLE INPUT: 2004/Ali/// 2003/Bob/// 1980/Sarah/0123/0312/0 1956/Michael/1211/1223/4 1988/Ryan/0926/1019/ 1976/Tim/0318/1010/0 2006/Ronald/0919/1012/2 1996/Mona/0707/0723/1 2000/Kim/0101/0201/1 2000/Jim/1101//3 SAMPLE OUTPUT: Welcome to the CS-102 Storm Tracker Program Current available commands: 1 --> Search for a storm name 2 --> Search for a year 3 --> Print all storms 9 --> Exit Your choice? 3 2004: Ali (no info): (no start) - (no end) 2003: Bob (no info): (no start) - (no end) 1980: Sarah (tropical storm): 01/23 - 03/12 1956: Michael (hurricane level 4): 12/11 - 12/23 1988: Ryan (no info): 09/26 - 10/19 1976: Tim (tropical storm): 03/18 - 10/10 2006: Ronald (hurricane level 2): 09/19 - 10/12
  • 9. 1996: Mona (hurricane level 1): 07/07 - 07/23 2000: Kim (hurricane level 1): 01/01 - 02/01 2000: Jim (hurricane level 3): 11/01 - (no end) Current available commands: 1 --> Search for a storm name 2 --> Search for a year 3 --> Print all storms 9 --> Exit Your choice? 1 Enter storm name prefix: Ali 2004: Ali (no info): (no start) - (no end) Current available commands: 1 --> Search for a storm name 2 --> Search for a year 3 --> Print all storms 9 --> Exit Your choice? 2 Enter storm year: 2000 2000: Kim (hurricane level 1): 01/01 - 02/01 2000: Jim (hurricane level 3): 11/01 - (no end) Current available commands: 1 --> Search for a storm name 2 --> Search for a year 3 --> Print all storms 9 --> Exit Your choice? 9 Solution public class Storm { //Attributes private String stormName; private int stormYear; private String stormStart;
  • 10. private String stormEnd; private int stormMag; /** * Constructor * * @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; } /** * @return the stormName */ public String getStormName() { return stormName; } /** * @param stormName the stormName to set */ public void setStormName(String stormName) { this.stormName = stormName; } /** * @return the stormYear */
  • 11. 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 */
  • 12. public int getStormMag() { return stormMag; } /** * @param stormMag the stormMag to set */ public void setStormMag(int stormMag) { this.stormMag = stormMag; } @Override public String toString() { return " " + getStormYear() + ": " + getStormName() + " " + ((getStormMag() == -1) ? "(no info)" : ((getStormMag() == 0) ? "(tropical storm)" : "(hurricane level " + getStormMag() + ")")) + ": " + ((getStormStart().equals("")) ? "(no start)" : getStormStart().substring(0, 2) + "/" + getStormStart().substring(2)) + " - " + ((getStormEnd().equals("")) ? "(no end)" : getStormEnd().substring(0, 2) + "/" + getStormEnd().substring(2)); } } import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Database { private static final int MAX_SIZE = 50; //Attributes private Storm[] stormArr; private int count; /** * Constructor * Accepts a file and attempts to read it * Fills the storm array with the data */
  • 13. public Database(File fileName) { //Initialize array this.stormArr = new Storm[MAX_SIZE]; this.count = 0; //Scanner to read from the file Scanner in = null; try { in = new Scanner(fileName); //Read data from the file while(in.hasNextLine()) { //Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude of storm String line = in.nextLine(); String[] data = line.replaceAll("/", "/ ").split("/"); if(data.length < 5) System.out.println("Database entry not in the correct format: " + line); //Add data to array this.stormArr[this.count] = new Storm(data[1].trim(), Integer.parseInt(data[0].trim()), data[2].trim(), data[3].trim(), (data[4].trim().equals("")) ? -1 : Integer.parseInt(data[4].trim())); this.count += 1; } } catch (FileNotFoundException e) { e.printStackTrace(); } finally { //Close scanner if(in == null) in.close(); } } /** * Returns a storm array which matches the name
  • 14. * * @param name */ public void getStormsByName(String name) { boolean found = false; for (Storm storm : stormArr) { if((storm != null ) && (storm.getStormName().equalsIgnoreCase(name))) { found = true; System.out.print(storm); } } if(!found) System.out.println("Could not find any storm named "" + name + ""."); } /** * Returns a storm array which matches the year * * @param year */ public void getStormsByYear(int year) { boolean found = false; for (Storm storm : stormArr) { if((storm != null ) && (storm.getStormYear() == year)) { found = true; System.out.print(storm); } } if(!found) System.out.println("Could not find any storm in the year "" + year + ""."); } /** * Prints all storm details
  • 15. */ public void printAll() { if(this.stormArr.length == 0) System.out.println("No data."); else { for (Storm storm : stormArr) { if(storm != null) System.out.print(storm); } } } } import java.io.File; import java.util.Scanner; public class Prog1 { /** * Displays a list of commands */ public static void printCommands() { System.out.println(" Current available commands:"); System.out.println("1 --> Search for a storm name"); System.out.println("2 --> Search for a year"); System.out.println("3 --> Print all storms"); System.out.println("9 --> Exit"); } public static void main(String args[]) { if (args.length == 0) // Check if file name is provided in the command // line System.out.println("File name not specified"); else { File f = new File(args[0]); if (!f.exists()) // Check if file exists System.out.println("Input file does not exist."); else if (f.length() == 0) { System.out.println("No data in the file"); } else {
  • 16. // Create Database object Database db = new Database(f); // Scanner to get user input Scanner in = new Scanner(System.in); // Variable to get user command int cmd = 0; //Start System.out.println("Welcome to the CS-102 Storm Tracker Program"); while (true) { printCommands(); System.out.print("Your choice? "); cmd = in.nextInt(); in.nextLine(); //Clear keyboard buffer switch (cmd) { case 1: //Search storm by name System.out.println("Enter storm name prefix: "); String name = in.nextLine(); db.getStormsByName(name); break; case 2: //Search storm by year System.out.println("Enter storm year: "); int year = in.nextInt(); db.getStormsByYear(year); break; case 3: //Print all storms db.printAll(); break; case 9: //Exit in.close(); System.exit(0); default: System.out.println("Invalid command. Please try again."); } System.out.println(); }
  • 17. } } } } SAMPLE INPUT: 2004/Ali/// 2003/Bob/// 1980/Sarah/0123/0312/0 1956/Michael/1211/1223/4 1988/Ryan/0926/1019/ 1976/Tim/0318/1010/0 2006/Ronald/0919/1012/2 1996/Mona/0707/0723/1 2000/Kim/0101/0201/1 2000/Jim/1101//3 SAMPLE OUTPUT: Welcome to the CS-102 Storm Tracker Program Current available commands: 1 --> Search for a storm name 2 --> Search for a year 3 --> Print all storms 9 --> Exit Your choice? 3 2004: Ali (no info): (no start) - (no end) 2003: Bob (no info): (no start) - (no end) 1980: Sarah (tropical storm): 01/23 - 03/12 1956: Michael (hurricane level 4): 12/11 - 12/23 1988: Ryan (no info): 09/26 - 10/19 1976: Tim (tropical storm): 03/18 - 10/10 2006: Ronald (hurricane level 2): 09/19 - 10/12 1996: Mona (hurricane level 1): 07/07 - 07/23 2000: Kim (hurricane level 1): 01/01 - 02/01 2000: Jim (hurricane level 3): 11/01 - (no end) Current available commands: 1 --> Search for a storm name 2 --> Search for a year
  • 18. 3 --> Print all storms 9 --> Exit Your choice? 1 Enter storm name prefix: Ali 2004: Ali (no info): (no start) - (no end) Current available commands: 1 --> Search for a storm name 2 --> Search for a year 3 --> Print all storms 9 --> Exit Your choice? 2 Enter storm year: 2000 2000: Kim (hurricane level 1): 01/01 - 02/01 2000: Jim (hurricane level 3): 11/01 - (no end) Current available commands: 1 --> Search for a storm name 2 --> Search for a year 3 --> Print all storms 9 --> Exit Your choice? 9