diff --git a/AvgOfThree/package.bluej b/AvgOfThree/package.bluej index 5f5f50b5..00395d8d 100644 --- a/AvgOfThree/package.bluej +++ b/AvgOfThree/package.bluej @@ -2,9 +2,9 @@ objectbench.height=100 objectbench.width=658 package.editor.height=400 -package.editor.width=560 -package.editor.x=30 -package.editor.y=30 +package.editor.width=865 +package.editor.x=860 +package.editor.y=20 package.numDependencies=0 package.numTargets=1 package.showExtends=true @@ -16,8 +16,8 @@ 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.x=732 +target1.editor.y=309 target1.height=50 target1.name=AvgOfThree target1.naviview.expanded=false diff --git a/Chapter 4 practice/Annuity.java b/Chapter 4 practice/Annuity.java new file mode 100644 index 00000000..296405b8 --- /dev/null +++ b/Chapter 4 practice/Annuity.java @@ -0,0 +1,39 @@ + + +/** + * Write a description of class Annuity here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Annuity +{ + private double PMT = 10000; + private double i = .08; + private double n = 20; + /** + * Default constructor for objects of class Annuity + */ + public Annuity() + { + // initialise instance variables + int presentValue = 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 void sampleMethod() + { + double presentValue = PMT * ((((Math.pow(1+i,n-1)-1)/i)/Math.pow(1+n,n-1))+1); + System.out.println(presentValue); + } + +} diff --git a/Chapter 4 practice/README.TXT b/Chapter 4 practice/README.TXT new file mode 100644 index 00000000..0de5dc9d --- /dev/null +++ b/Chapter 4 practice/README.TXT @@ -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: diff --git a/Chapter 4 practice/StringParsing.java b/Chapter 4 practice/StringParsing.java new file mode 100644 index 00000000..0321a0e0 --- /dev/null +++ b/Chapter 4 practice/StringParsing.java @@ -0,0 +1,36 @@ +import java.util.Scanner; + +/** + * Write a description of class StringParsing here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class StringParsing +{ + /** description of instance variable x (add comment for each instance variable) */ + private int x; + + /** + * Default constructor for objects of class StringParsing + */ + public StringParsing() + { + // initialise instance variables + x = 0; + } + + public void main() + { + Scanner in = new Scanner(System.in); + System.out.print("please imput a number between 1,000 and 999,999:\t"); + String rawNumber = in.next(); + int rawLength = rawNumber.length(); + int commaIndex = rawNumber.indexOf(","); + String firstHalf = rawNumber.substring(0,commaIndex); + String seccondHalf = rawNumber.substring(commaIndex+1); + String number = firstHalf + seccondHalf; + System.out.println(number); + } + +} diff --git a/Chapter 4 practice/package.bluej b/Chapter 4 practice/package.bluej new file mode 100644 index 00000000..e3f0b619 --- /dev/null +++ b/Chapter 4 practice/package.bluej @@ -0,0 +1,50 @@ +#BlueJ package file +objectbench.height=76 +objectbench.width=658 +package.editor.height=400 +package.editor.width=560 +package.editor.x=860 +package.editor.y=20 +package.numDependencies=0 +package.numTargets=3 +package.showExtends=true +package.showUses=true +project.charset=UTF-8 +target1.editor.height=1010 +target1.editor.width=840 +target1.editor.x=840 +target1.editor.y=0 +target1.height=50 +target1.name=rectangle +target1.naviview.expanded=true +target1.showInterface=false +target1.type=ClassTarget +target1.typeParameters= +target1.width=80 +target1.x=160 +target1.y=10 +target2.editor.height=700 +target2.editor.width=900 +target2.editor.x=861 +target2.editor.y=341 +target2.height=50 +target2.name=StringParsing +target2.showInterface=false +target2.type=ClassTarget +target2.typeParameters= +target2.width=100 +target2.x=70 +target2.y=70 +target3.editor.height=700 +target3.editor.width=900 +target3.editor.x=628 +target3.editor.y=508 +target3.height=50 +target3.name=Annuity +target3.naviview.expanded=true +target3.showInterface=false +target3.type=ClassTarget +target3.typeParameters= +target3.width=80 +target3.x=70 +target3.y=10 diff --git a/Chapter 4 practice/rectangle.java b/Chapter 4 practice/rectangle.java new file mode 100644 index 00000000..bf5d5de8 --- /dev/null +++ b/Chapter 4 practice/rectangle.java @@ -0,0 +1,40 @@ +import java.util.Scanner; +/** + * like a square, but not... square + * + * @author arash + * @version (a version number or a date) + */ +public class rectangle +{ + /** description of instance variable x (add comment for each instance variable) */ + private int x; + + /** + * Default constructor for objects of class rectangle + */ + public rectangle() + { + // initialise instance variables + x = 0; + } + + public void main() + { + Scanner in = new Scanner(System.in); + System.out.print("what is the lenght? \t:"); + double length = in.nextDouble(); + System.out.print("what is the width \t:"); + double width = in.nextDouble(); + double area = length*width; + double perimeter = 2*length + 2*width; + double diagonal = Math.sqrt((Math.pow(length,2)+Math.pow(width,2))); + System.out.print("\nthe area is\t:"); + System.out.println(area); + System.out.print("the perimeter is\t:"); + System.out.println(perimeter); + System.out.print("the diagonal is\t:"); + System.out.println(diagonal); + } + +} diff --git a/Chapter3Practice/Car.java b/Chapter3Practice/Car.java new file mode 100644 index 00000000..31223379 --- /dev/null +++ b/Chapter3Practice/Car.java @@ -0,0 +1,69 @@ + + +/** + * A cool hot hip young class + * tracks fuel remaining in the car as it is driven based + * on feul efficiencey + * + * @Arresh + * @version 12 september + */ +public class Car +{ + /** the fuel efficiency of this car measured in miles per gallon*/ + private double fuelEfficiency; + /**the number of gallons of fuel left in the tank*/ + private double fuelInTank; + + /** + * Default constructor for a Car of specified fuel efficiency + */ + public Car(double efficiency) + { + this.fuelEfficiency = efficiency; + this.fuelInTank = 0; + } + + /** + * Adds the specofoed number of gallons of fuel to this car's tank + * + * @pre the specified number of gallons does not excede this cars gass capacity8 + * @param gallons number of gallons of fuel to add to this car's tank + */ + public void addGas(double gallons) + { + this.fuelInTank =this.fuelInTank + gallons; + + } + + + /** + * Updates fuel in this car's tank based on the specified number of miles driven + * and this car's fuel efficiency + * + * @pre Specified number of miles does not exceed the fuel in this car's tank + * @post postconditions for the method + * (what the method guarantees upon completion) + * @param miles number of miles this car has driven + */ + public void drive(double miles) + { + double gallonsBurned = miles/ this.fuelEfficiency; + this.fuelInTank = this.fuelInTank - gallonsBurned; + + } + + /** + * returns number of gallons of fuel left in this car's tank + * + * @return's number of gallons of fuel left in this car's tank + */ + public double getGasInTank() + { + // put your code here + return this.fuelInTank; + } + + + +} diff --git a/Chapter3Practice/CarTest.java b/Chapter3Practice/CarTest.java new file mode 100644 index 00000000..8601e906 --- /dev/null +++ b/Chapter3Practice/CarTest.java @@ -0,0 +1,82 @@ + + +import static org.junit.Assert.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Write a description of test class CarTest here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class CarTest +{ + /** description of instance variable x (add comment for each instance variable) */ + private int x; + + /** + * Default constructor for objects of class CarTest + */ + public CarTest() + { + // initialise instance variables + x = 0; + } + + /** + * Sets up the test fixture. + * + * Called before every test case method. + */ + @Before + public void setUp() + { + } + + /** + * Tears down the test fixture. + * + * Called after every test case method. + */ + @After + public void tearDown() + { + } + + @Test + public void testGetGasInTank() + { + Car testCar = new Car(50); + double gallons = testCar.getGasInTank(); + assertEquals(0.0, gallons, 1e-6); + } + + @Test + public void testAddGas() + { + Car testCar = new Car(50); + testCar.addGas(20); + double gallons = testCar.getGasInTank(); + assertEquals(20.0, gallons, 1e-6); + + testCar.addGas(5); + gallons = testCar.getGasInTank(); + assertEquals(25.0, gallons, 1e-6); + } + + @Test + public void testDrive() + { + Car testCar = new Car(50); + testCar.addGas(20); + testCar.drive(25); + double gallons = testCar.getGasInTank(); + assertEquals(19.5, gallons, 1e-6); + + testCar.drive(100); + gallons = testCar.getGasInTank(); + assertEquals(17.5, gallons, 1e-6); + } +} \ No newline at end of file diff --git a/Chapter3Practice/Door.java b/Chapter3Practice/Door.java new file mode 100644 index 00000000..6e221fd4 --- /dev/null +++ b/Chapter3Practice/Door.java @@ -0,0 +1,64 @@ + + +/** + * not to be confused with The Doors + * + * @author (your name) + * @version (a version number or a date) + */ +public class Door +{ + /** says the name of the door */ + private String name; + private boolean state; + + /** + * Default constructor for objects of class Door + */ + public Door(boolean beggining_state, String beggining_name) + { + this.state = beggining_state; + this.name = beggining_name; + } + + /** + * 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 void close() + { + this.state = false; + } + + public void open() + { + this.state = true; + } + + public String getName() + { + return this.name; + } + public boolean getState() + { + return this.state; + } + public void setName(String newName) + { + this.name = newName; + } + + public void setState(boolean newState) + { + this.state = newState; + } + + +} diff --git a/Chapter3Practice/DoorTest.java b/Chapter3Practice/DoorTest.java new file mode 100644 index 00000000..5ebd849d --- /dev/null +++ b/Chapter3Practice/DoorTest.java @@ -0,0 +1,48 @@ + + +import static org.junit.Assert.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Write a description of test class DoorTest here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class DoorTest +{ + /** description of instance variable x (add comment for each instance variable) */ + private int x; + + /** + * Default constructor for objects of class DoorTest + */ + public DoorTest() + { + // initialise instance variables + x = 0; + } + + /** + * Sets up the test fixture. + * + * Called before every test case method. + */ + @Before + public void setUp() + { + } + + /** + * Tears down the test fixture. + * + * Called after every test case method. + */ + @After + public void tearDown() + { + } + +} diff --git a/Chapter3Practice/README.TXT b/Chapter3Practice/README.TXT new file mode 100644 index 00000000..0de5dc9d --- /dev/null +++ b/Chapter3Practice/README.TXT @@ -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: diff --git a/Chapter3Practice/Target.java b/Chapter3Practice/Target.java new file mode 100644 index 00000000..b6a1297f --- /dev/null +++ b/Chapter3Practice/Target.java @@ -0,0 +1,85 @@ +import java.awt.Graphics2D; +import java.awt.geom.Ellipse2D; +import java.awt.Color; +import java.util.Random; + +/** + * A target shape that can be positioned anywhere on the screen + * + * @Arresh + * @version (a version number or a date) + */ +public class Target +{ + /** description of instance variable x (add comment for each instance variable) */ + private int xLeft; + private int yTop; + private int size; + + /** + * @param x + * @param y + */ + public Target(int x, int y, int sise) + { + xLeft = x; + yTop = y; + size = sise; + } + + /** + * An example of a method - replace this comment with your own + * that describes the operation of the method + * + * @pre assumes that there exists a 10X 10 square with upper left verticie as + * inputs + * @post postconditions for the method + * (what the method guarantees upon completion) + * @param g2 The graphics context + * @return description of the return value + */ + public void draw(Graphics2D g2) + { + //the number of the ring is the radius, the smaller nestled in the larger + /*Ellipse2D.Double ring1 = new Ellipse2D.Double(xLeft+40, yTop +40, 20, 20); + Ellipse2D.Double ring2 = new Ellipse2D.Double(xLeft + 30, yTop +30, 40, 40); + Ellipse2D.Double ring3 = new Ellipse2D.Double(xLeft+20, yTop +20, 60, 60); + Ellipse2D.Double ring4 = new Ellipse2D.Double(xLeft+10, yTop+10 , 80, 80); + Ellipse2D.Double ring5 = new Ellipse2D.Double(xLeft, yTop , 100, 100); + */ + /* + Ellipse2D.Double ring1 = new Ellipse2D.Double(xLeft+40-50, yTop +40-50, 20, 20); + Ellipse2D.Double ring2 = new Ellipse2D.Double(xLeft + 30-50, yTop +30-50, 40, 40); + Ellipse2D.Double ring3 = new Ellipse2D.Double(xLeft+20-50, yTop +20-50, 60, 60); + Ellipse2D.Double ring4 = new Ellipse2D.Double(xLeft+10-50, yTop+10-50 , 80, 80); + Ellipse2D.Double ring5 = new Ellipse2D.Double(xLeft-50, yTop-50 , 100, 100); + */ + Ellipse2D.Double ring1 = new Ellipse2D.Double(xLeft- size/10, yTop - size/10, size/5, size/5); + Ellipse2D.Double ring2 = new Ellipse2D.Double(xLeft - 2*size/10, yTop -2*size/10, 2*size/5, 2*size/5); + Ellipse2D.Double ring3 = new Ellipse2D.Double(xLeft-3*size/10, yTop -3*size/10, 3*size/5, 3*size/5); + Ellipse2D.Double ring4 = new Ellipse2D.Double(xLeft-4*size/10, yTop-4*size/10 ,4*size/5,4*size/5); + Ellipse2D.Double ring5 = new Ellipse2D.Double(xLeft-size/2, yTop-size/2 , size, size); + Random Generator = new Random(); + Color random = new Color(Generator.nextInt(256),Generator.nextInt(256),Generator.nextInt(256)); + + g2.setColor(random); + g2.draw(ring5); + g2.fill(ring5); + g2.setColor(Color.WHITE); + g2.draw(ring4); + g2.fill(ring4); + g2.setColor(random); + g2.draw(ring3); + g2.fill(ring3); + g2.setColor(Color.WHITE); + g2.draw(ring2); + g2.fill(ring2); + g2.setColor(random); + g2.draw(ring1); + g2.fill(ring1); + + + + } + +} diff --git a/Chapter3Practice/TargetComponent.java b/Chapter3Practice/TargetComponent.java new file mode 100644 index 00000000..499e2159 --- /dev/null +++ b/Chapter3Practice/TargetComponent.java @@ -0,0 +1,25 @@ +import java.awt.Graphics; +import java.awt.Graphics2D; +import javax.swing.JComponent; +import java.util.Random; +/** + * Write a description of class TargetComponent here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class TargetComponent extends JComponent +{ + + public void paintComponent(Graphics g) + { + Graphics2D g2 = (Graphics2D) g; + Random Generator = new Random(); + int x = getWidth()/2; + int y = getHeight()/2; + int size = Generator.nextInt(300) + 50; + Target target1 = new Target(x,y, size); + target1.draw(g2); + } + +} diff --git a/Chapter3Practice/TargetVeiwer.java b/Chapter3Practice/TargetVeiwer.java new file mode 100644 index 00000000..ada54c15 --- /dev/null +++ b/Chapter3Practice/TargetVeiwer.java @@ -0,0 +1,28 @@ +import javax.swing.JFrame; + +/** + * Write a description of class TargetVeiwer here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class TargetVeiwer +{ + + public static void main(String[] args) + { + JFrame frame = new JFrame(); + + frame.setSize(400,400); + frame.setTitle("Get More, Pay Less"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + TargetComponent component = new TargetComponent(); + frame.add(component); + + frame.setVisible(true); + + + } + +} diff --git a/Chapter3Practice/VendingMachine.java b/Chapter3Practice/VendingMachine.java new file mode 100644 index 00000000..6ba88950 --- /dev/null +++ b/Chapter3Practice/VendingMachine.java @@ -0,0 +1,78 @@ + + +/** + * Simulates the tool of the capitalist opressors + * + * @author Arresh + * @version ¯\_(ツ)_/¯ + */ +public class VendingMachine +{ + /** description of instance variable x (add comment for each instance variable) */ + private int cans; + private int coins; + private int profit; + + /** + * Default constructor for objects of class VendingMachine + */ + public VendingMachine() + { + this.cans = 10; + this.coins = 0; + this.profit = 0; + } + + public VendingMachine(int startCans) + { + // initialise instance variables + this.cans = startCans; + this.coins = 0; + this.profit = 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 insertCoin() + { + // put your code here + this.coins += 1; + return 1; + } + + public void vendCan(int insertedCoins) + { + this.cans -= insertedCoins; + } + + public void reset(int refillCans) + { + this.profit += this.coins; + this.coins = 0; + this.cans += refillCans; + } + + public int getCans() + { + return this.cans; + } + + public int getCoins() + { + return this.coins; + } + + public int getProfit() + { + return this.profit; + } +} diff --git a/Chapter3Practice/VendingMachineTest.java b/Chapter3Practice/VendingMachineTest.java new file mode 100644 index 00000000..4973870e --- /dev/null +++ b/Chapter3Practice/VendingMachineTest.java @@ -0,0 +1,48 @@ + + +import static org.junit.Assert.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Write a description of test class VendingMachineTest here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class VendingMachineTest +{ + /** description of instance variable x (add comment for each instance variable) */ + private int x; + + /** + * Default constructor for objects of class VendingMachineTest + */ + public VendingMachineTest() + { + // initialise instance variables + x = 0; + } + + /** + * Sets up the test fixture. + * + * Called before every test case method. + */ + @Before + public void setUp() + { + } + + /** + * Tears down the test fixture. + * + * Called after every test case method. + */ + @After + public void tearDown() + { + } + +} diff --git a/Chapter3Practice/doc/Car.html b/Chapter3Practice/doc/Car.html new file mode 100644 index 00000000..2d7e827d --- /dev/null +++ b/Chapter3Practice/doc/Car.html @@ -0,0 +1,194 @@ + + + +
+ + ++java.lang.Object ++Car +
public class Car
+A cool hot hip young class + tracks fuel remaining in the car as it is driven based + on feul efficiencey +
+ +
+
| +Constructor Summary | +|
|---|---|
Car(double fuelEfficiency)
+
++ Default constructor for a Car of specified fuel efficiency |
+|
| +Method Summary | +|
|---|---|
+ void |
+addGas(double gallons)
+
++ Adds the specofoed number of gallons of fuel to this car's tank |
+
+ void |
+drive(double miles)
+
++ Updates fuel in this car's tank based on the specified number of miles driven + and this car's fuel efficiency |
+
+ double |
+getGasInTank()
+
++ returns number of gallons of fuel left in this car's tank |
+
| Methods inherited from class | +
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
| +Constructor Detail | +
|---|
+public Car(double fuelEfficiency)+
+
| +Method Detail | +
|---|
+public void addGas(double gallons)+
+
gallons - number of gallons of fuel to add to this car's tank+public void drive(double miles)+
+
miles - number of miles this car has driven+public double getGasInTank()+
+
| Car
+ + |
+
| Car
+ + |
+
|
+Classes
+
+ +Car |
+
| +Class Summary | +|
|---|---|
| Car | +A cool hot hip young class + tracks fuel remaining in the car as it is driven based + on feul efficiencey | +
+