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
10 changes: 5 additions & 5 deletions AvgOfThree/package.bluej
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions Chapter 4 practice/Annuity.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
13 changes: 13 additions & 0 deletions Chapter 4 practice/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:
36 changes: 36 additions & 0 deletions Chapter 4 practice/StringParsing.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
50 changes: 50 additions & 0 deletions Chapter 4 practice/package.bluej
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions Chapter 4 practice/rectangle.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
69 changes: 69 additions & 0 deletions Chapter3Practice/Car.java
Original file line number Diff line number Diff line change
@@ -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;
}



}
82 changes: 82 additions & 0 deletions Chapter3Practice/CarTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading