-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCell.java
More file actions
80 lines (80 loc) · 2.24 KB
/
Cell.java
File metadata and controls
80 lines (80 loc) · 2.24 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Cell is a unit of the spreadsheet so that is handles all the changes to the cell values according to the location.
*/
public class Cell
{
private String printLocation;
private int[] locationArray;
private String printValue;
private double doubleValue; //stays null until parsed
private char[] alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
private String inputValue;
public Cell(int r, int c)
{
printLocation = Character.toString(alphabet[c]) + (r+1);
locationArray = new int[2];
locationArray[0] = r;
locationArray[1] = c;
printValue = "<empty>";
inputValue = "<empty>";
}
public void setPrintLocation(String location)
{
printLocation = location;
}
public String getLocationString()
{
return printLocation;
}
public double getDoubleValue()
{
return doubleValue;
}
public String getValue()
{
return printValue;
}
public char[] getAlphabet()
{
return alphabet;
}
public String getInputValue()
{
return inputValue;
}
public void setValue(double input)
{
doubleValue = input;
}
public void setValue(String input)
{
printValue = input;
}
public void setInput(String input)
{
inputValue = input;
}
public void setCellIndividual(String input) throws NumberFormatException
{
inputValue = input;
try{
doubleValue = Double.parseDouble(input);
printValue = input;
}
catch (NumberFormatException error)
{
printValue = input;
if (input.charAt(0) == '\"')
printValue = input.substring(1, input.length());
if (input.charAt(input.length()-1) == '\"')
printValue = printValue.substring(0, printValue.length()-1);
inputValue = "\"" + printValue + "\"";
}
}
public void clear()
{
printValue = "<empty>";
inputValue = "<empty>";
doubleValue = 0.0;
}
}