JavaFx assignment
software assignment/ChartS_v3/.classpath
software assignment/ChartS_v3/.project
ChartS org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature
software assignment/ChartS_v3/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8
software assignment/ChartS_v3/bin/application.css
/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
software assignment/ChartS_v3/bin/BarChartExperiments.class
public synchronized class BarChartExperiments implements Observer { String department; javafx.scene.chart.BarChart barChart; SalesData data; Subject subject; public void BarChartExperiments(SalesData, Subject); public javafx.scene.chart.BarChart createBarChart(); public void refresh(String); }
software assignment/ChartS_v3/bin/Main$1.class
synchronized class Main$1 implements javafx.event.EventHandler { void Main$1(Main, javafx.scene.control.ComboBox); public void handle(javafx.event.ActionEvent); }
software assignment/ChartS_v3/bin/Main.class
public synchronized class Main extends javafx.application.Application implements Subject { String department; javafx.scene.chart.BarChart barChart; javafx.scene.chart.PieChart pieChart; javafx.scene.control.TableView tableView; SalesData data; java.util.ArrayList list; public void Main(); public void start(javafx.stage.Stage) throws Exception; public void notifyObservers(); public void register(Observer); public void unRegister(Observer); public static void main(String[]); }
software assignment/ChartS_v3/bin/MainTab$1.class
synchronized class MainTab$1 implements javafx.event.EventHandler { void MainTab$1(MainTab, javafx.scene.control.ComboBox); public void handle(javafx.event.ActionEvent); }
software assignment/ChartS_v3/bin/MainTab.class
public synchronized class MainTab extends javafx.application.Application implements Subject { String department; javafx.scene.chart.BarChart barChart; javafx.scene.control.TableView tableView; SalesData data; java.util.ArrayList list; public void MainTab(); public void start(javafx.stage.Stage) throws Exception; public void notifyObservers(); public void register(Observer); public void unRegister(Observer); public static void main(String[]); }
software assignment/ChartS_v3/bin/Observer.class
public abstract interface Observer { public abstract void refresh(String); }
software assignment/ChartS_v3/bin/PieChartExperiments.class
public synchronized class PieChartExperiments implements Observer { String department; javafx.scene.chart.PieChart pieChart; SalesData data; Subject subject; public void PieChartExperiments(SalesData, Subject); public javafx.scene.chart.PieChart createPieChart(); public void refresh(String); }
software assignment/ChartS_v3/bin/SaleItem.class
public synchronized class SaleItem { private String dept; private int month; private int day; private int quantity; private int amount; public String getDepartment(); public int getMonth(); public int getDay(); public String getDept(); public int getQuantity(); public int getAmount(); public void SaleItem(String, int, int, int, int); }
software assignment/ChartS_v3/bin/SalesData.class
public synchronized class SalesData { java.util.ArrayList allRows; String department; public void SalesData(String); public String getDepartment(); public void setDepartment(String); public int[] getYTDTotals(String); public int getMonthlyTotal(int, String); public java.util.ArrayList getCurrentMonthTransactions(int, String); }
software assignment/ChartS_v3/bin/Subject.class
public abstract interface Subject { public abstract void notifyObservers(); public abstract void register(Observer); public abstract void unRegister(Observer); }
software assignment/ChartS_v3/bin/TableExperiments.class
public synchronized class TableExperiments implements Observer { String department; javafx.scene.control.TableView table; SalesData data; public void TableExperiments(SalesData, Subject); public javafx.scene.control.TableView createTableView(); public void refresh(String); private javafx.collections.ObservableList getInitialTableData(); }
software assignment/ChartS_v3/src/application.css
/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
software assignment/ChartS_v3/src/BarChartExperiments.java
software assignment/ChartS_v3/src/BarChartExperiments.java
import
java
.
util
.
Calendar
;
import
java
.
util
.
Date
;
import
javafx
.
application
.
Application
;
import
javafx
.
collections
.
FXCollections
;
import
javafx
.
event
.
ActionEvent
;
import
javafx
.
event
.
EventHandler
;
import
javafx
.
geometry
.
Pos
;
import
javafx
.
scene
.
Group
;
import
javafx
.
scene
.
Scene
;
import
javafx
.
scene
.
chart
.
Axis
;
import
javafx
.
scene
.
chart
.
BarChart
;
import
javafx
.
scene
.
chart
.
CategoryAxis
;
import
javafx
.
scene
.
chart
.
NumberAxis
;
import
javafx
.
scene
.
chart
.
XYChart
;
import
javafx
.
scene
.
control
.
ComboBox
;
import
javafx
.
scene
.
layout
.
VBox
;
import
javafx
.
stage
.
Stage
;
public
class
BarChartExperiments
implements
Observer
{
String
department
=
"Furniture"
;
BarChart
barChart
;
SalesData
data
;
Subject
subject
;
public
BarChartExperiments
(
SalesData
data
,
Subject
s
)
{
s
.
register
(
this
);
this
.
data
=
data
;
}
public
BarChart
createBarChart
()
{
CategoryAxis
xAxis
=
new
CategoryAxis
();
xAxis
.
setLabel
(
"Month"
);
NumberAxis
yAxis
=
new
NumberAxis
();
yAxis
.
setLabel
(
"Sales"
);
barChart
=
new
BarChart
(
xAxis
,
yAxis
);
refresh
(
department
);
return
barChart
;
}
public
void
refresh
(
String
department
)
{
String
[]
months
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
int
[]
totals
=
data
.
getYTDTotals
(
department
);
XYChart
.
Series
dataSeries1
;
dataSeries1
=
new
XYChart
.
Series
();
dataSeries1
.
setName
(
"Year to date Sales"
);
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
new
Date
());
int
month
=
cal
.
get
(
Calendar
.
MONTH
)
+
1
;
for
(
int
i
=
0
;
i
<
month
;
i
++
)
{
dataSeries1
.
getData
().
add
(
new
XYChart
.
Data
(
months
[
i
],
totals
[
i
]));
}
barChart
.
getData
().
clear
();
barChart
.
getData
().
add
(
dataSeries1
);
}
}
software assignment/ChartS_v3/src/Main.java
software assignment/ChartS_v3/src/Main.java
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Calendar
;
import
java
.
util
.
Date
;
import
javafx
.
application
.
Application
;
import
javafx
.
collections
.
FXCollections
;
import
javafx
.
event
.
ActionEvent
;
import
javafx
.
event
.
EventHandler
;
import
javafx
.
geometry
.
Pos
;
import
javafx
.
scene
.
Group
;
import
javafx
.
scene
.
Scene
;
import
javafx
.
scene
.
chart
.
BarChart
;
import
javafx
.
scene
.
chart
.
CategoryAxis
;
import
javafx
.
scene
.
chart
.
NumberAxis
;
import
javafx
.
scene
.
chart
.
PieChart
;
import
javafx
.
scene
.
chart
.
XYChart
;
import
javafx
.
scene
.
control
.
ComboBox
;
import
javafx
.
scene
.
control
.
TableView
;
import
javafx
.
scene
.
layout
.
BorderPane
;
import
javafx
.
scene
.
layout
.
HBox
;
import
javafx
.
scene
.
layout
.
VBox
;
import
javafx
.
stage
.
Stage
;
public
class
Main
extends
Application
implements
Subject
{
String
department
=
"Furniture"
;
BarChart
barChart
;
PieChart
pieChart
;
TableView
tableView
;
SalesData
data
=
new
SalesData
(
"Transactions.dat"
);
ArrayList
<
Observer
>
list
=
new
ArrayList
<
Observer
>
();
@
Override
public
void
start
(
Stage
primaryStage
)
throws
Exception
{
primaryStage
.
setTitle
(
"Current Sales"
);
BarChartExperiments
b
=
new
BarChartExperiments
(
data
,
this
);
barChart
=
b
.
createBarChart
();
PieChartExperiments
p
=
new
PieChartExperiments
(
data
,
this
);
pieChart
=
p
.
createPieChart
();
TableExperiments
t
=
new
TableExperiments
(
data
,
this
);
tableView
=
t
.
createTableView
();
String
depts
[]
=
{
"Furniture"
,
"HardWare"
,
"Electronics"
};
// Create a combo box
ComboBox
combo_box
=
new
ComboBox
(
FXCollections
.
observableArrayList
(
depts
));
combo_box
.
setValue
(
"Furniture"
);
// Create action event
EventHandler
<
ActionEvent
>
event
=
new
EventHandler
<
ActionEvent
>
()
{
public
void
handle
(
ActionEvent
e
)
{
department
=
(
String
)
combo_box
.
getValue
();
notifyObservers
();
}
};
// Set on action
combo_box
.
setOnAction
(
event
);
VBox
vbox
=
new
VBox
(
combo_box
);
vbox
.
setAlignment
(
Pos
.
CENTER
);
HBox
hbox
=
new
HBox
();
BorderPane
border
=
new
BorderPane
();
border
.
setTop
(
vbox
);
border
.
setCenter
(
hbox
);
Scene
scene
=
new
Scene
(
border
,
800
,
350
);
hbox
.
getChildren
().
addAll
(
tableView
,
barChart
,
pieChart
);
hbox
.
setAlignment
(
Pos
.
CENTER
);
primaryStage
.
setScene
(
scene
);
primaryStage
.
setHeight
(
350
);
primaryStage
.
setWidth
(
1200
);
primaryStage
.
show
();
}
public
void
notifyObservers
()
{
for
(
Observer
o
:
list
)
{
o
.
refresh
(
department
);
}
}
public
void
register
(
Observer
obs
)
{
list
.
add
(
obs
);
}
public
void
unRegister
(
Observer
obs
)
{
list
.
remove
(
obs
);
}
public
static
void
main
(
String
[]
args
)
{
Application
.
launch
(
args
);
}
}
software assignment/ChartS_v3/src/MainTab.java
software assignment/ChartS_v3/src/MainTab.java
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Calendar
;
import
java
.
util
.
Date
;
import
javafx
.
application
.
Application
;
import
javafx
.
collections
.
FXCollections
;
import
javafx
.
event
.
ActionEvent
;
import
javafx
.
event
.
EventHandler
;
import
javafx
.
geometry
.
Pos
;
import
javafx
.
scene
.
Group
;
import
javafx
.
scene
.
Scene
;
import
javafx
.
scene
.
chart
.
BarChart
;
import
javafx
.
scene
.
chart
.
CategoryAxis
;
import
javafx
.
scene
.
chart
.
NumberAxis
;
import
javafx
.
scene
.
chart
.
PieChart
;
import
javafx
.
scene
.
chart
.
XYChart
;
import
javafx
.
scene
.
control
.
ComboBox
;
import
javafx
.
scene
.
control
.
Tab
;
import
javafx
.
scene
.
control
.
TabPane
;
import
javafx
.
scene
.
control
.
TableView
;
import
javafx
.
scene
.
layout
.
BorderPane
;
import
javafx
.
scene
.
layout
.
HBox
;
import
javafx
.
scene
.
layout
.
VBox
;
import
javafx
.
stage
.
Stage
;
public
class
MainTab
extends
Application
implements
Subject
{
String
department
=
"Furniture"
;
BarChart
barChart
;
TableView
tableView
;
SalesData
data
=
new
SalesData
(
"Transactions.dat"
);
ArrayList
<
Observer
>
list
=
new
ArrayList
<
Observer
>
();
@
Override
public
void
start
(
Stage
primaryStage
)
throws
Exception
{
primaryStage
.
setTitle
(
"Current Sales"
);
BarChartExperiments
b
=
new
BarChartExperiments
(
data
,
this
);
barChart
=
b
.
createBarChart
();
TableExperiments
t
=
new
TableExperiments
(
data
,
this
);
tableView
=
t
.
createTableView
();
String
depts
[]
=
{
"Furniture"
,
"HardWare"
,
"Electronics"
};
// Create a combo box
ComboBox
combo_box
=
new
ComboBox
(
FXCollections
.
observableArrayList
(
depts
));
combo_box
.
setValue
(
"Furniture"
);
// Create action event
EventHandler
<
ActionEvent
>
event
=
new
EventHandler
<
ActionEvent
>
()
{
public
void
handle
(
ActionEvent
e
)
{
department
=
(
String
)
combo_box
.
getValue
();
notifyObservers
();
}
};
// Set on action
combo_box
.
setOnAction
(
event
);
TabPane
tabPane
=
new
TabPane
();
BorderPane
mainPane
=
new
BorderPane
();
VBox
vbox1
=
new
VBox
();
vbox1
.
setAlignment
(
Pos
.
CENTER
);
vbox1
.
getChildren
().
add
(
tableView
);
//Create Tabs
Tab
tabA
=
new
Tab
();
tabA
.
setText
(
"Table View"
);
tabA
.
setContent
(
vbox1
);
tabPane
.
getTabs
().
add
(
tabA
);
VBox
vbox2
=
new
VBox
();
vbox2
.
setAlignment
(
Pos
.
CENTER
);
vbox2
.
getChildren
().
add
(
barChart
);
//Create Tabs
Tab
tabB
=
new
Tab
();
tabB
.
setText
(
"Bar Chart"
);
tabB
.
setContent
(
vbox2
);
tabPane
.
getTabs
().
add
(
tabB
);
mainPane
.
setTop
(
combo_box
);
mainPane
.
setAlignment
(
combo_box
,
Pos
.
CENTER
);
mainPane
.
setCenter
(
tabPane
);
Scene
scene
=
new
Scene
(
mainPane
,
400
,
600
);
/*BorderPane border = new BorderPane();
border.setTop(vbox);
border.setCenter(hbox);
Scene scene = new Scene(border, 800, 200);
hbox.getChildren().addAll(tableView,barChart,pieChart);
hbox.setAlignment(Pos.CENTER);*/
primaryStage
.
setScene
(
scene
);
primaryStage
.
setHeight
(
300
);
primaryStage
.
setWidth
(
1200
);
primaryStage
.
show
();
}
public
void
notifyObservers
()
{
for
(
Observer
o
:
list
)
{
o
.
refresh
(
department
);
}
}
public
void
register
(
Observer
obs
)
{
list
.
add
(
obs
);
}
public
void
unRegister
(
Observer
obs
)
{
list
.
remove
(
obs
);
}
public
static
void
main
(
String
[]
args
)
{
Application
.
launch
(
args
);
}
}
software assignment/ChartS_v3/src/Observer.java
software assignment/ChartS_v3/src/Observer.java
public
interface
Observer
{
public
void
refresh
(
String
dept
);
}
software assignment/ChartS_v3/src/PieChartExperiments.java
software assignment/ChartS_v3/src/PieChartExperiments.java
import
java
.
util
.
Calendar
;
import
java
.
util
.
Date
;
import
javafx
.
application
.
Application
;
import
javafx
.
collections
.
FXCollections
;
import
javafx
.
event
.
ActionEvent
;
import
javafx
.
event
.
EventHandler
;
import
javafx
.
geometry
.
Pos
;
import
javafx
.
scene
.
Group
;
import
javafx
.
scene
.
Scene
;
import
javafx
.
scene
.
chart
.
Axis
;
import
javafx
.
scene
.
chart
.
PieChart
;
import
javafx
.
scene
.
chart
.
CategoryAxis
;
import
javafx
.
scene
.
chart
.
NumberAxis
;
import
javafx
.
scene
.
chart
.
XYChart
;
import
javafx
.
scene
.
control
.
ComboBox
;
import
javafx
.
scene
.
control
.
Tooltip
;
import
javafx
.
scene
.
layout
.
VBox
;
import
javafx
.
stage
.
Stage
;
public
class
PieChartExperiments
implements
Observer
{
String
department
=
"Furniture"
;
PieChart
pieChart
;
SalesData
data
;
Subject
subject
;
public
PieChartExperiments
(
SalesData
data
,
Subject
s
)
{
s
.
register
(
this
);
this
.
data
=
data
;
}
public
PieChart
createPieChart
()
{
pieChart
=
new
PieChart
();
pieChart
.
setTitle
(
"Year To Date Sales PieChart"
);
refresh
(
department
);
return
pieChart
;
}
public
void
refresh
(
String
department
)
{
String
[]
months
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
new
Date
());
int
month
=
cal
.
get
(
Calendar
.
MONTH
)
+
1
;
int
[]
totals
=
data
.
getYTDTotals
(
department
);
int
[]
totalSales
=
{
0
};
for
(
int
i
=
0
;
i
<
month
;
i
++
)
{
totalSales
[
0
]
+=
totals
[
i
];
}
PieChart
.
Data
[]
slices
=
new
PieChart
.
Data
[
month
];
pieChart
.
getData
().
clear
();
for
(
int
i
=
0
;
i
<
month
;
i
++
)
{
slices
[
i
]
=
new
PieChart
.
Data
(
months
[
i
],
totals
[
i
]);
pieChart
.
getData
().
add
(
slices
[
i
]);
}
pieChart
.
getData
().
forEach
(
data
->
{
String
percentage
=
String
.
format
(
"%.2f%%"
,
((
data
.
getPieValue
()
*
100
)
/
totalSales
[
0
]));
Tooltip
tool_Tip
=
new
Tooltip
(
percentage
);
Tooltip
.
install
(
data
.
getNode
(),
tool_Tip
);
});
}
}
software assignment/ChartS_v3/src/SaleItem.java
software assignment/ChartS_v3/src/SaleItem.java
public
class
SaleItem
{
private
String
dept
;
private
int
month
;
private
int
day
;
private
int
quantity
;
private
int
amount
;
public
String
getDepartment
()
{
return
dept
;
}
public
int
getMonth
()
{
return
month
;
}
public
int
getDay
()
{
return
day
;
}
public
String
getDept
()
{
return
dept
;
}
public
int
getQuantity
()
{
return
quantity
;
}
public
int
getAmount
()
{
return
amount
;
}
public
SaleItem
(
String
d
,
int
month
,
int
day
,
int
quantity
,
int
amount
)
{
dept
=
d
;
this
.
month
=
month
;
this
.
day
=
day
;
this
.
quantity
=
quantity
;
this
.
amount
=
amount
;
}
}
software assignment/ChartS_v3/src/SalesData.java
software assignment/ChartS_v3/src/SalesData.java
import
java
.
io
.
File
;
import
java
.
io
.
IOException
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Calendar
;
import
java
.
util
.
Date
;
import
java
.
util
.
Scanner
;
import
java
.
util
.
StringTokenizer
;
public
class
SalesData
{
ArrayList
<
SaleItem
>
allRows
;
String
department
=
"Furniture"
;
public
SalesData
(
String
fileName
)
{
allRows
=
new
ArrayList
<
SaleItem
>
();
Scanner
input
=
null
;
try
{
input
=
new
Scanner
(
new
File
(
fileName
));
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"File not found!"
);
}
while
(
input
.
hasNext
())
{
String
line
=
input
.
nextLine
();
StringTokenizer
st
=
new
StringTokenizer
(
line
,
","
);
String
s
=
st
.
nextToken
();
int
m
=
Integer
.
parseInt
(
st
.
nextToken
());
int
d
=
Integer
.
parseInt
(
st
.
nextToken
());
int
q
=
Integer
.
parseInt
(
st
.
nextToken
());
int
a
=
Integer
.
parseInt
(
st
.
nextToken
());
SaleItem
item
=
new
SaleItem
(
s
,
m
,
d
,
q
,
a
);
allRows
.
add
(
item
);
}
}
public
String
getDepartment
(){
return
department
;
}
public
void
setDepartment
(
String
d
){
department
=
d
;}
public
int
[]
getYTDTotals
(
String
department
)
{
int
[]
totals
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
for
(
int
i
=
0
;
i
<
12
;
i
++
)
{
totals
[
i
]
=
getMonthlyTotal
(
i
+
1
,
department
);
}
return
totals
;
}
public
int
getMonthlyTotal
(
int
month
,
String
department
)
{
int
total
=
0
;
ArrayList
<
SaleItem
>
result
=
getCurrentMonthTransactions
(
month
,
department
);
for
(
SaleItem
s
:
result
)
{
total
=
total
+
s
.
getAmount
();
}
return
total
;
}
public
ArrayList
getCurrentMonthTransactions
(
int
month
,
String
department
)
{
ArrayList
<
SaleItem
>
result
=
new
ArrayList
<
SaleItem
>
();
for
(
SaleItem
s
:
allRows
)
{
if
(
s
.
getDepartment
().
equals
(
department
)
&&
s
.
getMonth
()
==
month
)
{
result
.
add
(
s
);
}
}
return
result
;
}
}
software assignment/ChartS_v3/src/Subject.java
software assignment/ChartS_v3/src/Subject.java
public
interface
Subject
{
public
void
notifyObservers
();
public
void
register
(
Observer
obs
);
public
void
unRegister
(
Observer
obs
);
}
software assignment/ChartS_v3/src/TableExperiments.java
software assignment/ChartS_v3/src/TableExperiments.java
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Calendar
;
import
java
.
util
.
Date
;
import
java
.
util
.
List
;
import
javafx
.
application
.
Application
;
import
javafx
.
collections
.
FXCollections
;
import
javafx
.
collections
.
ObservableList
;
import
javafx
.
event
.
ActionEvent
;
import
javafx
.
event
.
EventHandler
;
import
javafx
.
geometry
.
Pos
;
import
javafx
.
scene
.
Scene
;
import
javafx
.
scene
.
chart
.
BarChart
;
import
javafx
.
scene
.
chart
.
CategoryAxis
;
import
javafx
.
scene
.
chart
.
NumberAxis
;
import
javafx
.
scene
.
chart
.
XYChart
;
import
javafx
.
scene
.
control
.
ComboBox
;
import
javafx
.
scene
.
control
.
TableColumn
;
import
javafx
.
scene
.
control
.
TableView
;
import
javafx
.
scene
.
control
.
cell
.
PropertyValueFactory
;
import
javafx
.
scene
.
layout
.
VBox
;
import
javafx
.
stage
.
Stage
;
public
class
TableExperiments
implements
Observer
{
String
department
;
TableView
<
SaleItem
>
table
;
SalesData
data
;
public
TableExperiments
(
SalesData
data
,
Subject
s
)
{
s
.
register
(
this
);
this
.
data
=
data
;
department
=
"Furniture"
;
}
public
TableView
createTableView
(){
table
=
new
TableView
<>
();
refresh
(
department
);
return
table
;
}
public
void
refresh
(
String
department
)
{
this
.
department
=
department
;
ObservableList
<
SaleItem
>
items
=
getInitialTableData
();
table
.
setItems
(
items
);
TableColumn
monthCol
=
new
TableColumn
(
"Month"
);
monthCol
.
setCellValueFactory
(
new
PropertyValueFactory
<
SaleItem
,
Integer
>
(
"month"
));
TableColumn
dayCOl
=
new
TableColumn
(
"Day"
);
dayCOl
.
setCellValueFactory
(
new
PropertyValueFactory
<
SaleItem
,
Integer
>
(
"day"
));
TableColumn
quanityCol
=
new
TableColumn
(
"Quantity"
);
quanityCol
.
setCellValueFactory
(
new
PropertyValueFactory
<
SaleItem
,
Integer
>
(
"quantity"
));
TableColumn
amountCol
=
new
TableColumn
(
"Amount"
);
amountCol
.
setCellValueFactory
(
new
PropertyValueFactory
<
SaleItem
,
Integer
>
(
"amount"
));
table
.
getColumns
().
setAll
(
monthCol
,
dayCOl
,
quanityCol
,
amountCol
);
table
.
setPrefWidth
(
450
);
table
.
setPrefHeight
(
300
);
table
.
setColumnResizePolicy
(
TableView
.
CONSTRAINED_RESIZE_POLICY
);
}
private
ObservableList
<
SaleItem
>
getInitialTableData
()
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
new
Date
());
int
month
=
cal
.
get
(
Calendar
.
MONTH
)
+
1
;
ArrayList
<
SaleItem
>
result
=
data
.
getCurrentMonthTransactions
(
month
,
department
);
ObservableList
<
SaleItem
>
list
=
FXCollections
.
observableList
(
result
);
return
list
;
}
}
software assignment/ChartS_v3/Transactions.dat
| Furniture | 1 | 1 | 2 | 200 |
| Furniture | 1 | 10 | 2 | 400 |
| Furniture | 1 | 15 | 2 | 400 |
| Furniture | 2 | 1 | 2 | 2000 |
| Furniture | 2 | 10 | 2 | 2000 |
| Furniture | 2 | 15 | 2 | 1000 |
| Furniture | 3 | 1 | 2 | 2000 |
| Furniture | 3 | 10 | 2 | 1000 |
| Furniture | 3 | 15 | 2 | 1000 |
| Furniture | 4 | 1 | 2 | 200 |
| Furniture | 4 | 10 | 2 | 400 |
| Furniture | 4 | 15 | 2 | 400 |
| Furniture | 5 | 1 | 2 | 2000 |
| Furniture | 5 | 1 | 2 | 2000 |
| Furniture | 5 | 1 | 2 | 2000 |
| Furniture | 6 | 10 | 2 | 2000 |
| Furniture | 6 | 15 | 2 | 2000 |
| Furniture | 6 | 1 | 2 | 1000 |
| Furniture | 6 | 2 | 2 | 4000 |
| Furniture | 7 | 10 | 2 | 200 |
| Furniture | 7 | 15 | 2 | 700 |
| Furniture | 7 | 1 | 2 | 100 |
| Furniture | 8 | 10 | 2 | 200 |
| Furniture | 8 | 15 | 2 | 200 |
| Furniture | 8 | 1 | 2 | 1600 |
| Furniture | 9 | 10 | 2 | 200 |
| Furniture | 9 | 15 | 2 | 200 |
| Furniture | 9 | 1 | 2 | 600 |
| Furniture | 10 | 10 | 2 | 1000 |
| Furniture | 10 | 15 | 2 | 2000 |
| Furniture | 10 | 1 | 2 | 1000 |
| Furniture | 11 | 10 | 2 | 200 |
| Furniture | 11 | 15 | 2 | 200 |
| Furniture | 11 | 1 | 2 | 800 |
| Furniture | 12 | 10 | 2 | 2000 |
| Furniture | 12 | 15 | 2 | 2000 |
| Furniture | 12 | 1 | 2 | 2000 |
| HardWare | 1 | 1 | 2 | 2000 |
| HardWare | 1 | 10 | 2 | 2000 |
| HardWare | 1 | 15 | 2 | 1000 |
| HardWare | 2 | 1 | 2 | 2000 |
| HardWare | 2 | 10 | 2 | 2000 |
| HardWare | 2 | 15 | 2 | 2000 |
| HardWare | 3 | 1 | 2 | 200 |
| HardWare | 3 | 10 | 2 | 1000 |
| HardWare | 3 | 15 | 2 | 800 |
| HardWare | 4 | 1 | 2 | 200 |
| HardWare | 4 | 10 | 2 | 400 |
| HardWare | 4 | 15 | 2 | 400 |
| HardWare | 5 | 1 | 2 | 200 |
| HardWare | 5 | 1 | 2 | 200 |
| HardWare | 5 | 1 | 2 | 600 |
| HardWare | 6 | 10 | 3 | 3000 |
| HardWare | 6 | 15 | 2 | 2000 |
| HardWare | 6 | 1 | 2 | 1000 |
| HardWare | 7 | 10 | 2 | 200 |
| HardWare | 7 | 15 | 2 | 700 |
| HardWare | 7 | 1 | 2 | 100 |
| HardWare | 8 | 10 | 2 | 200 |
| HardWare | 8 | 15 | 2 | 200 |
| HardWare | 8 | 1 | 2 | 600 |
| HardWare | 9 | 10 | 2 | 200 |
| HardWare | 9 | 15 | 2 | 200 |
| HardWare | 9 | 1 | 2 | 600 |
| HardWare | 10 | 10 | 2 | 2000 |
| HardWare | 10 | 15 | 2 | 2000 |
| HardWare | 10 | 1 | 2 | 2000 |
| HardWare | 11 | 10 | 2 | 1000 |
| HardWare | 11 | 15 | 2 | 200 |
| HardWare | 11 | 1 | 2 | 1800 |
| HardWare | 12 | 10 | 2 | 200 |
| HardWare | 12 | 15 | 2 | 200 |
| HardWare | 12 | 1 | 2 | 600 |
| Electronics | 1 | 1 | 2 | 200 |
| Electronics | 1 | 10 | 2 | 400 |
| Electronics | 1 | 15 | 2 | 400 |
| Electronics | 2 | 1 | 2 | 2000 |
| Electronics | 2 | 10 | 2 | 2000 |
| Electronics | 2 | 15 | 2 | 1000 |
| Electronics | 3 | 1 | 2 | 2000 |
| Electronics | 3 | 10 | 2 | 1000 |
| Electronics | 3 | 15 | 2 | 1000 |
| Electronics | 4 | 1 | 2 | 200 |
| Electronics | 4 | 10 | 2 | 400 |
| Electronics | 4 | 15 | 2 | 400 |
| Electronics | 5 | 1 | 2 | 200 |
| Electronics | 5 | 1 | 2 | 200 |
| Electronics | 5 | 1 | 2 | 600 |
| Electronics | 6 | 10 | 2 | 2000 |
| Electronics | 6 | 15 | 1 | 1000 |
| Electronics | 6 | 1 | 2 | 1000 |
| Electronics | 7 | 10 | 2 | 200 |
| Electronics | 7 | 15 | 2 | 700 |
| Electronics | 7 | 1 | 2 | 100 |
| Electronics | 8 | 10 | 2 | 1200 |
| Electronics | 8 | 15 | 2 | 1200 |
| Electronics | 8 | 1 | 2 | 1600 |
| Electronics | 9 | 10 | 2 | 200 |
| Electronics | 9 | 15 | 2 | 200 |
| Electronics | 9 | 1 | 2 | 600 |
| Electronics | 10 | 10 | 2 | 1000 |
| Electronics | 10 | 15 | 2 | 2000 |
| Electronics | 10 | 1 | 2 | 1000 |
| Electronics | 11 | 10 | 2 | 1000 |
| Electronics | 11 | 15 | 2 | 200 |
| Electronics | 11 | 1 | 2 | 1800 |
| Electronics | 12 | 10 | 2 | 200 |
| Electronics | 12 | 15 | 2 | 200 |
| Electronics | 12 | 1 | 2 | 600 |
software assignment/DepartmentSalesS_v3/.classpath
software assignment/DepartmentSalesS_v3/.project
DepartmentSalesS org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature
software assignment/DepartmentSalesS_v3/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8
software assignment/DepartmentSalesS_v3/bin/MonthlyReport.class
public synchronized class MonthlyReport extends javax.swing.JPanel implements Observer { private Report report; private SalesData data; public void MonthlyReport(Report, SalesData) throws Exception; public void refreshData(Observable); public void paintComponent(java.awt.Graphics); }
software assignment/DepartmentSalesS_v3/bin/Observable.class
public abstract interface Observable { public abstract void notifyObservers(); public abstract void register(Observer); public abstract void unRegister(Observer); }
software assignment/DepartmentSalesS_v3/bin/Observer.class
public abstract interface Observer { public abstract void refreshData(Observable); }
software assignment/DepartmentSalesS_v3/bin/PieChart.class
public synchronized class PieChart extends javax.swing.JPanel implements Observer { private Report report; private String department; private SalesData data; public void PieChart(Report, SalesData) throws Exception; public void refreshData(Observable); public void paintComponent(java.awt.Graphics); private void plotMonths(java.awt.Graphics); }
software assignment/DepartmentSalesS_v3/bin/Report$1.class
synchronized class Report$1 implements java.awt.event.ActionListener { void Report$1(Report, javax.swing.JComboBox); public void actionPerformed(java.awt.event.ActionEvent); }
software assignment/DepartmentSalesS_v3/bin/Report$2.class
synchronized class Report$2 implements java.awt.event.ActionListener { void Report$2(Report); public void actionPerformed(java.awt.event.ActionEvent); }
software assignment/DepartmentSalesS_v3/bin/Report.class
public synchronized class Report extends javax.swing.JPanel implements Observable { private java.util.ArrayList observersList; private String department; public void Report(); public void notifyObservers(); public void register(Observer); public void unRegister(Observer); public String getDepartment(); public void setDepartment(String); }
software assignment/DepartmentSalesS_v3/bin/SaleItem.class
public synchronized class SaleItem { private String dept; private int month; private int day; private int quantity; private int amount; public String getDepartment(); public int getMonth(); public int getDay(); public String getDept(); public int getQuantity(); public int getAmount(); public void SaleItem(String, int, int, int, int); }
software assignment/DepartmentSalesS_v3/bin/SalesData.class
public synchronized class SalesData { java.util.ArrayList allRows; String department; public void SalesData(String); public String getDepartment(); public void setDepartment(String); public int[] getYTDTotals(String); public int getMonthlyTotal(int, String); public java.util.ArrayList getCurrentMonthTransactions(int, String); }
software assignment/DepartmentSalesS_v3/bin/SupervisorView.class
public synchronized class SupervisorView { public void SupervisorView(); public static void main(String[]) throws Exception; }
software assignment/DepartmentSalesS_v3/bin/YTDChart.class
public synchronized class YTDChart extends javax.swing.JPanel implements Observer { private Report report; private String department; private SalesData data; public void YTDChart(Report, SalesData) throws Exception; public void refreshData(Observable); public void paintComponent(java.awt.Graphics); private void plotMonths(java.awt.Graphics); }
software assignment/DepartmentSalesS_v3/src/MonthlyReport.java
software assignment/DepartmentSalesS_v3/src/MonthlyReport.java
import
java
.
io
.
*
;
import
java
.
awt
.
*
;
import
javax
.
swing
.
*
;
import
java
.
util
.
*
;
public
class
MonthlyReport
extends
JPanel
implements
Observer
{
private
Report
report
;
private
SalesData
data
;
public
MonthlyReport
(
Report
r
,
SalesData
d
)
throws
Exception
{
report
=
r
;
data
=
d
;
report
.
register
(
this
);
}
public
void
refreshData
(
Observable
subject
)
{
repaint
();
}
public
void
paintComponent
(
Graphics
g
)
{
super
.
paintComponent
(
g
);
// get subject's state
String
department
=
report
.
getDepartment
();
g
.
drawString
(
"Current Month Transactions - "
+
department
,
50
,
20
);
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
new
Date
());
int
month
=
cal
.
get
(
Calendar
.
MONTH
)
+
1
;
ArrayList
<
SaleItem
>
trnList
=
data
.
getCurrentMonthTransactions
(
month
,
department
);
int
x
=
50
,
y
=
40
;
int
width
=
80
,
height
=
20
;
for
(
int
i
=
0
;
i
<
trnList
.
size
();
i
++
)
{
SaleItem
st
=
trnList
.
get
(
i
);
x
=
50
;
g
.
drawRect
(
x
,
y
,
width
,
height
);
g
.
drawString
(
" "
+
(
i
+
1
),
x
,
y
+
15
);
x
=
x
+
width
;
g
.
drawRect
(
x
,
y
,
width
,
height
);
g
.
drawString
(
" "
+
st
.
getMonth
()
+
"/"
+
st
.
getDay
(),
x
,
y
+
15
);
x
=
x
+
width
;
g
.
drawRect
(
x
,
y
,
width
,
height
);
g
.
drawString
(
" "
+
st
.
getQuantity
()
+
" Items"
,
x
,
y
+
15
);
x
=
x
+
width
;
g
.
drawRect
(
x
,
y
,
width
,
height
);
g
.
drawString
(
" $"
+
st
.
getAmount
(),
x
,
y
+
15
);
y
=
y
+
height
;
}
}
}
// end of class
software assignment/DepartmentSalesS_v3/src/Observable.java
software assignment/DepartmentSalesS_v3/src/Observable.java
public
interface
Observable
{
public
void
notifyObservers
();
public
void
register
(
Observer
obs
);
public
void
unRegister
(
Observer
obs
);
}
software assignment/DepartmentSalesS_v3/src/Observer.java
software assignment/DepartmentSalesS_v3/src/Observer.java
public
interface
Observer
{
public
void
refreshData
(
Observable
subject
);
}
software assignment/DepartmentSalesS_v3/src/PieChart.java
software assignment/DepartmentSalesS_v3/src/PieChart.java
import
java
.
io
.
*
;
import
java
.
awt
.
*
;
import
java
.
awt
.
event
.
*
;
import
javax
.
swing
.
*
;
import
com
.
sun
.
java
.
swing
.
plaf
.
windows
.
*
;
import
java
.
util
.
*
;
public
class
PieChart
extends
JPanel
implements
Observer
{
private
Report
report
;
private
String
department
=
"Furniture"
;
private
SalesData
data
;
public
PieChart
(
Report
r
,
SalesData
d
)
throws
Exception
{
this
.
report
=
r
;
data
=
d
;
report
.
register
(
this
);
}
public
void
refreshData
(
Observable
subject
)
{
if
(
subject
==
report
)
{
department
=
report
.
getDepartment
().
trim
();
repaint
();
}
}
public
void
paintComponent
(
Graphics
g
)
{
super
.
paintComponent
(
g
);
plotMonths
(
g
);
int
x
=
100
,
y
=
50
;
int
w
=
125
,
h
=
125
;
int
startAngle
=
0
,
arcAngle
=
0
;
int
[]
totals
=
data
.
getYTDTotals
(
department
);
Color
[]
colors
=
{
Color
.
red
,
Color
.
lightGray
,
Color
.
blue
,
Color
.
gray
,
Color
.
green
,
Color
.
black
,
Color
.
cyan
,
Color
.
magenta
,
Color
.
orange
,
Color
.
pink
,
Color
.
darkGray
,
Color
.
yellow
};
// current month
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
new
Date
());
int
month
=
cal
.
get
(
Calendar
.
MONTH
)
+
1
;
int
total
=
0
;
for
(
int
i
=
0
;
i
<
month
;
i
++
)
{
total
+=
totals
[
i
];
}
for
(
int
i
=
0
;
i
<
month
;
i
++
)
{
g
.
setColor
(
colors
[
i
]);
if
(
totals
[
i
]
>
0
)
{
arcAngle
=
(
int
)
((
totals
[
i
]
*
360
)
/
total
);
g
.
fillArc
(
x
+
50
,
65
,
w
,
h
,
startAngle
,
arcAngle
);
g
.
drawString
(
"$"
+
totals
[
i
],
x
,
y
);
}
y
+=
50
;
startAngle
+=
arcAngle
;
}
}
private
void
plotMonths
(
Graphics
g
)
{
g
.
drawString
(
department
+
"PieChart YTD"
,
150
,
20
);
String
[]
months
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
Color
[]
colors
=
{
Color
.
red
,
Color
.
lightGray
,
Color
.
blue
,
Color
.
gray
,
Color
.
green
,
Color
.
black
,
Color
.
cyan
,
Color
.
magenta
,
Color
.
orange
,
Color
.
pink
,
Color
.
darkGray
,
Color
.
yellow
};
int
x
=
50
,
y
=
50
;
for
(
int
j
=
0
;
j
<
months
.
length
;
j
++
)
{
g
.
setColor
(
colors
[
j
]);
g
.
drawString
(
months
[
j
],
x
,
y
);
y
+=
50
;
}
}
}
// end of class PieChart
software assignment/DepartmentSalesS_v3/src/Report.java
software assignment/DepartmentSalesS_v3/src/Report.java
import
javax
.
swing
.
JFrame
;
import
javax
.
swing
.
JPanel
;
import
java
.
awt
.
BorderLayout
;
import
javax
.
swing
.
JLabel
;
import
java
.
awt
.
FlowLayout
;
import
javax
.
swing
.
JComboBox
;
import
javax
.
swing
.
DefaultComboBoxModel
;
import
javax
.
swing
.
JButton
;
import
java
.
awt
.
event
.
ActionListener
;
import
java
.
awt
.
event
.
ActionEvent
;
import
java
.
util
.
ArrayList
;
public
class
Report
extends
JPanel
implements
Observable
{
public
Report
()
{
observersList
=
new
ArrayList
();
setLayout
(
new
FlowLayout
());
JLabel
lblNewLabel
=
new
JLabel
(
"Please select a department"
);
add
(
lblNewLabel
);
final
JComboBox
comboBox
=
new
JComboBox
();
comboBox
.
setModel
(
new
DefaultComboBoxModel
(
new
String
[]
{
"Furniture"
,
"HardWare"
,
"Electronics"
}));
add
(
comboBox
);
JButton
btnNewButton
=
new
JButton
(
"Ok"
);
btnNewButton
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
arg0
)
{
setDepartment
((
String
)
comboBox
.
getSelectedItem
());
notifyObservers
();
}
});
add
(
btnNewButton
);
JButton
btnNewButton_1
=
new
JButton
(
"Exit"
);
btnNewButton_1
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
e
)
{
System
.
exit
(
0
);
}
});
add
(
btnNewButton_1
);
department
=
"Furniture"
;
}
@
Override
public
void
notifyObservers
()
{
for
(
int
i
=
0
;
i
<
observersList
.
size
();
i
++
)
{
Observer
observer
=
(
Observer
)
observersList
.
get
(
i
);
observer
.
refreshData
(
this
);
}
}
@
Override
public
void
register
(
Observer
obs
)
{
observersList
.
add
(
obs
);
}
@
Override
public
void
unRegister
(
Observer
obs
)
{
// TODO Auto-generated method stub
}
private
ArrayList
observersList
;
public
String
getDepartment
()
{
return
department
;
}
public
void
setDepartment
(
String
department
)
{
this
.
department
=
department
;
}
private
String
department
;
}
software assignment/DepartmentSalesS_v3/src/SaleItem.java
software assignment/DepartmentSalesS_v3/src/SaleItem.java
public
class
SaleItem
{
private
String
dept
;
private
int
month
;
private
int
day
;
private
int
quantity
;
private
int
amount
;
public
String
getDepartment
()
{
return
dept
;
}
public
int
getMonth
()
{
return
month
;
}
public
int
getDay
()
{
return
day
;
}
public
String
getDept
()
{
return
dept
;
}
public
int
getQuantity
()
{
return
quantity
;
}
public
int
getAmount
()
{
return
amount
;
}
public
SaleItem
(
String
d
,
int
month
,
int
day
,
int
quantity
,
int
amount
)
{
dept
=
d
;
this
.
month
=
month
;
this
.
day
=
day
;
this
.
quantity
=
quantity
;
this
.
amount
=
amount
;
}
}
software assignment/DepartmentSalesS_v3/src/SalesData.java
software assignment/DepartmentSalesS_v3/src/SalesData.java
import
java
.
io
.
File
;
import
java
.
io
.
IOException
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Calendar
;
import
java
.
util
.
Date
;
import
java
.
util
.
Scanner
;
import
java
.
util
.
StringTokenizer
;
public
class
SalesData
{
ArrayList
<
SaleItem
>
allRows
;
String
department
=
"Furniture"
;
public
SalesData
(
String
fileName
)
{
allRows
=
new
ArrayList
<
SaleItem
>
();
Scanner
input
=
null
;
try
{
input
=
new
Scanner
(
new
File
(
fileName
));
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"File not found!"
);
}
while
(
input
.
hasNext
())
{
String
line
=
input
.
nextLine
();
StringTokenizer
st
=
new
StringTokenizer
(
line
,
","
);
String
s
=
st
.
nextToken
();
int
m
=
Integer
.
parseInt
(
st
.
nextToken
());
int
d
=
Integer
.
parseInt
(
st
.
nextToken
());
int
q
=
Integer
.
parseInt
(
st
.
nextToken
());
int
a
=
Integer
.
parseInt
(
st
.
nextToken
());
SaleItem
item
=
new
SaleItem
(
s
,
m
,
d
,
q
,
a
);
allRows
.
add
(
item
);
}
}
public
String
getDepartment
(){
return
department
;
}
public
void
setDepartment
(
String
d
){
department
=
d
;}
public
int
[]
getYTDTotals
(
String
department
)
{
int
[]
totals
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
for
(
int
i
=
0
;
i
<
12
;
i
++
)
{
totals
[
i
]
=
getMonthlyTotal
(
i
+
1
,
department
);
}
return
totals
;
}
public
int
getMonthlyTotal
(
int
month
,
String
department
)
{
int
total
=
0
;
ArrayList
<
SaleItem
>
result
=
getCurrentMonthTransactions
(
month
,
department
);
for
(
SaleItem
s
:
result
)
{
total
=
total
+
s
.
getAmount
();
}
return
total
;
}
public
ArrayList
getCurrentMonthTransactions
(
int
month
,
String
department
)
{
ArrayList
<
SaleItem
>
result
=
new
ArrayList
<
SaleItem
>
();
for
(
SaleItem
s
:
allRows
)
{
if
(
s
.
getDepartment
().
equals
(
department
)
&&
s
.
getMonth
()
==
month
)
{
result
.
add
(
s
);
}
}
return
result
;
}
}
software assignment/DepartmentSalesS_v3/src/SupervisorView.java
software assignment/DepartmentSalesS_v3/src/SupervisorView.java
import
java
.
awt
.
BorderLayout
;
import
java
.
awt
.
GridLayout
;
import
javax
.
swing
.
JFrame
;
import
javax
.
swing
.
JPanel
;
public
class
SupervisorView
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
JFrame
mainFrame
=
new
JFrame
();
mainFrame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
//Create the Subject
Report
objSubject
=
new
Report
();
mainFrame
.
add
(
objSubject
,
BorderLayout
.
NORTH
);
//Create Observers
JPanel
display
=
new
JPanel
();
display
.
setLayout
(
new
GridLayout
(
1
,
3
));
SalesData
data
=
new
SalesData
(
"Transactions.dat"
);
display
.
add
(
new
MonthlyReport
(
objSubject
,
data
));
display
.
add
(
new
YTDChart
(
objSubject
,
data
));
display
.
add
(
new
PieChart
(
objSubject
,
data
));
mainFrame
.
add
(
display
,
BorderLayout
.
CENTER
);
mainFrame
.
setSize
(
1500
,
900
);
mainFrame
.
setVisible
(
true
);
}
}
// end of class
software assignment/DepartmentSalesS_v3/src/YTDChart.java
software assignment/DepartmentSalesS_v3/src/YTDChart.java
import
java
.
io
.
*
;
import
java
.
awt
.
*
;
import
java
.
awt
.
event
.
*
;
import
javax
.
swing
.
*
;
import
com
.
sun
.
java
.
swing
.
plaf
.
windows
.
*
;
import
java
.
util
.
*
;
public
class
YTDChart
extends
JPanel
implements
Observer
{
private
Report
report
;
private
String
department
=
"Furniture"
;
private
SalesData
data
;
public
YTDChart
(
Report
r
,
SalesData
d
)
throws
Exception
{
this
.
report
=
r
;
data
=
d
;
report
.
register
(
this
);
}
public
void
refreshData
(
Observable
subject
)
{
if
(
subject
==
report
)
{
department
=
report
.
getDepartment
().
trim
();
repaint
();
}
}
public
void
paintComponent
(
Graphics
g
)
{
super
.
paintComponent
(
g
);
plotMonths
(
g
);
int
x
=
100
,
y
=
50
;
int
w
=
50
;
int
h
=
20
;
int
[]
totals
=
data
.
getYTDTotals
(
department
);
// current month
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
new
Date
());
int
month
=
cal
.
get
(
Calendar
.
MONTH
)
+
1
;
for
(
int
i
=
0
;
i
<
month
;
i
++
)
{
g
.
setColor
(
Color
.
blue
);
if
(
totals
[
i
]
>
0
)
{
w
=
(
int
)
(
totals
[
i
]
/
50
);
g
.
fillRect
(
x
,
y
,
w
,
h
);
g
.
drawString
(
"$"
+
totals
[
i
],
x
+
w
+
5
,
y
+
15
);
}
y
=
y
+
30
;
}
}
private
void
plotMonths
(
Graphics
g
)
{
g
.
drawString
(
department
+
" YTD Report"
,
150
,
20
);
String
[]
months
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
int
x
=
50
,
y
=
65
;
for
(
int
j
=
0
;
j
<
months
.
length
;
j
++
)
{
g
.
setColor
(
Color
.
blue
);
g
.
drawString
(
months
[
j
],
x
,
y
);
y
=
y
+
30
;
}
}
}
// end of class YTDChart
software assignment/DepartmentSalesS_v3/Transactions.dat
| Furniture | 1 | 1 | 2 | 200 |
| Furniture | 1 | 10 | 2 | 400 |
| Furniture | 1 | 15 | 2 | 400 |
| Furniture | 2 | 1 | 2 | 2000 |
| Furniture | 2 | 10 | 2 | 2000 |
| Furniture | 2 | 15 | 2 | 1000 |
| Furniture | 3 | 1 | 2 | 2000 |
| Furniture | 3 | 10 | 2 | 1000 |
| Furniture | 3 | 15 | 2 | 1000 |
| Furniture | 4 | 1 | 2 | 200 |
| Furniture | 4 | 10 | 2 | 400 |
| Furniture | 4 | 15 | 2 | 400 |
| Furniture | 5 | 1 | 2 | 2000 |
| Furniture | 5 | 1 | 2 | 2000 |
| Furniture | 5 | 1 | 2 | 2000 |
| Furniture | 6 | 10 | 2 | 2000 |
| Furniture | 6 | 15 | 2 | 2000 |
| Furniture | 6 | 1 | 2 | 1000 |
| Furniture | 6 | 2 | 2 | 4000 |
| Furniture | 7 | 10 | 2 | 200 |
| Furniture | 7 | 15 | 2 | 700 |
| Furniture | 7 | 1 | 2 | 100 |
| Furniture | 8 | 10 | 2 | 200 |
| Furniture | 8 | 15 | 2 | 200 |
| Furniture | 8 | 1 | 2 | 1600 |
| Furniture | 9 | 10 | 2 | 200 |
| Furniture | 9 | 15 | 2 | 200 |
| Furniture | 9 | 1 | 2 | 600 |
| Furniture | 10 | 10 | 2 | 1000 |
| Furniture | 10 | 15 | 2 | 2000 |
| Furniture | 10 | 1 | 2 | 1000 |
| Furniture | 11 | 10 | 2 | 200 |
| Furniture | 11 | 15 | 2 | 200 |
| Furniture | 11 | 1 | 2 | 800 |
| Furniture | 12 | 10 | 2 | 2000 |
| Furniture | 12 | 15 | 2 | 2000 |
| Furniture | 12 | 1 | 2 | 2000 |
| HardWare | 1 | 1 | 2 | 2000 |
| HardWare | 1 | 10 | 2 | 2000 |
| HardWare | 1 | 15 | 2 | 1000 |
| HardWare | 2 | 1 | 2 | 2000 |
| HardWare | 2 | 10 | 2 | 2000 |
| HardWare | 2 | 15 | 2 | 2000 |
| HardWare | 3 | 1 | 2 | 200 |
| HardWare | 3 | 10 | 2 | 1000 |
| HardWare | 3 | 15 | 2 | 800 |
| HardWare | 4 | 1 | 2 | 200 |
| HardWare | 4 | 10 | 2 | 400 |
| HardWare | 4 | 15 | 2 | 400 |
| HardWare | 5 | 1 | 2 | 200 |
| HardWare | 5 | 1 | 2 | 200 |
| HardWare | 5 | 1 | 2 | 600 |
| HardWare | 6 | 10 | 3 | 3000 |
| HardWare | 6 | 15 | 2 | 2000 |
| HardWare | 6 | 1 | 2 | 1000 |
| HardWare | 7 | 10 | 2 | 200 |
| HardWare | 7 | 15 | 2 | 700 |
| HardWare | 7 | 1 | 2 | 100 |
| HardWare | 8 | 10 | 2 | 200 |
| HardWare | 8 | 15 | 2 | 200 |
| HardWare | 8 | 1 | 2 | 600 |
| HardWare | 9 | 10 | 2 | 200 |
| HardWare | 9 | 15 | 2 | 200 |
| HardWare | 9 | 1 | 2 | 600 |
| HardWare | 10 | 10 | 2 | 2000 |
| HardWare | 10 | 15 | 2 | 2000 |
| HardWare | 10 | 1 | 2 | 2000 |
| HardWare | 11 | 10 | 2 | 1000 |
| HardWare | 11 | 15 | 2 | 200 |
| HardWare | 11 | 1 | 2 | 1800 |
| HardWare | 12 | 10 | 2 | 200 |
| HardWare | 12 | 15 | 2 | 200 |
| HardWare | 12 | 1 | 2 | 600 |
| Electronics | 1 | 1 | 2 | 200 |
| Electronics | 1 | 10 | 2 | 400 |
| Electronics | 1 | 15 | 2 | 400 |
| Electronics | 2 | 1 | 2 | 2000 |
| Electronics | 2 | 10 | 2 | 2000 |
| Electronics | 2 | 15 | 2 | 1000 |
| Electronics | 3 | 1 | 2 | 2000 |
| Electronics | 3 | 10 | 2 | 1000 |
| Electronics | 3 | 15 | 2 | 1000 |
| Electronics | 4 | 1 | 2 | 200 |
| Electronics | 4 | 10 | 2 | 400 |
| Electronics | 4 | 15 | 2 | 400 |
| Electronics | 5 | 1 | 2 | 200 |
| Electronics | 5 | 1 | 2 | 200 |
| Electronics | 5 | 1 | 2 | 600 |
| Electronics | 6 | 10 | 2 | 2000 |
| Electronics | 6 | 15 | 1 | 1000 |
| Electronics | 6 | 1 | 2 | 1000 |
| Electronics | 7 | 10 | 2 | 200 |
| Electronics | 7 | 15 | 2 | 700 |
| Electronics | 7 | 1 | 2 | 100 |
| Electronics | 8 | 10 | 2 | 1200 |
| Electronics | 8 | 15 | 2 | 1200 |
| Electronics | 8 | 1 | 2 | 1600 |
| Electronics | 9 | 10 | 2 | 200 |
| Electronics | 9 | 15 | 2 | 200 |
| Electronics | 9 | 1 | 2 | 600 |
| Electronics | 10 | 10 | 2 | 1000 |
| Electronics | 10 | 15 | 2 | 2000 |
| Electronics | 10 | 1 | 2 | 1000 |
| Electronics | 11 | 10 | 2 | 1000 |
| Electronics | 11 | 15 | 2 | 200 |
| Electronics | 11 | 1 | 2 | 1800 |
| Electronics | 12 | 10 | 2 | 200 |
| Electronics | 12 | 15 | 2 | 200 |
| Electronics | 12 | 1 | 2 | 600 |