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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 7 of 7

Thread: Looking for help - Beginner programming

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Looking for help - Beginner programming

    I am attempting to make a heart rate calculator program. Here is a little overview of what I am trying to do.
    It must use a constructor and get and set methods. It must print heart rate ranges and the user's information(age).
    I am sure there are many problems with my code I am truly a beginner this is one of my first programs. Any obivous errors pointed out would help a lot.
    Thank you.



       // Use scanner to get inputs
    import java.util.Scanner;
     
    // Declare class
    public class HeartRates {
    	private int Age;
    	private int DayOfBirth;
    	private int MonthOfBirth;
    	private int YearOfBirth;
    	private double MaxHeartRate;
    	private double MinTargetHeartRate;
    	private double MaxTargetHeartRate;
    	private String FirstName;
    	private String LastName;
     
     
     
    public HeartRates(_FirstName) //This is incomplete, I am very confused on the constructor concept.
    {
    	FirstName = _FirstName;
     
    }
     
     
     
    	// method to set age
    	public void setAge(int n) // store age
    	{ 
    		Age = n;
    	} // end method setAge
     
    	// method to get age
    	public int getAge()
    	{
    		return Age;
    	}
     
    	// method to set day of birth
    	public void setDayOfBirth(int z)
    	{
    		DayOfBirth = z; 
    	} // end method setDayOfBirth
     
    	// method to get day of birth
    	public int getDayOfBirth()
    	{
    		return DayOfBirth;
    	}
     
    	// method to set month of birth
    	public void setMonthOfBirth(String month)
    	{
    		MonthOfBirth = month;
    	}
     
    	// method to get month of birth
    	public String getMonthOfBirth()
    	{
    		return MonthOfBirth;
    	}
    	// method to set year of birth
    	public void setYearOfBirth(int y)
    	{
    		YearOfBirth = y;
    	}
     
    	// method to get year of birth
    	public int getYearOfBirth()
    	{
    		return YearOfBirth;
    	}
     
    	// method to set first name
    	public void setFirstName(String first)
    	{
    		FirstName = first;
    	}
     
    	// method to get first name
    	public String getFirstName()
    	{
    		return FirstName;
    	}
     
    	// method to set last name
    	public void setLastName(String last)
    	{
    		LastName = last;
    	}
     
    	// method to get last name
    	public String getLastName()
    	{
    		return LastName;
    	}
     
     
     
     
    	// method that calculates and returns age
    	public int Age () {
     
    		Age = (2014 - YearOfBirth);
    	}
     
    	public int MaxHeartRate () {
    		MaxHeartRate = 220 - Age;
    	}
     
    	public int MaxTargetHeartRate () {
    		MaxTargetHeartRate = (MaxHeartRate*.085);
    	}
     
    	public int MinTargetHeartRate () {
    		MinTargetHeartRate = (MaxHeartRate*0.50);
    	}
     
     
     
    	public static void main(String[] args) {
    		System.out.print("Enter first and last name \n");
    		System.out.print("Enter birthdate in format xx/xx/xxxx \n");
    		System.out.printf("%s", getFirstName());
    	} 
     
     
     
     
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,349
    Thanks
    49
    Thanked 2,204 Times in 2,177 Posts

    Default Re: Looking for help - Beginner programming

    Did you have any specific questions about your program?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Looking for help - Beginner programming

    Well I just don't know what to do next, it will not run. One question is, when using the get and set method, does using that automatically ask the user for input? Or do I have to do something separately to ask for input?

    Such as this, is it scanning in the first name?


    /// method to set first name
    public void setFirstName(String first)
    {
    FirstName = first;
    }

    // method to get first name
    public String getFirstName()
    {
    return FirstName;
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,349
    Thanks
    49
    Thanked 2,204 Times in 2,177 Posts

    Default Re: Looking for help - Beginner programming

    it will not run
    What does "not run" mean? If you are getting error messages, copy the full text and paste it here.
    Otherwise explain.

    does using that automatically ask the user
    Nothing automatically asks the user for input. It is up to the programmer to write the code that asks the user a question and reads his response.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Looking for help - Beginner programming

    How do I ask for the input for first name and implement it with the get and set method? I have a small amount of coding with c++ using scanf(%d) and I don't think that works here.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,349
    Thanks
    49
    Thanked 2,204 Times in 2,177 Posts

    Default Re: Looking for help - Beginner programming

    How do I ask for the input for first name
    Use the System.out.println() method to ask the user a question.
    The Scanner class has some methods that can be used to read a response from the user.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jan 2014
    Posts
    5
    My Mood
    Relaxed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Looking for help - Beginner programming

    Change public HeartRates(_FirstName) to public HeartRates(String _FirstName). You need to tell the program what type of variable you are using in your constructor, so that's why you say String. I know that's one problem but your code may have more.
    Last edited by Za Voucha; January 31st, 2014 at 08:24 PM. Reason: Font Error

Similar Threads

  1. Polymorphism Java Programming HELPP P.S. I am a beginner in Java Programming
    By judemartin99 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 20th, 2013, 02:21 PM
  2. Linked Lists Java Programming HELPP P.S. I am a beginner in Java Programming
    By judemartin99 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 20th, 2013, 02:19 PM
  3. Re: Beginner Programming Help
    By madhu12 in forum Computer Support
    Replies: 1
    Last Post: October 11th, 2012, 09:25 AM
  4. Beginner Programming Help
    By PCoombe85 in forum Object Oriented Programming
    Replies: 4
    Last Post: October 10th, 2012, 01:11 PM
  5. Programming beginner
    By LatinaC09 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 15th, 2010, 01:33 PM