Question

JAVA project PLEASE complete/ create project with comments in the programming explaining everything

Text file

Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude of storm/ //made up data

2004/Ali/1212/1219/1
2003/Bob/1123/1222/3
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
2001/Jim/1101/1201/3

Text file

Computing and Algorithms II: Programming Assignment 1 CS-102 Fall 2016 In this programming assignment, you will demonstrate your knowledge of material cov- ered in CS-101 (and re-acquaint yourself with the Java environment) by creating a simple database system for maintaining data on named tropical storms. File Input Your program will accept a single argument on the command line, which is a non-empty string giving the name of a file in the current directory This file will contain descriptions of tropical storms. Each line of the file will contain one record of data. Each record will be represented by several strings, separated by slashes, in the following order: 1. A four-digit integer representing the year of the storm. The smallest valid year is 1950; there is no largest valid year 2. A string representing the name given to the storm (e.g. Frances, Ivan, Jeanne) 3. A four-digit integer representing the starting date of the storm. The integers will have 4. A four-digit integer representing the ending date of the storm (in the same format as 5. A single digit representing the strength of the storm at its largest point. Valid digits are the form mmdd, where mm is a month (01-12), and dd is a day (01-31) the starting date) 0-6; 0 represents a tropical storm, while 1-5 represent hurricanes of the corresponding category. (e.g. category 3 hurricane) Note: Any of the last three items may be the empty string; this allows the database to be used for future storms as well as past storms. The first two items are required for all entries (Note that even if the items are absent, the delimiting slashes are required.) Your program will begin by reading in this information and storing it internally in an appropriate format. (See Internal Requirements.) Interactive Input Your program will then interact with the user running the program, offering the user a menu of commands. The following commands should be offered at this time: . Search the database for a storm name. If selected, the program should ask the user for a string. Using that name, the program should display all storms in the database whose names begins with that string. If no matching storms can be found, an appropriate message should be displayed

Class storm{
private String nameStorm;

private int yearStorm;
private int startStorm;
private int endStorm;
private int magStorm;

public storm(String name, int year, int start, int end, int mag){
nameStorm = name;
yearStorm = year;
startStorm = start;
endStorm = end;
magStorm = mag;
}
public String toString(){
return nameStorm yearStorm startStorm endStorm magStorm;
}

//The year of the storm
public getyearStorm(){
return yearStorm;
}
public void setyearStorm{
this.yearStorm = yearStorm;
}

//The name of the storm
public getnameStorm (){
return nameStorm;
}
public void setNamestorm{
this.nameStorm = nameStorm;
}

//the mmdd the storm started
public getstartStorm (){
return startStorm;
}
public void setmmddstart{
this.startStorm = startStorm;
}

//the mmdd the storm ended
public getendStorm (){
return endStorm;
}
public void setmmddend{
this.endStorm = endStorm;
}

//the level of the storm
public getmagStorm (){
return magStorm;
}
public void setmagStorm{
this.magStorm = magStorm;
}
}

public class Main{
public static void main(String[] args) {
//What will be printed out when application is is running
System.out.println("Welcome to the CS-102 Storm Tracker Program");
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("4. Exit");

//Having user input 1,2,3,4
int NumberList;
String nameStorm;
int yearStorm;
  
Scanner scan = new Scanner(System.in);
System.out.println("Enter a number 1-4");
NumberList = scan.nextInt();
System.out.println("You entered " + NumberList);

//if & else to print out what the user selected
if (NumberList == 1){
System.out.println("Enter storm names?");
nameStorm=scan.nextLine();
}
else if (NumberList == 2){
System.out.println("Enter Storm Year");
yearStorm=scan.nextInt();
}
else if (NumberList == 3){
System.out.println("Do you want to print all storms (y/n)");
}
else {
System.out.println("Exit");
}   
}
}

public class database{
// Opening the file   
java.io.File file = new java.io.File ("stormdata.txt");
try{
Scanner input = new Scanner(file);
//Read File Line By Line
while (input.hasNext()){
// Print the content on the console
String num = input.nextLine();
System.out.println ();
}
//Close the input stream
catch (FileNotFoundException e){//Catch exception if any
System.out.println("Error: File not found ");
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #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
   */
   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 "\n" + 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("\nCurrent 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

Add a comment
Know the answer?
Add Answer to:
JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write in JAVA Get Familiar with the Problem Carefully read the program description and look at...

    Write in JAVA Get Familiar with the Problem Carefully read the program description and look at the data file to gain an understanding of what is to be done. Make sure you are clear on what is to be calculated and how. That is, study the file and program description and ponder! Think! The Storm Class Type Now concentrate on the Storm class that we define to hold the summary information for one storm. First, look at the definition of...

  • Modify the program that you wrote for the last exercise in a file named Baseball9.java that...

    Modify the program that you wrote for the last exercise in a file named Baseball9.java that uses the Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class should once again be stored in a file named Player.java, however Baseball9.java is the only file that you need to modify for this assignment. Once all of the input data from the file is stored in the array, code and invoke a...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

  • Can someone compile this and name the it A4MA5331550.java and compile to make .class file. Will...

    Can someone compile this and name the it A4MA5331550.java and compile to make .class file. Will need to name . class file A4MA5331550 also when done put both files in a zipped folder named A4MA5331550 and email the folder to [email protected] here is the program: import java.util.Scanner; /** * 09/17/2017 * Dakota Mammedaty * MA5331550 * Bubble sorted */ public class MA5331550 { public static void main(String[] args) throws IOException { Sort st =new Sort(); st.getData(); System.out.println("=================Sorting Algorithms================="); System.out.println("1. Bubble...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • Java Programming Question

    After pillaging for a few weeks with our new cargo bay upgrade, we decide to branch out into a new sector of space to explore and hopefully find new targets. We travel to the next star system over, another low-security sector. After exploring the new star system for a few hours, we are hailed by a strange vessel. He sends us a message stating that he is a traveling merchant looking to purchase goods, and asks us if we would...

  • Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains...

    Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains a Java program. Your program should read the file (e.g., InputFile.java) and output its contents properly indented to ProgramName_Formatted.java (e.g., InputFile_Formatted.java). (Note: It will be up to the user to change the name appropriately for compilation later.) When you see a left-brace character ({) in the file, increase your indentation level by NUM_SPACES spaces. When you see a right-brace character (}), decrease your indentation...

  • (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text...

    (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text file named pets10.txt with 10 pets (or use the one below). Store this file in the same folder as your “class” file(s). The format is the same format used in the original homework problem. Each line in the file should contain a pet name (String), a comma, a pet’s age (int) in years, another comma, and a pet’s weight (double) in pounds. Perform the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT