运动状态最佳心率计算器 (Target-Heart-Rate Calculator)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hpdlzu80100/article/details/51682000

基本业务逻辑:

运动时最高心率:220-年龄(年)

运动时目标心率范围:运动时最高心率×0.5~运动时最高心率×0.85

说明:计算公式出处为American Heart Association (AHA) (www.americanheart.org/presenter.jhtml?identifier=4736)


代码如下:

//Exercise 3.16: Target-Heart-Rate Calculator,HeartRates.java
//By Pandenghuang@163.com
import javax.swing.JOptionPane;; // program uses class Scanner

public class HeartRateCalculator 
{
	private String name; 
	private int year;  

	public HeartRateCalculator(String name,int year) 
	{
	   this.name = name; 

	   if (year > 1916 && year<2016) 
	      this.year = year; 
	   else 
		   this.year = 1980; 
	}
	
	public int getage()
	{
	   return 2016-year; 
	} 
	
	public int getMaxHeartRate()
	{
	   return 220-getage(); 
	} 
	
	public String getTargetHeartRate()
	{
	   return String.format("%d 到 %d", (int)(getMaxHeartRate()*0.5),(int)(getMaxHeartRate()*0.85)); 
	} 
	
	public static void main(String[] args)
	{
	
	 String name=JOptionPane.showInputDialog("请输入您的名字:");
	 int year=Integer.parseInt(JOptionPane.showInputDialog("请输入您的出生年份:")); 
	 
	 HeartRates heartRates=new HeartRates(name,year,10,20);
	 
	 int age=heartRates.getage();
	 System.out.println(age);
	 int maxHeartRate=heartRates.getMaxHeartRate();
	 System.out.println(maxHeartRate);
	 String targetHeartRate=heartRates.getTargetHeartRate();
	 System.out.println(targetHeartRate);
	 
	 String message=String.format("%s,你好!\n您的年龄为:%d岁\n您锻炼时最高心率不能超过%d次/秒\n您锻炼时的理想心率(次/秒)为:%s",name,age,maxHeartRate,targetHeartRate);
	 JOptionPane.showMessageDialog(null, message);
	
	}
}

运行截屏如下:



阅读更多

没有更多推荐了,返回首页