master
Noah Pederson 6 years ago
parent 4fd94efc85
commit 1dfbfa8c7c
  1. 2
      .idea/misc.xml
  2. 2
      .idea/modules.xml
  3. 11
      Assessment-7/Assessment-7.iml
  4. 38
      Assessment-7/src/DisplayAuthors.java
  5. BIN
      Chapter10/Chapter10.zip
  6. 2
      Chapter9/.classpath
  7. 11
      Midterm-Part2/Midterm-Part2.iml
  8. 9
      Midterm-Part2/src/Movable.java
  9. 38
      Midterm-Part2/src/MovablePoint.java
  10. 82
      Midterm-Part2/src/OverAchieve.java
  11. 32
      Midterm-Part2/src/TestMove.java

@ -13,7 +13,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="Java 8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -2,10 +2,12 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Assessment-7/Assessment-7.iml" filepath="$PROJECT_DIR$/Assessment-7/Assessment-7.iml" />
<module fileurl="file://$PROJECT_DIR$/Chapter10/Chapter10.iml" filepath="$PROJECT_DIR$/Chapter10/Chapter10.iml" />
<module fileurl="file://$PROJECT_DIR$/Chapter11/Chapter11.iml" filepath="$PROJECT_DIR$/Chapter11/Chapter11.iml" />
<module fileurl="file://$PROJECT_DIR$/Chapter14/Chapter14.iml" filepath="$PROJECT_DIR$/Chapter14/Chapter14.iml" />
<module fileurl="file://$PROJECT_DIR$/Chapter9/Chapter9.iml" filepath="$PROJECT_DIR$/Chapter9/Chapter9.iml" />
<module fileurl="file://$PROJECT_DIR$/Midterm-Part2/Midterm-Part2.iml" filepath="$PROJECT_DIR$/Midterm-Part2/Midterm-Part2.iml" />
<module fileurl="file://$PROJECT_DIR$/School.iml" filepath="$PROJECT_DIR$/School.iml" />
</modules>
</component>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,38 @@
import java.sql.*;
public class DisplayAuthors {
public static void main(String... args) {
final String DATABASE_URL = "jdbc:derby:books";
final String SELECT_QUERY =
"SELECT authorID, firstName, lastName, FROM authors";
try (Connection conn = DriverManager.getConnection(
DATABASE_URL, "deitel", "deitel");
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_QUERY)) {
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
System.out.printf("Authors Table of Books Database:%n%n");
for (int i = 1; i <= numberOfColumns; i++)
System.out.printf("%-8s\t", metaData.getColumnName(i));
System.out.println();
while (resultSet.next()) {
for (int i = 1; i <= numberOfColumns; i++) {
System.out.printf("%-8s\t", resultSet.getObject(i));
System.out.println();
}
}
} catch (SQLException sqlException) {
sqlException.printStackTrace();
}
}
}

Binary file not shown.

@ -2,5 +2,5 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="output" path="/out/production/Chapter9"/>
</classpath>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,9 @@
/**
* Created by peder_000 on 6/6/2016.
*/
public interface Movable {
void moveUp();
void moveRight();
void moveDownLeft();
}

@ -0,0 +1,38 @@
/**
* Created by peder_000 on 6/6/2016.
*/
public class MovablePoint implements Movable {
private int x, y;
public MovablePoint() {
this(0,0);
}
public MovablePoint(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return x + ", " + y;
}
@Override
public void moveUp() {
y++;
}
@Override
public void moveRight() {
x++;
}
@Override
public void moveDownLeft() {
//Shoul I do some form of checking here? Negative coordinates are technically legal on a standard plane...
x--;
y--;
}
}

@ -0,0 +1,82 @@
/**
* Created by peder_000 on 6/6/2016.
*/
public class OverAchieve {
public static void main(String... args) {
//Initialize test arrays
String[] a = new String[]{
"Hello",
"World",
"Naptime",
"Programmering",
"I hate initializing arrays like this"
};
double[] b = new double[] {
1.0,
2.2,
3.3,
4.7,
555.7
};
//create 2 new arrays by calling increase on the first 2
String[] c = increaseArray(a);
double[] d = increaseArray(b);
//Display everything
displayArray(a);
displayArray(b);
displayArray(c);
displayArray(d);
}
//takes an array of doubles, doubles each element and returns the result in a new array of doubles
public static double[] increaseArray(double[] d) {
//I think it wants a *copy* of the array, not to just modify the reference value
//So initialize a new array of the same size here
double[] newD = new double[d.length];
for(int i = 0; i < d.length; i++) {
newD[i] = d[i] * 2;
}
return newD;
}
//Takes an array of strings, concats each element to itself, and returns a NEW string array
public static String[] increaseArray(String[] s) {
String[] newS = new String[s.length];
for(int i = 0; i < s.length; i++) {
newS[i] = s[i] + s[i];
}
return newS;
}
//this should so be named "displarray"
//displays the contents of an array of strings
public static void displayArray(String[] s) {
for(int i = 0; i < s.length; i++) {
System.out.println(i + ": " + s[i]);
}
}
//dispalay the contents of an array of doubles
public static void displayArray(double[] d) {
for(int i = 0; i < d.length; i++) {
System.out.println(i + ": " + d[i]);
}
}
}

@ -0,0 +1,32 @@
/**
* Created by peder_000 on 6/6/2016.
*/
public class TestMove {
public static void main(String... args) {
//Create a new MovablePoint, display it's coordinates, decrease both by 2, increase y by 1 dispaly again
MovablePoint a = new MovablePoint(57, 89);
System.out.println(a.toString());
a.moveDownLeft();
a.moveDownLeft();
a.moveUp();
System.out.println(a.toString());
//Another MovablePoint...
MovablePoint b = new MovablePoint();
System.out.println(b.toString()); //I'm assuming this is wanted even though it's not explicitly mentioned
//loop through 14 times to get to the proper x position
for(int i = 0; i < 14; i++) {
b.moveUp();
b.moveRight();
}
//loop 13 more times to get to the proper y position
for(int i = 0; i < 13; i++) {
b.moveUp();
}
System.out.println(b.toString());
}
}
Loading…
Cancel
Save