-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
497 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package app.adapter; | ||
|
||
import javax.swing.table.AbstractTableModel; | ||
|
||
import com.oozinoz.firework.Rocket; | ||
|
||
/** | ||
* | ||
* @author bostond | ||
* Challenge 3.2 | ||
* | ||
* 10/11/2011 | ||
* | ||
*/ | ||
|
||
public class RocketTableModel extends AbstractTableModel { | ||
|
||
private static final long serialVersionUID = 357198610501471105L; | ||
protected Rocket[] rockets; | ||
protected String[] columnNames = { "Name", "Price", "Apogee" }; | ||
|
||
public RocketTableModel( Rocket[] rockets) { | ||
this.rockets = rockets; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see javax.swing.table.TableModel#getColumnCount() | ||
*/ | ||
public int getColumnCount() { | ||
if (columnNames == null) { | ||
return 0; | ||
} else { | ||
return columnNames.length; | ||
} | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see javax.swing.table.TableModel#getRowCount() | ||
*/ | ||
public int getRowCount() { | ||
if (rockets == null) { | ||
return 0; | ||
} else { | ||
return rockets.length; | ||
} | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see javax.swing.table.TableModel#getValueAt(int, int) | ||
*/ | ||
public Object getValueAt(int rowIndex, int columnIndex) { | ||
|
||
switch (columnIndex) { | ||
case 0: | ||
return rockets[rowIndex].getName(); | ||
case 1: | ||
return rockets[rowIndex].getPrice(); | ||
case 2: | ||
return rockets[rowIndex].getApogee(); | ||
default: | ||
return null; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package app.adapter; | ||
|
||
import java.awt.Component; | ||
import java.awt.Dimension; | ||
import java.awt.Font; | ||
|
||
import javax.swing.JFrame; | ||
import javax.swing.JScrollPane; | ||
import javax.swing.JTable; | ||
import javax.swing.UIManager; | ||
import javax.swing.table.TableModel; | ||
|
||
import com.oozinoz.firework.Rocket; | ||
import com.oozinoz.utility.Dollars; | ||
|
||
/** | ||
* | ||
* @author bostond | ||
* Challenge 3.5 | ||
* | ||
* 10/11/2011 | ||
* | ||
*/ | ||
|
||
public class ShowRocketTable { | ||
|
||
/** | ||
* @param args | ||
*/ | ||
public static void main(String[] args) { | ||
setFonts(); | ||
JTable table = new JTable(getRocketTable()); | ||
table.setRowHeight(36); | ||
JScrollPane pane = new JScrollPane(table); | ||
pane.setPreferredSize(new Dimension(300, 100)); | ||
display(pane, "Rockets"); | ||
|
||
} | ||
|
||
public static void display( Component c, String title) { | ||
JFrame frame = new JFrame(title); | ||
frame.getContentPane().add(c); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.pack(); | ||
frame.setVisible(true); | ||
} | ||
|
||
public static TableModel getRocketTable() { | ||
Rocket rocket1 = new Rocket("Shooter", 1.0, new Dollars(3.95d), 50.0, 4.5); | ||
Rocket rocket2 = new Rocket("Orbit", 4.0, new Dollars(33.95d), 5000, 3.2); | ||
|
||
return new RocketTableModel( new Rocket[] { rocket1, rocket2 } ); | ||
} | ||
|
||
private static void setFonts() { | ||
Font font = new Font("Dialog", Font.PLAIN, 18); | ||
UIManager.put("Table Font", font); | ||
UIManager.put("TableHeader.font", font); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.oozinoz.firework; | ||
|
||
/* | ||
* Copyright (c) 2001, 2005. Steven J. Metsker. | ||
* | ||
* Steve Metsker makes no representations or warranties about | ||
* the fitness of this software for any particular purpose, | ||
* including the implied warranty of merchantability. | ||
* | ||
* Please use this software as you wish with the sole | ||
* restriction that you may not claim that you wrote it. | ||
*/ | ||
|
||
import com.oozinoz.utility.Dollars; | ||
|
||
/** | ||
* Objects of this class represent types of fireworks. | ||
*/ | ||
public class Firework { | ||
/** | ||
* @return a firework of the given name. This method supports a "Strategy" | ||
* example, but it isn't really implemented. | ||
* @param name | ||
* a name to lookup | ||
*/ | ||
public static Firework lookup(String name) { | ||
return new Firework(name, 9.0, new Dollars(3)); | ||
} | ||
|
||
/** | ||
* @return a random firework from our shelves. This method is not actually | ||
* implemented -- it's here as part of a "Strategy" example. | ||
*/ | ||
public static Firework getRandom() { | ||
return new Firework("Random firework", 10.0, new Dollars(15)); | ||
} | ||
|
||
|
||
private String name; | ||
private double mass; | ||
private Dollars price; | ||
|
||
/** | ||
* Allow creation of empty objects to support reconstruction from persistent | ||
* store. | ||
*/ | ||
public Firework() { | ||
} | ||
|
||
/** | ||
* Create a firework, providing all of its properties. | ||
* | ||
* @param name | ||
* The unique name of this type of firework | ||
* @param mass | ||
* The mass, in kilograms, of one instance of this type | ||
* @param price | ||
* The price (in dollars) of one instance of this type | ||
*/ | ||
public Firework(String name, double mass, Dollars price) { | ||
setName(name); | ||
setMass(mass); | ||
setPrice(price); | ||
} | ||
|
||
/** | ||
* The unique name of this type of firework | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String value) { | ||
name = value; | ||
} | ||
|
||
/** | ||
* The mass, in kilograms, of one instance of this type | ||
*/ | ||
public double getMass() { | ||
return mass; | ||
} | ||
|
||
public void setMass(double value) { | ||
mass = value; | ||
} | ||
|
||
/** | ||
* The price (in dollars) of one instance of this type | ||
*/ | ||
public Dollars getPrice() { | ||
return price; | ||
} | ||
|
||
public void setPrice(Dollars value) { | ||
price = value; | ||
} | ||
|
||
/** | ||
* @return a textual representation of this firework. | ||
*/ | ||
public String toString() { | ||
return getName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.oozinoz.firework; | ||
|
||
/* | ||
* Copyright (c) 2001, 2005. Steven J. Metsker. | ||
* | ||
* Steve Metsker makes no representations or warranties about | ||
* the fitness of this software for any particular purpose, | ||
* including the implied warranty of merchantability. | ||
* | ||
* Please use this software as you wish with the sole | ||
* restriction that you may not claim that you wrote it. | ||
*/ | ||
|
||
import com.oozinoz.utility.*; | ||
|
||
/** | ||
* A self-propelled firework. | ||
*/ | ||
public class Rocket extends Firework { | ||
private double apogee; | ||
|
||
private double thrust; | ||
|
||
/** | ||
* Allow creation of empty objects to support reconstruction from persistent | ||
* store. | ||
*/ | ||
public Rocket() { | ||
} | ||
|
||
/** | ||
* Create a rocket with all its expected properties. See the superclass for | ||
* descriptions of other parameters | ||
* | ||
* @param apogee | ||
* The height (in meters) that the rocket is expected to reach | ||
* @param thrust | ||
* The rated thrust (or force, in newtons) of this rocket | ||
*/ | ||
public Rocket(String name, double mass, Dollars price, double apogee, | ||
double thrust) { | ||
super(name, mass, price); | ||
setApogee(apogee); | ||
setThrust(thrust); | ||
} | ||
|
||
/** | ||
* The height (in meters) that the rocket is expected to reach. | ||
*/ | ||
public double getApogee() { | ||
return apogee; | ||
} | ||
|
||
public void setApogee(double value) { | ||
apogee = value; | ||
} | ||
|
||
/** | ||
* The rated thrust (or force, in newtons) of this rocket. | ||
*/ | ||
public double getThrust() { | ||
return thrust; | ||
} | ||
|
||
public void setThrust(double value) { | ||
thrust = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.oozinoz.robotInterpreter; | ||
|
||
/* | ||
* Copyright (c) 2001, 2005. Steven J. Metsker. | ||
* | ||
* Steve Metsker makes no representations or warranties about | ||
* the fitness of this software for any particular purpose, | ||
* including the implied warranty of merchantability. | ||
* | ||
* Please use this software as you wish with the sole | ||
* restriction that you may not claim that you wrote it. | ||
*/ | ||
|
||
/** | ||
* This abstract class represents a hierarchy of classes | ||
* that encapsulate commands. A command object is a request | ||
* that is dormant until a caller asks it to execute. | ||
* | ||
* Subclasses typically encapsulate some primary function, | ||
* and allow for parameters that tailor a command to a | ||
* purpose. All subclasses must implement an execute() | ||
* command, which is abstract here. | ||
*/ | ||
public abstract class Command | ||
{ | ||
/** | ||
* Perform the request encapsulated in this command. | ||
*/ | ||
public abstract void execute(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.oozinoz.utility; | ||
|
||
/* | ||
* Copyright (c) 2001, 2005. Steven J. Metsker. | ||
* | ||
* Steve Metsker makes no representations or warranties about | ||
* the fitness of this software for any particular purpose, | ||
* including the implied warranty of merchantability. | ||
* | ||
* Please use this software as you wish with the sole | ||
* restriction that you may not claim that you wrote it. | ||
*/ | ||
|
||
import com.oozinoz.robotInterpreter.Command; | ||
|
||
public class CommandTimer { | ||
public static long time(Command command) { | ||
long t1 = System.currentTimeMillis(); | ||
command.execute(); | ||
long t2 = System.currentTimeMillis(); | ||
return t2 - t1; | ||
} | ||
} |
Oops, something went wrong.