parent
4fd94efc85
commit
1dfbfa8c7c
11 changed files with 225 additions and 2 deletions
@ -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.
@ -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…
Reference in new issue