Homework Help Question & Answers

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 Storm in the Storm.java file.

You must complete the methods in the Storm class and use them effectively throughout your program.

Note: The SaffirSimpson() method uses wind and pressure to calculate the category of a Storm.

Whenever you update wind, you must convert it from knots (how it is stored in the data file) to miles per hour.

The SaffirSimpson() and toString() methods have been written for you and do not need any further coding. The toString() method might need some tweaking for alignment purposes.

The GetStorm() Function

This is the most challenging method in the program! Here are some points to consider as you try to design this function.

Take another look at the data file - and notice that typically there are several records associated with one storm. It will be the job of GetStorm() to process these records, and build a Storm object, containing the relevant summary information.

Work out the while loop needed to process the correct records. For example, process records until the sequence number changes, or ....

Remember that this method returns a Storm object. It will have to use the new operator to allocate memory for this object.

Add the sort function

Use the selection sort algorithm to sort the Storms. Remember, we are sorting the array of Storms but the key is the Storm category.

Final cleanup and testing

Clean up any small bugs and add comments for documentation.

What to Hand In

Submit your code and screen output by the due date.

Project Files

The relevant files for this project are:

StormChaser.java (program starter file)

Storm.java (Storm class definition)

hurricanedata1950to2015.txt (data file)

MUST USE THESE STARTER FILES

/*

* Class: Storm.java

* Purpose: Store hurricane data for individual storm objects

*/

public class Storm {

private final double KnotsToMPH = 1.15;

private String stormID;

private int beginDate;

private int duration;

private String name;

private int category;

private int wind;

private int pressure;

public Storm( String stormid, int bdate, int dur, String sname, int w, int p )

{

stormID = stormid;

beginDate = bdate;

duration = dur;

name = sname;

wind = w;

pressure = p;

SaffirSimpson();

}

public void setDuration( int d )

{

duration = d;

}

public void setWind( int w )

{

}

public void setPressure( int p )

{

}

private void SaffirSimpson()

{

// Compute storm category, using the Saffir-Simpson scale

if(pressure <= 920 && wind >= 156)

{

category = 5; // Category 5

}

if(pressure > 920 && wind < 156)

{

category = 4; // Category 4

}

if(pressure > 945 && wind < 113)

{

category = 3; // Category 3

}

if(pressure > 965 && wind < 96)

{

category = 2; // Category 2

}   

if(pressure > 980 && wind < 83)

{

category = 1; // Category 1

}

if(wind < 64)

{

category = -1; // Tropical Storm

}   

if(wind < 34)

{

category = -2; // Tropical Depression

}

if(pressure == 0)

{

category = 0; // Missing pressure

}

}

public int getCategory()

{

return category;

}

public String toString()

{

return String.format("%s %9d %7d %-10s %2d %6d %8d\n",

stormID, beginDate, duration, name, category, wind, pressure);

}

}

SECOND STARTER FILE

/*

* Class: StormChaser.java

* Purpose: Main program to read hurricane data file, create Storm objects,

* and keep those that are category 3 or higher.

*/

import java.io.*;

import java.util.Scanner;

public class StormChaser {

public static void main(String[] args)

{

// Constants

final int MAX_STORMS = 300;

// array of Storms

Storm CurrentStorm; // storm returned by GetStorm

int nStorms = 0; // number in array List

int totalStorms = 0; // total number of storms in the input file

Scanner fileInput;

  

// Openning hurricane data file

try{

System.out.println("Openning hurricane data file...");

fileInput = new Scanner(new File("hurricanedata1950to2015.txt"));

}

catch(FileNotFoundException e){

System.err.println("FileNotFoundException: " + e.getMessage());

return;

}

System.out.println( "File opened successfully...");

System.out.println( "Reading file..." );

// Read Storm data from file until EOF

while( )

{

CurrentStorm = GetStorm(fileInput);

++totalStorms;

// If Storm i category 3 or higher, add to the array

if( )

{

  

nStorms++;

}

}

System.out.println( "Number of storms: " + totalStorms );

System.out.println( "Hurricanes with category 3 and above: " + nStorms );

DisplayStorms( "First Twenty Storms", List, 20 );

Sort( List, nStorms );

DisplayStorms( "Top Twenty Storms", List, 20 );

fileInput.close();

}

public static Storm GetStorm( Scanner in )

{

// Create constants as array indexes for data elements

  

  

// Declare variables

  

Storm NewStorm;

  

// Read the Storm header information

  

  

// Tokenize the header

  

// Read first row of Storm data

  

  

// Tokenize the Storm data

String[] dataElements = data.split(",");

  

// Extract the data elements

beginDate = Integer.parseInt(dataElements[BEGINDATE].trim());

wind = Integer.parseInt(dataElements[WIND].trim());

pressure = Integer.parseInt(dataElements[PRESSURE].trim());

duration = 6;   

  

// Create Storm object

NewStorm = new Storm(stormid, beginDate, duration, name, wind, pressure);   

  

for( int i = 1; i < ; i++ )

{

// Read next row of Storm data

data = in.nextLine();

  

// Tokenize the Storm data

dataElements = data.split(",");

  

// Extract the data elements

  

  

// Update Storm object

  

}

// Return the new storm object

return NewStorm;   

}

public static void DisplayStorms( String title, Storm[] List, int NStorms )

{

// display NStorms storms

// print some title and column headings

System.out.println(title);

System.out.println(

" Begin Duration Maximum Minimum ");

System.out.println(

"Storm ID Date (hours) Name Category Winds (mph) Press. (mb)");

System.out.println(

"-------------------------------------------------------------------------");

for( int k = 0; k < NStorms; k++ )

{

// Print out one Storm

  

}

System.out.println ("\n");

}

public static void Sort( Storm StormList[], int n )

{

// bubble sort the list of Storms

int pass = 0, k, switches;

Storm temp;

switches = 1;

while( switches != 0 )

{

switches = 0;

pass++;

for( k = 0; k < n - pass; k++ )

{

if( StormList[k].getCategory() < StormList[k+1].getCategory() )

{

temp = StormList[k];

StormList[k] = StormList[k+1];

StormList[k+1] = temp;

switches = 1;

}

}

}

}

}

hurricanedata1950to2015.txt

0 0
Add a comment
Answer #1

import java.io.*;
import java.util.Scanner;

public class StormChaser {
    public static void main(String[] args)
    {
        final int MAX_STORMS = 200;

        Storm[] List = new Storm[MAX_STORMS];
        Storm CurrentStorm;    
        int NStorms = 0;       
        int Total = 0;         
        Scanner fileInput;

    
        try{
            System.out.println("Openning hurricane data file...");
            fileInput = new Scanner(new File("hurricane.data"));
        }
        catch(FileNotFoundException e){
            System.err.println("FileNotFoundException: " + e.getMessage());
            return;
        }
        System.out.println( "File opened successfully...");
        System.out.println( "Reading file..." );


        // Read Storm data from file until EOF

        while(Total != MAX_STORMS )
        {
            CurrentStorm = GetStorm(fileInput);
            ++Total;
            if( CurrentStorm.getCategory() >= 3 )
            {
                List[NStorms++] = CurrentStorm;
            }
        }
        System.out.println( "Number of storms: " );
        System.out.println( "Hurricanes with category 3 and above: " + NStorms );
        DisplayStorms( "First Ten Storms", List, 10 );
        Sort( List, NStorms );
        DisplayStorms( "Top Ten Storms", List, 10 );
        fileInput.close();
    }

    public static Storm GetStorm( Scanner in )
    {

        int year = 0, month, day, hour, sequence, wind = 0, pressure = 0;
        String name = "";
        int current = 0, beginDate = 0, duration = 0;
        Storm NewStorm;
        double junk = 0.0;

     
        if( !in.hasNextLine() )
        {
            NewStorm = new Storm(beginDate, duration, name, wind, pressure);
            return NewStorm;
        }
      
        year = in.nextInt();
        month = in.nextInt();
        day = in.nextInt();
        hour = in.nextInt();
        sequence = in.nextInt();
        name = in.next();
        junk = in.nextDouble();   
        junk = in.nextDouble();   
        wind = in.nextInt();
        pressure = in.nextInt();


      
        beginDate = year * 10000 + month * 100 + day;
        duration = 0;
        NewStorm = new Storm(beginDate, duration, name, wind, pressure);
        current = sequence;


        while( in.hasNextLine() && sequence == current )
        {
          
            duration += 6;
            NewStorm.setDuration(duration);
            NewStorm.setWind(wind);
            NewStorm.setPressure(pressure);


            //get next record
            year = in.nextInt();
            month = in.nextInt();
            day = in.nextInt();
            hour = in.nextInt();
            sequence = in.nextInt();
            name = in.next();
            junk = in.nextDouble();  
            junk = in.nextDouble();   
            wind = in.nextInt();
            pressure = in.nextInt();

        }

     
        return NewStorm;
    }

    public static void DisplayStorms( String title, Storm[] List, int NStorms )
    {
        System.out.println(title + "\n");
        System.out.println("Begin Date   Duration   Name   Category   Maximum    Minimum");
        System.out.println("             (hours)                     Winds (mph) Press. (mb)");
        System.out.println("----------------------------------------------------------------");
        for( int k = 0; k < NStorms; k++ )
            System.out.print(List[k].toString());
        System.out.println ("\n");
    }

    public static void Sort( Storm[] StormList, int N )
    {
        int pass = 0, k, switches;
        Storm temp;
        switches = 1;
        while( switches != 0 )
        {
            switches = 0;
            pass++;
            for( k = 0; k < N - pass; k++ )
            {
                if( StormList[k].getCategory() < StormList[k+1].getCategory() )
                {
                    temp = StormList[k];
                    StormList[k] = StormList[k+1];
                    StormList[k+1] = temp;
                    switches = 1;
                }
            }
        }
    }
}
-----------------------------------------------------------------------------------------------------------
public class Storm {
    private final double KnotsToMPH = 1.15;

    private int beginDate;
    private int duration;
    private String name;
    private int category;
    private int wind;
    private int pressure;

    public Storm( int bdate, int dur, String sname, int w, int p )
    {
        beginDate = bdate;
        duration = dur;
        name = sname;
        wind = (int) (w * KnotsToMPH);
        pressure = p;
        SaffirSimpson();
    }

    public void setDuration( int d )
    {
        duration = d;
    }

    public void setWind( int w )
    {
        w = (int)(w * KnotsToMPH);

        if(w > wind)
        {
            wind = w;
        }
    }

    public void setPressure( int p )
    {
        if (pressure == 0)
        {
            pressure = p;
        }
        if (p > 0 && p < pressure)
        {

            pressure = p;
        }

        SaffirSimpson();
    }

    private void SaffirSimpson()
    {

        if(pressure <= 920 && wind >= 156)
        {
            category = 5;
        }
        if(pressure > 920 && wind < 156)
        {
            category = 4;
        }
        if(pressure > 945 && wind < 113)
        {
            category = 3;
        }
        if(pressure > 965 && wind < 96)
        {
            category = 2;
        }
        if(pressure > 980 && wind < 83)
        {
            category = 1;
        }
        if(wind < 64)
        {
            category = -1;
        }
        if(wind < 34)
        {
            category = -2;
        }
        if(pressure == 0)
        {
            category = 0;
        }
    }

    public int getCategory()
    {
        return category;
    }

    public String toString()
    {
        return String.format("%9d %8d   %10s %4d %9d %10d\n", beginDate, duration, name, category, wind, pressure);

    }

}
Storm Chaser- C:\Users. Su apnil StormChaser - StormChaser Asrc Storm java-IntelliJ IDEA 2017 2.5 Eile Edit View Navigate Cod

Add a comment
Know the answer?
Add Answer to:
Write in JAVA Get Familiar with the Problem Carefully read the program description and look at...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coin

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
  • This is a java homework for my java class. Write a program to perform statistical analysis...

    This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...

  • Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and...

    Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and implementation HighArray class and note the attributes and its methods.    Create findAll method which uses linear search algorithm to return all number of occurrences of specified element. /** * find an element from array and returns all number of occurrences of the specified element, returns 0 if the element does not exit. * * @param foundElement   Element to be found */ int findAll(int...

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

  • USE JAVA PROGRAMMING Create a program that would collect list of persons using double link list...

    USE JAVA PROGRAMMING Create a program that would collect list of persons using double link list and use a Merge Sort to sort the object by age. Create a class called Person : name and age Create methods that add, and delete Person from the link list Create a method that sorts the persons' objects by age. package mergesort; public class MergeSortExample { private static Comparable[] aux; // auxiliary array for merges public static void sort(Comparable[] a) { aux =...

  • Starting out with Java 1st chapter 16 problem 6

    This program is suppose to take in names.txt file save it to an array. Use quicksort to sort the names in ascending order. then allow the user to search for a name inthe array using binary search. But my program compiles but doesnt actual do anything HELP!//names.txtMARYPATRICIALINDABARBARAELIZABETHJENNIFERMARIASUSANMARGARETDOROTHYLISANANCYKARENBETTYHELENSANDRADONNACAROLRUTHSHARONMICHELLELAURASARAHKIMBERLYDEBORAHJESSICASHIRLEYCYNTHIAANGELAMELISSABRENDAAMYANNAREBECCAVIRGINIAKATHLEENPAMELAMARTHADEBRAAMANDASTEPHANIECAROLYNCHRISTINEMARIEJANETCATHERINEFRANCESANNJOYCEDIANEALICEJULIEHEATHERTERESADORISGLORIAEVELYNJEANCHERYLMILDREDKATHERINEJOANASHLEYJUDITHROSE/** QUICKSORT SEARCH PROGRAM*//*The QuickSort class provides a public staticmethod for performing a QuickSort on a string array.*/public class QuickSort{/*The quickSort method calls the qSort methodto sort a string [email protected] array The array to...

  • CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...

    CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...

  • Solve this using Java for an Intro To Java Class. Provided files: Person.java /** * Models...

    Solve this using Java for an Intro To Java Class. Provided files: Person.java /** * Models a person */ public class Person { private String name; private String gender; private int age; /** * Consructs a Person object * @param name the name of the person * @param gender the gender of the person either * m for male or f for female * @param age the age of the person */ public Person(String name, String gender, int age) {...

  • I'm attempting to convert ch object array to double array public void calculateSalesPrice() { double salePrice[]...

    I'm attempting to convert ch object array to double array public void calculateSalesPrice() { double salePrice[] = new double[ch.length]; int p = 0; for (int i = 0; i < ch.length; i += 3) { p = i + 1; for(int j = 0;j } } error message:items.java:16: error: cannot find symbol for(int j = 0;j ^ symbol: variable length location: class Object items.java:17: error: array required, but Object found salePrice[j] = (double full program import java.io.File; import java.util.Scanner; import...

  • 2-d array java (look for assignment7.java and customer.java at the end)

    In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified bya user. Then it will attempt to assign each customer to a seat in a movie theatre.1. First, you need to add one additional constructor method into Customer.java file.MethodDescription of the Methodpublic Customer (String customerInfo)Constructs a Customer object using the string containing customer's info. Use the split method of the String class...

  • How to solve and code the following requirements (below) using the JAVA program? 1. Modify the...

    How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...

Free Homework 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.