I am having trouble with my class assignment. I have gotten myself confused and don't know how to proceed. also i'm really having a problem thinking this through, and don't know where to continue working or what to throw away from my code. Any input or help would be immensely helpful as i am at a dead end currently. The bottom methods are all commented out as I want to be able to finish the first part first. maybe if i can get that done i can do the rest on my own. also, if you can tell me how to tidy up my code and make it more readable, that would be helpful, as its starting to confuse even me at this point.
this is my class assignment:
You have been asked to build a program to read high and low temperatures for each month from a data file. Based upon the data, you will report temperature statistics to both the output window and a file as outlined below. Output should include a heading and be formatted in columns. The table gridlines are not required. Your program design and solution should implement methods as described in Chapter 5.
Input – All program input will be through a data file
Input File: your program should prompt for the name of the input file
You should test your program using at least two sample executions. One with
MonthlyTemperatures.txt (provided in Blackboard)
You will create a second text file to test your program
Files should include month name, highest temperature and lowest temperature for each month.
this is what the .txt looks like
January 72 -12
February 75 -5
March 80 8
April 98 15
May 98 29
June 100 28
July 103 48
August 106 40
September 102 35
October 90 26
November 85 14
December 76 -10
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
/**
This program applies line numbers to a file.
*/
public class TempCheck
{
public static void main(String[] args) throws FileNotFoundException
{
//Variables
int lineNumber = 1;
String line;
String[] data = new String[12];
int[] temps = new int[12];
// Prompt for the input and output file names
Scanner console = new Scanner(System.in);
System.out.print("Input file: ");
String inputFileName = console.next();
System.out.print("Output file: ");
String outputFileName = console.next();
// Construct the Scanner and PrintWriter objects for reading and writing
File inputFile = new File(inputFileName);
Scanner in = new Scanner(inputFile);
PrintWriter out = new PrintWriter(outputFileName);
for (int i = 0; i < 12; i++)
{
line = in.nextLine();
data[i] = line;
// Data being sent to the other methods
temps = firstTemp(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8],data[9],data[10],data[11]);
}
/**
all of the months printed with there
corresponding tempuratures,
the averages of the tempuratures,
and the rangeof the tempuratures
*/
System.out.println ("Month Tempuratures Average Range");
System.out.println (" ______________ _________ _______");
System.out.println ("January | | | | | |");
System.out.println ("Febryary | | | | | |");
System.out.println ("March | | | | | |");
System.out.println ("April | | | | | |");
System.out.println ("May | | | | | |");
System.out.println ("June | | | | | |");
System.out.println ("July | | | | | |");
System.out.println ("August | | | | | |");
System.out.println ("September | | | | | |");
System.out.println ("October | | | | | |");
System.out.println ("November | | | | | |");
System.out.println ("December | | | | | |");
System.out.println (" -------------- --------- -------");
in.close();
out.close();
}
/**
Extracts the first tempurature
@param line a line containing a month name, followed by a tempurature value
@return the first Temp associated with the month
*/
public static int[] firstTemp(String jan,String feb,String mar,String apr,String may,String jun,String jul,String aug,String sep,String oct,String nov,String dec,)
{
//array for the first temps
int[] temps = new int[12];
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(jan.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[0] = jan.parseInteger(jan.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(feb.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[1] = feb.parseInteger(feb.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(mar.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[2] = mar.parseInteger(mar.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(apr.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[3] = apr.parseInteger(apr.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(may.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[4] = may.parseInteger(may.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(jun.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[5] = jun.parseInteger(jun.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(jul.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[6] = jul.parseInteger(jul.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(aug.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[7] = aug.parseInteger(aug.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(sep.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[8] = sep.parseInteger(sep.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(oct.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[9] = oct.parseInteger(oct.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(nov.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[10] = nov.parseInteger(nov.substring(i).trim());
int i = 0; // Locate the start of the first digit
while (!Character.isDigit(dec.charAt(i)))
{
i++;
}
// Extract and convert the value
temps[11] = dec.parseInteger(dec.substring(i).trim());
return temps;
}
/**
/**
Extracts the second tempurature
@param line a line containing a month name, followed by a tempurature value
@return the second Temp associated with the month
*
public static int[] secondTemp(
{
//do stuff
}
/**Averages all of the tempuratures from each month
@
@return the averages for each month
*
public static int averageTemp (
{
//do stuff
}
/** Records the range of all of the tempuratures for each month
@
@return the range for each month
*
public static int tempRange (
{
//do stuff
}
*/
}