Results 1 to 6 of 6
  1. #1
    clanboru15 is offline Member
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    Default Im on my last lab!!!! And im stuck...:(

    Basically, my lab is due very soon, and I have been trying to figure this out to no avail. I'll link to the main page, but here is the general instructions:

    1. Ask the user to enter the name of the input file containing the heart rate measurements, and input the file name;

    2. Ask the user to enter the name of the output file where the output HTML document will be saved, and input the file name;

    3. Open the input file by using a Scanner object (see Input file format for a description of the format of the input file);

    4. Open (create) the output file by using a PrintWriter object (see Output file format for a description of the format of the output file);

    5. Output to the file the appropriate opening HTML tags;

    6. Output to the file the header row of the table;

    7. For each series of heart rates in the input file, do the following:

    Input the series of numbers from the input file and store them in an array;

    Compute the minimum, maximum, and fitness quotient for the series;

    Output one row of the HTML table to the output file, with the fitness quotient, minimum and maximum heart rates, and the list of heart rates;

    8. Output to the file the appropriate closing HTML tags;

    9. Close the input and output files

    I can link to the website if you need it, but the website wont let me ehre.

    Now I dont really ever plan on taking more java, so at the moment I would really like to just get this done. Here is what I have so far...

    Java Code:
    import java.util.Scanner;
    import java.io.*;
    public class Lab7 {
    
    	//add try and catch
    	public static void main(String[] args) throws IOException{
    		Scanner keyboard = new Scanner(System.in);
    		
    		System.out.print("Enter input file name: ");
    		String infilename = keyboard.nextLine();
    	
    		System.out.print("Enter output file name: ");
    		String outfilename = keyboard.nextLine();
    		
    		File file = new File(infilename);
    		Scanner inputfile = new Scanner (file);
    		
    		PrintWriter outputFile = new PrintWriter("fitnessquotient.txt");
    		outputFile.write(<html>);
    		//not correct^^
    		
    		int min = 0;
    		int max = 0;
    		int totalarraylength = inputfile.nextInt();
    
    		//initial array
    		int i = 0;
    		while(inputfile.hasNext()){
    			int line = inputfile.nextInt();
    			int [] inputArray = new int[totalarraylength];
    			inputArray[i] = line;
    			i++;
    		}
    
    		int a = 1;
    		while (a < inputArray.length){
    			int [] personArray = new int [inputArray[a]];
    			
    			int b = 0;
    			while (b < personArray.length){
    				int heartRate = inputArray.nextInt();
    				if (min > heartRate){
    					min = heartRate; }
    				if (max < heartRate){
    					max = heartRate;
    				}
    				personArray[a] = inputArray.nextInt();
    				
    			}
    			//take inputArray to find min, max, and fitness quotient	
    		}
    
    		inputfile.close();
    		outputFile.close();
    	}
    }
    any help is appreciated... I saw a couple classmates labs, and they were doing about the same thing as me, except they seem to know whats going on.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I see requirements, I see some code, but sorry, but I don't really see a specific question. You may wish to post what your specific problems currently are.

    Also, please realize that we are all volunteers, and all of us are motivated by a love for Java and programming, a love that we hope to transmit to others by our helping here.

    This:
    Now I dont really ever plan on taking more java, so at the moment I would really like to just get this done.
    I'm afraid is not going to motivate many here to help you. Just information for your own benefit. Best of luck.

  3. #3
    clanboru15 is offline Member
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    Default

    Specific Question...
    ok
    How do I do the html output? The lab gives the tags like
    <html>
    <tr>
    <th>
    and such but I have no idea how to write that to the file using what I know. I'll attempt to do the other parts.

    Sorry I dont share some of the ethusiasm :/ I really appreciate how code works and I wanted to learn java, but it turned out to be very hard for me to understand despite the linear nature of the language. I can sit there and say what I need to do and how to do it, but when I go to use code, i completely blank and I get lost...

  4. #4
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    its very basic, they just want you to concat html tags to the data. say for example:
    Java Code:
    int heartRate = 90;
    String output = "<table><td><tr>" + 
                          heartRate + 
                          "</tr></td></table>";
    and so on....
    my html is a bit rusty, but its something like that.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  5. #5
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    you need to manually build the buffer for the html file as angryboy has described. there is no magical library to do this for you. actually, there may be one, but it's a lot easier to do it manually.

    unless your problem is writing to a file. there are a lot of posts here that you can search out for solutions. or doing a google search would give you a quick answer.

  6. #6
    clanboru15 is offline Member
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    Default

    "you need to manually build the buffer for the html file as angryboy has described."

    I knew this, I just couldnt find the syntax for it anywhere. Thanks much. Tried google several times, wasnt very helpful, or I was using the wrong keywords. I may be back with more questions... I had to leave for a while and now Im not sure how much I will be able to get done.

Similar Threads

  1. Stuck on code...plz help
    By trump101 in forum New To Java
    Replies: 1
    Last Post: 11-26-2008, 01:48 AM
  2. really stuck now..
    By shongo in forum Advanced Java
    Replies: 2
    Last Post: 11-09-2008, 03:56 AM
  3. [SOLVED] Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 12
    Last Post: 09-23-2008, 04:18 AM
  4. Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 03:22 AM
  5. I am completely stuck
    By jpnym15 in forum New To Java
    Replies: 2
    Last Post: 11-14-2007, 07:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •