I am receiving incorrect output for the code-
/*
** file: Mtbf.mash
** purpose: Write a program that can be used to read an extract from a log for one elevator and print the Total uptime,
number of failures the MTBF (in years).
*/
import console;
String[] let = new String[2000]; // Array to store U for labelling uptime and D for labeling downtime
int[] seconds = new int[2000]; // Array to store time
//global variable to initialise i, sum and number of failures
int i = 0;
int sum = 0;
int numFailures = 0;
void main(){
words();
failures();
sumUptime();
toPrint();
I have attached the text file
}
void words(){
while(isNextLine()){
let[i] = readWord();
seconds[i] = readInt();
i = i + 1;
}
}
void failures(){
for(int n=0; n<i-1; n=n+1){
if (equals(let[n],"D")){
numFailures = numFailures + 1;
}
}
}
//This function is used to calculate uptime
void sumUptime(){
for(int u = 1; u<i; u = u + 2){
sum = sum+(seconds[u]-seconds[u-1]);
}
}
//This Function Convert seconds to year(in double)
double convert(int a){
double minutes=a/60;
double hours=minutes/60;
double days=hours/24;
double years=days/365.25;
return years;
}
void toPrint(){
println("Total uptime ="+ convert(sum)+"(years)");
println("Number of failures = "+numFailures);
println("Mean time between failures = "+ convert(sum/numFailures) +"(years)");
}
The output should be-
$ java AnalyseOne < S1.txt
Total uptime = 3.035229865389003 (years)
Number of failures = 6
Mean time between failures = 0.5058716442315004 (years)
I have attached a file that contains the log for the elevator
Attached File(s)
-
s1.txt (302bytes)
Number of downloads: 63

New Topic/Question
Reply


MultiQuote



|