SlideShare a Scribd company logo
1 of 18
Download to read offline
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

(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
 
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 (16)

(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
 
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
 
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
 
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

Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
cupulin
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 

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