Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Methods and Arrays

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Thanked 0 Times in 0 Posts

    Default Methods and Arrays

    For this problem I'm supposed to help a client at a local fitness company. The client provides data in the form of a text file. Each row is the number of calories consumed for breakfast, lunch, and dinner and the data included is for one week. (7 lines of text)
    I'm supposed to print out: 1. list of the total number of calories consumed each day, 2. average number of calories consumed each day, 3. average number of calories consumed in each of the three meals, 4. the maximum number of calories consumed in any specific day, 5. and the maximum number of calories consumed in any one meal. All of these must have their own seperate methods and not be all put into the main method.
    This is what I have so far but am having trouble actually starting each method.
    Any help of any kind would be greatly appreciated!

    The text file includes:
    200 1000 800
    450 845 1200
    800 250 400
    0 1500 1800
    600 500 1000
    700 1400 1700
    675 400 900

    import java.util.*;
    import java.io.*;
    public class dietTracking {
    	public static void main(String[] arg){
    	static void readData(String fileName){		
    			File input=new File(fileName);
    			Scanner scanLine=new Scanner(input);		//To read line from the text file
    			String line=scanLine.nextLine();			//Read whole line from the file
    			Scanner scanNumber=new Scanner(line);		//To read numbers from the Line buffer
    			for(int meal=0; meal<3; meal++){			//To read three numbers from the line buffer
    				if(scanNumber.hasNextInt()){			//Check whether number is present in the line
    					int calories=scanNumber.nextInt();	//Read number from the line buffere and store
    					System.out.print(calories+" ");
    		catch (FileNotFoundException e){				//catch exception if input file is missing

  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    My Mood
    Thanked 263 Times in 232 Posts

    Default Re: Methods and Arrays

    Quote Originally Posted by scott201 View Post
    This is what I have so far but am having trouble actually starting each method.
    Plan ahead how to solve the problem first, (on paper perhaps) and then translate the solution into code. Work on one problem at a time.
    Pick one to begin with, write out the plan of how to solve it, and post the plan here with your question if you get stuck

Similar Threads

  1. [SOLVED] Using set/get methods and arrays
    By Shadud in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 25th, 2012, 10:11 PM
  2. Tic-Tac-Toe (loops, arrays, and methods) help please
    By CVL220 in forum Collections and Generics
    Replies: 3
    Last Post: November 10th, 2012, 01:47 PM
  3. [SOLVED] NullPointerException when using methods to find matching chars in two arrays.
    By Javaisfrustrating in forum Exceptions
    Replies: 4
    Last Post: November 18th, 2011, 04:12 AM
  4. Passing Arrays Between Methods
    By kigroy in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 10th, 2011, 10:10 PM
  5. [SOLVED] Writing a program with arrays and class methods... PLEASE HELP?
    By syang in forum What's Wrong With My Code?
    Replies: 17
    Last Post: August 8th, 2011, 07:02 AM

Tags for this Thread