2 Replies - 1072 Views - Last Post: 01 January 2013 - 06:05 PM Rate Topic: -----

#1 techhead   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 01-June 12

Incorrect output for MTBF program

Posted 01 January 2013 - 06:53 AM

Hi

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)

  • Attached File  s1.txt (302bytes)
    Number of downloads: 63


Is This A Good Question/Topic? 0
  • +

Replies To: Incorrect output for MTBF program

#2 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1825
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Incorrect output for MTBF program

Posted 01 January 2013 - 11:45 AM

I dont know how you get this code to run, but it freaks me out..... Is this a java code? I dont see a class there and I see a C main() function instead of the java main method...
Please post your complete working code and tell us what output you were getting when running that code?
Was This Post Helpful? 0
  • +
  • -

#3 techhead   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 01-June 12

Re: Incorrect output for MTBF program

Posted 01 January 2013 - 06:05 PM

Here's the code again, it is mash source code thats why.-
/*  

02 ** file: Mtbf.mash  

03 ** purpose: Write a program that can be used to read an extract from a log for one elevator and print the Total uptime,   

04 number of failures the MTBF (in years).  

05 */ 

06    

07 import console;  

08    

09 String[] let = new String[2000]; // Array to store U for labelling uptime and D for labeling downtime  

10 int[] seconds = new int[2000]; // Array to store time  

11 //global variable to initialise i, sum and number of failures  

12 int i = 0;  

13 int sum = 0;  

14 int numFailures = 0;  

15     

16 void main(){  

17     words();  

18     failures();  

19     sumUptime();  

20     toPrint();  

21    

22

23    

24 }  

25    

26 void words(){  

27     while(isNextLine()){  

28         let[i] = readWord();  

29         seconds[i] = readInt();  

30         i = i + 1;  

31     }  

32 }  

33    

34 void failures(){  

35     for(int n=0; n<i-1; n=n+1){  

36         if (equals(let[n],"D")){  

37             numFailures = numFailures + 1;  

38         }  

39     }  

40 }  

41 //This function is used to calculate uptime   

42 void sumUptime(){  

43     for(int u = 1; u<i; u = u + 2){  

44         sum = sum+(seconds[u]-seconds[u-1]);  

45     }  

46 }  

47 //This Function Convert seconds to year(in double)  

48 double convert(int a){  

49     double minutes=a/60;  

50     double hours=minutes/60;  

51     double days=hours/24;  

52     double years=days/365.25;  

53     return years;  

54 }  

55 void toPrint(){  

56     println("Total uptime ="+ convert(sum)+"(years)");  

57     println("Number of failures = "+numFailures);  

58     println("Mean time between failures = "+ convert(sum/numFailures) +"(years)");  

59 } 



I got 13.71... for Total uptime
9 for failures
1.52 for MTBF

Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1