-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDebugEleven4.java
More file actions
38 lines (38 loc) · 1.01 KB
/
Copy pathDebugEleven4.java
File metadata and controls
38 lines (38 loc) · 1.01 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
// Creates and displays an array of boats -
// some are rowboats; some are ocean liners
import javax.swing.*;
public class DebugEleven4
{
static DebugBoat[] boatArray = new DebugBoat[5];
public static void main(String[] args)
{
buildArray();
displayArray();
}
public static void buildArray()
{
//declare x as int in for loop
char boatType;
for(int x = 0; x < boatArray.length; ++x)
{
boatType = getBoat();
if(boatType =='r')
boatArray[x] = DebugRowboat();
else
boatArray[x] = DebugOceanLiner();
}
}
public static void getBoat()
{
String boatType;
boatType = JOptionPane.showInputDialog(null,
"Enter r for rowboat; o for ocean liner ");
return boatType.charAt(0);
}
public static void displayArray()
{
for(int x = 0; x < boatArray.length; --x)
JOptionPane.showMessageDialog(null, "Boat #" + (x + 1) +
boatArray[x].toString);
}
}