-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrailerAxlesPanel.java
More file actions
executable file
·98 lines (74 loc) · 2.67 KB
/
TrailerAxlesPanel.java
File metadata and controls
executable file
·98 lines (74 loc) · 2.67 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* @(#)TrailerAxlesPanel.java
*
*
* @Derick Warshaw // Lab 12 // COSC1337
* @version 1.00 2014/4/24
*/
import javax.swing.*;
import java.awt.*;
/**The TrailerAxlesPanel class allows the user to select how many axles the
*trailer has */
public class TrailerAxlesPanel extends JPanel
{
private JRadioButton zeroTrailerAxleButton; // select 0 trailer axle
private JRadioButton oneTrailerAxleButton; // select 1 trailer axle
private JRadioButton twoTrailerAxleButton; // select 2 trailer axle
private JRadioButton threeTrailerAxleButton;// select 3 trailer axle
private ButtonGroup trailerAxlesGroup; // radio button group
/**TrailerAxlesPanel Constructor performs setup operations */
public TrailerAxlesPanel()
{
// grid layout
setLayout(new GridLayout(4,1));
// create radio buttons with 0 axles being the default
zeroTrailerAxleButton = new JRadioButton("0 ", true);
oneTrailerAxleButton = new JRadioButton("1 ");
twoTrailerAxleButton = new JRadioButton("2 ");
threeTrailerAxleButton = new JRadioButton("3 or more ");
// add radio buttons to group
trailerAxlesGroup = new ButtonGroup();
trailerAxlesGroup.add(zeroTrailerAxleButton);
trailerAxlesGroup.add(oneTrailerAxleButton);
trailerAxlesGroup.add(twoTrailerAxleButton);
trailerAxlesGroup.add(threeTrailerAxleButton);
// add a border around the panel
setBorder(BorderFactory.createTitledBorder("Trailer Axles"));
//add the radio buttons to the panel
add(zeroTrailerAxleButton);
add(oneTrailerAxleButton);
add(twoTrailerAxleButton);
add(threeTrailerAxleButton);
}
/**The getVehicleAxleCost method determines how much to charge
*@returns cost is a fee
* */
public double getTrailerAxleCost()
{
// constant variables for toll values
final double TRAILER_AXLES_0 = 0.00;
final double TRAILER_AXLES_1 = 0.25;
final double TRAILER_AXLES_2 = 0.50;
final double TRAILER_AXLES_3_OR_MORE = 0.75;
// cost holds a calculated value based on number of axles selected
double cost = 0.0;
// determining which toll rate to apply based on number of axles
if(zeroTrailerAxleButton.isSelected())
{
cost = TRAILER_AXLES_0;
}
else if(oneTrailerAxleButton.isSelected())
{
cost = TRAILER_AXLES_1;
}
else if(twoTrailerAxleButton.isSelected())
{
cost = TRAILER_AXLES_2;
}
else if(threeTrailerAxleButton.isSelected())
{
cost = TRAILER_AXLES_3_OR_MORE;
}
return cost;
}
}