-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemory.java
More file actions
55 lines (54 loc) · 943 Bytes
/
Memory.java
File metadata and controls
55 lines (54 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Class Memory .
* This class is used to save results to memory
*/
public class Memory
{
private String[] inp;
private double[] outp;
public Memory()
{
inp=new String[0];
outp=new double[0];
}
public void display()
{
System.out.println("INPUT\t\t\t\tOUTPUT");
for(int i=0;i<inp.length;i++)
{
System.out.println(inp[i]+"\t\t\t\t"+outp[i]);
}
}
public void append(String in, double out)
{
int l=inp.length;
String temp[]=new String[l+1];
for(int i=0;i<l;i++)
temp[i]=inp[i];
temp[l]=in;
inp=temp;
double tmp[]=new double[l+1];
for(int i=0;i<l;i++)
tmp[i]=outp[i];
tmp[l]=out;
outp=tmp;
}
public String getInp(int i) throws Exception
{
if(i<=inp.length)
return inp[i-1];
else
throw (new Exception("Mycalc: \nResult not in memory"));
}
public String getOutp(int i) throws Exception
{
if(i<=inp.length)
return (""+outp[i-1]);
else
throw (new Exception("Mycalc: \nResult not in memory"));
}
public int getSize()
{
return(outp.length);
}
}