首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导Programming程序、Java编程语言讲解 调试Matlab程序|辅导R语言程序
项目预算:
开发周期:
发布时间:
要求地区:
Applications Programming
Lab - MVC (worth 8%)
The process:
1. Create the application class.
2. Create the view in FXML.
3. Create the controller in Java.
4. Modify the model to support JavaFX properties.
5. Implement the event handlers.
Tutor demo
Main class: StadiumApplication
Make an application that sells seats in a stadium. The seats are divided into different groups and
each seat group has a different price and capacity. In this simple application, the stadium has only
one group of "front" seats. There are 300 front seats with a price of $400 per seat. The user
interface is shown below:
The user enters a number into the Sell TextField and presses "Sell". The figures are updated to
reflect the sale, and the Sell TextField is reset to zero.
Your tutor will code the solution.
Note: Your tutor may demonstrate bindings with code like this:
income.bind(sold.multiply(price));
Another way to create bindings is through the Bindings class:
income.bind(Bindings.multiply(sold, price));
Read the documentation for the Bindings class here.
Student Specification
Main class: StoreApplication
Make a graphical user interface for the program you developed in the earlier classes lab: a store.
The store has one product and a cash register. The product is "Sticky Tape". Initially there are 200
items of this product in stock, and they sell for $2.99 each. The user interface is as follows:
The user can input the number of items to sell. Clicking the "Sell" button will sell that number of
items and reset the Sell TextField to zero. All figures are updated to reflect the sale. The stock is
shown as "XYZ items" where XYZ is replaced by the stock property from the model. The price is
displayed with a dollar sign to two decimal places, and so is the cash in the cash register.
Step 1. Open the lecture notes. You will need them as a reference. You may also refer to
the tutor demo (downloadable from ED) and the lecture demo (downloadable from
Canvas/Modules/ Subject Documents).
Step 2. Create a new JavaFX project in NetBeans IDE called "Lab9_2021AUT". If you
have a preferred IDE, you may use it instead, as long as it supports Java 8 and allows
projects to include non-Java files such as XML, CSS and PNG files.
NOTE: NetBeans will offer to automatically create a main class for you. Do not accept the
offer since you will create the classes later by hand. But if you do accept the offer, please
note:
1. The suggested class name should be changed to StoreApplication
2. The class should NOT be placed inside the suggested package, so you will need to
delete the package name.
Step 3. Copy and paste the following code as a template for your StoreApplication class:
public class StoreApplication extends Application {
public static void main(String[] args) { launch(args); }
@Override
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("store.fxml"));
// Add code here to load the root node from the FXML file
// and show it
}
}
Don't forget to import the required classes.
Step 4. Create an fxml file called "store.fxml" in the same directory as your StoreApplication
class. Add code to this file to define the layout exactly as shown in the screenshot above.
Note: everything in the left column is a label. The right column consists of Text nodes for
Product, Stock, Price and Cash and a TextField for Sell. The Sell button is aligned right.
Step 5. Define a controller class called StoreController and declare the name of this
controller class in your store.fxml file to link it to this controller. Use the following code as a
template for your StoreController class:
public class StoreController {
@FXML private Button sellBtn;
@FXML private Text stockTxt;
@FXML private Text priceTxt;
@FXML private TextField amountTf;
@FXML private Text cashTxt;
}
For each of these @FXML fields, modify the corresponding XML definition for this node in the
store.fxml file to include an fx:id attribute that links it to the corresponding field above. Note
that amountTf is the text field appearing after the Sell label.
Run your application to make sure it still works. Fix any errors reported.
Step 6. Create the model classes for Store, Product and CashRegister. You can use the
solutions from last week's lecture which are included below.
Copy the following code into a new interface called ProductObserver
public interface ProductObserver {
void handleSale(double amount);
}
Copy the following code into a new class called CashRegister
public class CashRegister implements ProductObserver {
private double cash;
public CashRegister() {
cash = 0.0;
}
public void add(double money) {
cash = cash + money;
}
@Override
public void handleSale(double amount) {
add(amount);
}
}
Copy the following code into a new class called Product
public class Product {
private LinkedList
observers = new LinkedList
();
private String name;
private int stock;
private double price;
public Product(String name, int stock, double price) {
this.name = name;
this.stock = stock;
this.price = price;
}
public void sell(int n) {
stock = stock - n;
double money = n * price;
for (ProductObserver observer : observers)
observer.handleSale(money);
}
public void restock(int n) {
stock = stock + n;
}
public boolean has(int n) {
return stock >= n;
}
public void addProductObserver(ProductObserver observer) {
observers.add(observer);
}
@Override
public String toString() {
return stock + " " + name + " at $" + price;
}
}
Copy the following code into a new class called Store:
public class Store {
private CashRegister cashRegister;
private Product product;
public Store() {
cashRegister = new CashRegister();
product = new Product("Sticky tape", 200, 2.99);
product.addProductObserver(cashRegister);
}
}
Step 7. Modify the controller and your model classes to expose JavaFX properties according
to the JavaFX property patterns. Refer to the 4 patterns from the lecture:
1. Pattern #1: Immutable property
2. Pattern #2: Read Write property
3. Pattern #3: Read Only property
4. Pattern #4: Immutable property with mutable state
For example, the name of a product never changes so it is an immutable property. It looks
like this:
public class Product {
private String name;
...
public final String getName() { return name; }
}
Step 8. Now bind each Text node in your view to the model:
1. For the Product name, use an FXML property binding expression, i.e. ${.....}.
NOTE! Some students have reported that FXML binding expressions don't work on a
Mac. If that is the case, you have permission to do the bindings in Java code rather
than FXML code.
For example, the lecture demo example (which you can download from Canvas /
Modules /Subject Documents), you saw this code:
nameTf.textProperty().bindBidirectional(customer.getAccount().nameProperty());
However, in this case, you want to do a unidirectional binding:
nameTf.textProperty().bind(customer.getAccount().nameProperty());
Replace nameTf by the node in your scene representing the product name. Because
you want to refer to this from your Java code, you'll need to inject the node into your
controller:
@FXML private Text nameTxt;
You should also modify customer.getAccount().nameProperty() to refer to the name
property of the product.
2. For the Stock, do a binding in Java code so that the string " items" appears after the
stock number (see the lecture notes for an example)
3. For the Price and Cash, do a binding in Java code so that the price is displayed as
currency with a dollar sign and 2 decimal places.
Run your application to verify that all of the current product data is displayed.
Step 9. Set the initial contents of amountTf to just the number 0.
Step 10. In FXML, add an attribute on your Button node to specify the name of a Java
method to handle the button click. Name this method handleSell. Write a corresponding
method in your controller class that is linked to this action (see the lecture notes for an
example). In this method, write code to perform the sale, but ONLY if there is enough stock.
After performing the sale, set the contents of amountTf back to 0. Test your application to
ensure that the button works. When you click it, the sale happens, and the data is
automatically updated in the view.
Step 11. This is an assessed lab. Copy and paste the source codes and fxml codes to ED.
Step 12. Peer marking submission on Canvas. The instruction is specified here.
NOTE: After you submit the source files to ED, you will not receive your mark immediately. It is
not possible for ED to mark a GUI automatically since a user is required to use a mouse to
drive the program. Therefore, this lab will be manually marked by peer marking. You should
submit a JAR file to Canvas by the due date to participate the peer marking. Late submission
will be excluded from peer marking activities and result 50% mark deduction.
Marking Scheme
All leaf nodes are shown 10%
All nodes are laid out correctly in a grid 10%
The Sell button is correctly aligned right 5%
The product name, stock, price and cash values are shown 20%
The stock, price and cash values are formatted correctly 20%
After clicking Sell, the stock is correctly updated in the view 10%
After clicking Sell, the cash is correctly updated in the view 10%
After clicking Sell, the sell amount is reset to 0 10%
Clicking Sell does nothing if there is not enough stock 5%
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!