java无忧网

标题: 英文作业:编写一个程序,提示用户输入温度和风速,程序然后显示风寒指数 [打印本页]

作者: java无忧网    时间: 2018-9-24 08:11
标题: 英文作业:编写一个程序,提示用户输入温度和风速,程序然后显示风寒指数
Assignment #2
Goals:
Ø  Thisassignment gives students more experience in:
·        Problem Solving
·        Writing Java programs
·        Writing Algorithms,using pseudo code
Problem Description
How cold is it outside? Thetemperature alone is not enough to provide the answer. Other factors includingwind speed, relative humidity, and sunshine play important roles in determiningcoldness outside.
In 2001, the NationalWeather Service implemented the new wind-chill index to measure the coldnessusing temperature and wind speed.
The formula is given asfollows:
  Twc = 13.112 + 0.6215 Ta -11.37 V0.16 + 0.3965 Ta V0.16
Where
·        Ta is the ambientair temperature in Celsius degree,
·        V is the wind speedin kilometers per hour,
·        Twc is the wind-chill index.
The formula can be usedonly for:
·        wind speeds between 0 and 100 km/h, and
·        temperatures between -50 and 5°C
Requirements
Write a program thatprompts the user to enter a temperature and a wind speed, the program then displaysthe wind-chill index. Use Math.pow(a, b) to compute V0.16.
Here is a sample program run:
  This program calculates the wind-chill index.
Enter the temperaturein Celsius: 0
Enter the wind speed kilometersper hour: 20
The wind chill indexis -5
·        Your programshould display the wind chill index as an integer number.
·        Your programsshould also display an appropriate error message and terminate if the userenters invalid input. For example:
Ø  If the temperature entered is not between -50oC and 5oC.
Ø  If the wind speed entered is not between 0 and 100 km/h.
Make a folder containingyour source code, and external document file, zip the folder and submit the zipfile to BrightSpace.
Marking Scheme
[4 marks] Presentation and Style: Readability, descriptiveidentifier,
                 indentation, bracket placement
[8 marks] Correctness: Program works without bugs
[4 marks] Error checking: Appropriate error message to the user when
                 invalid data is entered.
[4 marks] Documentation: External and Internal


目标:
这个作业给学生更多的经验:
解决问题
编写Java程序
使用伪代码编写算法
问题描述
外面有多冷?单靠温度是不够的。风速、相对湿度和日照等因素对室外寒冷的影响起着重要的作用。
2001年,国家气象局实施了新的风冷指数,利用温度和风速测量寒冷。
公式如下:
TWC=13.112+0.6215 Ta=1137 V0.16+ 0.3965 Ta V0.16
在哪里?
TA是摄氏摄氏度的环境空气温度,
v是每小时公里的风速,
TWC是风寒指数。
公式只能用于:
风速在0至100公里/小时之间,以及
温度在50℃和5℃之间
要求
编写一个程序,提示用户输入温度和风速,程序然后显示风寒指数。使用数学.PoW(a,b)来计算v0.16。
这里有一个示例程序运行:
这个程序计算风寒指数。
进入摄氏温度:0
输入风速公里每小时:20
寒风指数为-5
你的程序应该把风寒指数作为整数来显示。
您的程序还应该显示一个适当的错误消息,如果用户输入无效的输入,则终止。例如:
如果进入的温度不在-50℃和5℃之间。
如果风速输入不在0至100公里/小时之间。
制作一个包含源代码和外部文档文件的文件夹,压缩文件夹并将zip文件提交给BrightSpace。
标记方案
[ 4分]介绍和风格:可读性,描述性标识符,
压痕,托槽放置
[ 8个标记]正确性:程序没有bug
[ 4个标记]错误检查:何时向用户发出适当的错误消息
输入无效数据。
文献〔4分〕:外部与内部
代码:
import java.util.Scanner;


public class Test {

        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                Scanner input=new Scanner(System.in);
                System.out.println("Enter the wind speeds between 0 and 100 km/h, and temperatures between -50 and 5°C");
                System.out.print("Enter the temperature in Celsius:");
                double ta=input.nextDouble();
               
                System.out.print("Enter the wind speed kilometers per hour:");
                double v=input.nextDouble();
               
                double twc=13.112 + 0.6215* ta -11.37 *Math.pow(v, 0.16) + 0.3965 *ta* Math.pow(v, 0.16);
       
                System.out.println("The wind chill index is "+(int)twc);
        }


}









欢迎光临 java无忧网 (http://www.javawyw.com/) Powered by Discuz! X3.2