Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS200 Lab 2: Formula Programming
This lab consists of three parts. In each part you will write a complete Java application program. 
When finished submit hardcopies of your three source code files and the outputs generated by 
running your programs with the specified inputs.
In each part you are to apply the algorithm you were given for writing a program that calculates a 
mathematical formula to write a program that calculates the specified formula. You may use any 
descriptive, valid identifiers for your class and variable names (hint: the variables used in the 
formulas are fine for your program variable names).
Part A. Write a Java application program that calculates the volume of a box. Use the following 
formula:
  vol = length * width * height
where vol is the volume, and length, width, and height are the dimensions of the box.
Run your program twice with the following inputs:
Run 1: 
length: 5.0 
width: 2.0 
height: 10.4 
Run 2: 
length: 3.0 
width: 4.2 
height: 6.6 
Part B. Write a Java application program that converts a user-input degrees Celsius to degrees 
Fahrenheit. The formula is:
  f = c  * 9.0 / 5.0 + 32.0
where c is degrees Celsius and f is degrees Fahrenheit.
Run your program three times with the following inputs for degrees Celsius.
Run 1:  37.0
Run 2:  0.0
Run 3:  100.0
page 1 of 2 
Part C. Write a Java application program that calculates your car’s miles-per-gallon when you 
fill-up your tank. Use the following formula:
  mpg = (m2 - m1) / g 
where mpg is miles-per-gallon, m1 is the mileage (odometer reading) at the last fill-up, m2 
is the current mileage (odometer reading), and g is the number of gallons it now takes to fill-up 
the car.
Run your program twice with the following inputs:
Run 1: 
mileage at last fill-up: 88000.0 
current mileage: 88396.0 
gallons for current fill-up: 12.0 
Run 2: 
mileage at last fill-up: 6540.0 
current mileage: 6675.0 
gallons for current fill-up: 3.5
page 2 of 2