Skip to content

Commit

Permalink
Added Lab 4 Starter Files
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-kulkarni authored and czar committed Oct 26, 2024
1 parent c2fcb45 commit 96757e9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lab1/Collatz.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@
* @author YOUR NAME HERE
*/
public class Collatz {

/** Buggy implementation of nextNumber! */
public static int nextNumber(int n) {
if (n == 128) {
return 1;
} else if (n == 5) {
return 3 * n + 1;
} else {
return n * 2;
}
}

public static void main(String[] args) {
int n = 5;
System.out.print(n + " ");

while (n != 1) {
n = nextNumber(n);
System.out.print(n + " ");
}
System.out.println();
}
}

13 changes: 13 additions & 0 deletions lab4/flik/Flik.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package flik;

/** An Integer tester created by Flik Enterprises.
* @author Josh Hug
* */
public class Flik {
/** @param a Value 1
* @param b Value 2
* @return Whether a and b are the same */
public static boolean isSameNumber(Integer a, Integer b) {
return a == b;
}
}
14 changes: 14 additions & 0 deletions lab4/flik/HorribleSteve.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package flik;

public class HorribleSteve {
public static void main(String [] args) throws Exception {
int i = 0;
for (int j = 0; i < 500; ++i, ++j) {
if (!Flik.isSameNumber(i, j)) {
throw new Exception(
String.format("i:%d not same as j:%d ??", i, j));
}
}
System.out.println("i is " + i);
}
}
44 changes: 44 additions & 0 deletions lab4/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>CS61B</groupId>
<artifactId>61BMasterPom</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../library-sp21/javalib/masterpom.xml</relativePath>
</parent>

<groupId>CS61B</groupId>
<artifactId>lab4</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<sourceDirectory>${project.basedir}</sourceDirectory>
<testSourceDirectory>${project.basedir}</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.14</source>
<target>1.14</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>
<arg>-J-XX:+ShowCodeDetailsInExceptionMessages</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>

</project>

0 comments on commit 96757e9

Please sign in to comment.