📄 lightbulbanalysis.java
字号:
import java.io.*;
import javagently.*;
import myutilities.*;
class LightBulbAnalysis {
/* The light bulb program J M Bishop 1990, 1998
* ---------------------- updated May 2000
*
* Calculates the average light of light bulbs
* Uses the mean and stddev methods created
* in a Stats class in the myutilities package.
*
* Illustrates array i/o again
*/
LightBulbAnalysis () throws IOException {
int max = 101;
Display display = new Display("Light Bulb Analysis");
display.println ("***** Light Bulb Analysis *****\n");
display.println ("Statistical analysis of the lifetime of "+
"light bulbs");
display.println("with no. of readings < "+max);
display.println("Enter in the readings pressing ready after each one");
display.println("Enter yes for stop with the last reading");
display.prompt("Hours",0);
display.prompt("Stop", "no");
double hourReadings [] = new double[max];
int n = 0;
boolean stop = false;
for (n=1; n<max & !stop; n++) {
display.ready();
hourReadings[n] = display.getDouble("Hours");
display.print(Stream.format(hourReadings[n],6,1)+" ");
stop = display.getString("Stop").equalsIgnoreCase("yes");
}
n--;
display.println("\nThat's the data, thanks");
display.println("There were "+n+" samples");
if (n == 1) {
System.out.println("Mean = "+
Stream.format(Stats.mean(hourReadings,n),10,6)+
" but standard deviation not defined for n=1");
}
else {
double ave = Stats.mean(hourReadings,n);
display.println("Mean = "+Stream.format(ave,6,2)+
" hours");
display.println("Standard deviation = " +
Stream.format(
Stats.stddev(hourReadings,n,ave),6,2) + " hours");
}
}
public static void main (String [] args) throws IOException {
new LightBulbAnalysis ();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -