Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Annuity/Annuity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.lang.Math;
public class Annuity
{
/** description of instance variable x (add comment for each instance variable) */
public static final long PERIODIC_PAYMENT = 10000;
public static final double COMPOUND_RATE = .08;
public static final long NUM_PAYMENTS = 20;

public static double calculateAnnuity ()
{
double numerator = (Math.pow((1+COMPOUND_RATE), (NUM_PAYMENTS-1)) - 1) / COMPOUND_RATE;
double denom = (Math.pow((1+COMPOUND_RATE), (NUM_PAYMENTS-1)));
return PERIODIC_PAYMENT*((numerator/denom)+1);
}

}
13 changes: 13 additions & 0 deletions Annuity/README.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
------------------------------------------------------------------------
This is the project README file. Here, you should describe your project.
Tell the reader (someone who does not know anything about this project)
all she needs to know. The comments should usually include at least:
------------------------------------------------------------------------

PROJECT TITLE:
PURPOSE OF PROJECT:
VERSION or DATE:
DEPENDENCIES:
HOW TO START THIS PROJECT:
AUTHORS:
USER INSTRUCTIONS:
24 changes: 24 additions & 0 deletions Annuity/package.bluej
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#BlueJ package file
objectbench.height=76
objectbench.width=1660
package.editor.height=854
package.editor.width=1562
package.editor.x=-8
package.editor.y=-8
package.numDependencies=0
package.numTargets=1
package.showExtends=true
package.showUses=true
project.charset=UTF-8
target1.editor.height=700
target1.editor.width=900
target1.editor.x=759
target1.editor.y=291
target1.height=50
target1.name=Annuity
target1.showInterface=false
target1.type=ClassTarget
target1.typeParameters=
target1.width=80
target1.x=70
target1.y=10
1 change: 1 addition & 0 deletions AvgOfThree/AvgOfThree.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void main (String[] args)
System.out.print ("Enter the first number: ");
a = s.nextDouble();


System.out.print ("Enter the second number: ");
b = s.nextDouble();

Expand Down
18 changes: 9 additions & 9 deletions AvgOfThree/package.bluej
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#BlueJ package file
objectbench.height=100
objectbench.width=658
package.editor.height=400
package.editor.width=560
package.editor.x=30
package.editor.y=30
objectbench.width=1355
package.editor.height=830
package.editor.width=1562
package.editor.x=-8
package.editor.y=-8
package.numDependencies=0
package.numTargets=1
package.showExtends=true
Expand All @@ -14,10 +14,10 @@ readme.editor.height=700
readme.editor.width=900
readme.editor.x=0
readme.editor.y=22
target1.editor.height=700
target1.editor.width=900
target1.editor.x=70
target1.editor.y=50
target1.editor.height=1026
target1.editor.width=1696
target1.editor.x=-8
target1.editor.y=-8
target1.height=50
target1.name=AvgOfThree
target1.naviview.expanded=false
Expand Down
22 changes: 22 additions & 0 deletions CityscapeLab/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
43 changes: 43 additions & 0 deletions CityscapeLab/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
Expand Down
59 changes: 59 additions & 0 deletions CityscapeLab/Building.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.Color;
import java.util.Random;
import java.awt.Graphics2D;
/**
* Class that defines a building with starting positions, height, and width.
*
* @author Christopher Ng
* @version 2 October 2014
*/
public class Building
{
/** int specifying building's height */
private int windowHeight;
/** int specifying building's width */
private int width;
/**int specifying leftmost coordinate */
private int xleft;
/** int specifying top coordinate */
private int ytop;
/** int for storing height of the hill object in CityScape */
private int hillHeight;
/**
* Default constructor for objects of class Building
* @param windowHeight the height of the JFrame window
* @param width width of the building
* @param xleft starting x position
* @param ytop starting y position
*/
public Building(int xleft, int ytop, int width, int windowHeight)
{
this.windowHeight = windowHeight;
this.width = width;
this.xleft = xleft;
this.ytop = ytop;
}

public void setHillHeight(int hillHeight)
{
this.hillHeight = hillHeight;
}

/**
* Draws a building based on variables initialized in constructor
*/
public void draw(Graphics2D g2)
{
Rectangle mainBuilding = new Rectangle(xleft, ytop, width, windowHeight-ytop-hillHeight);
g2.setColor(Color.GRAY);
g2.draw(mainBuilding);
g2.fill(mainBuilding);

}


}


40 changes: 40 additions & 0 deletions CityscapeLab/Bus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


/**
* Write a description of class Bus here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bus
{
/** description of instance variable x (add comment for each instance variable) */
private int x;

/**
* Default constructor for objects of class Bus
*/
public Bus()
{
// initialise instance variables
x = 0;
}

/**
* An example of a method - replace this comment with your own
* that describes the operation of the method
*
* @pre preconditions for the method
* (what the method assumes about the method's parameters and class's state)
* @post postconditions for the method
* (what the method guarantees upon completion)
* @param y description of parameter y
* @return description of the return value
*/
public int sampleMethod(int y)
{
// put your code here
return x+y;
}

}
40 changes: 40 additions & 0 deletions CityscapeLab/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


/**
* Write a description of class Car here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Car
{
/** description of instance variable x (add comment for each instance variable) */
private int x;

/**
* Default constructor for objects of class Car
*/
public Car()
{
// initialise instance variables
x = 0;
}

/**
* An example of a method - replace this comment with your own
* that describes the operation of the method
*
* @pre preconditions for the method
* (what the method assumes about the method's parameters and class's state)
* @post postconditions for the method
* (what the method guarantees upon completion)
* @param y description of parameter y
* @return description of the return value
*/
public int sampleMethod(int y)
{
// put your code here
return x+y;
}

}
38 changes: 28 additions & 10 deletions CityscapeLab/CityscapeComponent.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
import java.util.Random;

/**
* Class that creates instances of the classes that comprise the cityscape and delegates drawing the
Expand All @@ -11,6 +12,7 @@
*/
public class CityscapeComponent extends JComponent
{
public static boolean isNight=true;
/**
* An example of a method - replace this comment with your own
* that describes the operation of the method
Expand All @@ -21,17 +23,33 @@ public class CityscapeComponent extends JComponent
* (what the method guarantees upon completion)
* @param y description of parameter y
* @return description of the return value
*/
*/

public void paintComponent(Graphics g)
{
{
Graphics2D g2 = (Graphics2D) g;

// writing the code for my lab...

// create instances of classes and invoke the draw method on each
// ...


int space = this.getWidth()/9;
int windowHeight = this.getHeight();
Random randomGen = new Random();
Sky sky = new Sky(this.getWidth(), this.getHeight());
sky.draw(g2);
Moon moon = new Moon(0, windowHeight/8, 100, 100);
moon.draw(g2);
Hill hill = new Hill(0, this.getHeight()-this.getHeight()/4, this.getWidth(), this.getHeight()/4);
hill.draw(g2);
int hillHeight = hill.getHillHeight();
Building building1 = new Building(space, randomGen.nextInt(windowHeight)-hill.getHillHeight(), space, windowHeight);
building1.setHillHeight(hillHeight);
building1.draw(g2);
Building building2 = new Building(space*3, randomGen.nextInt(windowHeight)-hill.getHillHeight(), space, windowHeight);
building2.setHillHeight(hillHeight);
building2.draw(g2);
Building building3 = new Building(space*5, randomGen.nextInt(windowHeight)-hill.getHillHeight(), space, windowHeight);
building3.setHillHeight(hillHeight);
building3.draw(g2);
Building building4 = new Building(space*7, randomGen.nextInt(windowHeight)-hill.getHillHeight(), space, windowHeight);
building4.setHillHeight(hillHeight);
building4.draw(g2);
}
}

}
Loading