import java.io.*; import java.util.*; public class Lab16 { private static String names[]; private static int fileSize; public static void main(String args[]) throws IOException { System.out.println("LAB 16! \n\n"); System.out.println(); System.out.println("Contents of Names1"); names = new String[33]; readFile("Names1.txt"); displayArray(); sortArray(); displayArray(); writeFile("Names2.txt"); } public static void readFile(String fileName) throws IOException { int k = 0; ExpoInFile f = new ExpoInFile("Names1.txt"); names[k] = f.readString(); k++; while(k <= 32) { names[k] = f.readString(); k++; } f.closeFile(); } public static void displayArray() { for(int i = 0; i <= 32; i++) { System.out.println(names[i]); } } public static void writeFile(String n) throws IOException { ExpoOutFile t = new ExpoOutFile(n); for(int q = 0; q <= 32; q++) { t.writelnString(names[q]); } t.closeFile(); } public static void sortArray() { System.out.println(); System.out.println("============================================================="); System.out.println("Alphabetical:"); System.out.println(); Arrays.sort(names); } }
Bill's code
my code for java class, it's probably stupid. play with it so you figure out how it works. it's been put on here as a purely "collaborative" learning effort
Wednesday, May 4, 2011
Lab16
Friday, April 29, 2011
lab15
//seriously change it a little so teach doesent eat me
import java.awt.*;
import java.applet.*;
public class Lab15 extends Applet
{
private int numBars;
int barHeight[];
int sortDelay;
public void init()
{
numBars = 47;
sortDelay = 10;
barHeight = new int[numBars];
getBarValues();
}
public void getBarValues()
{
Expo.startSeed(3333);
for(int k = 0;k < numBars; k++)
{
barHeight[k] = Expo.seedRandom(10,600);
}
}
public void paint(Graphics g)
{
showFrame(g);
displayRandomBars(g);
clearRedBars(g);
sortBars(g);
}
public void showFrame(Graphics g)
{
g.fillRect(0,0,1300,20);
g.fillRect(0,0,20,1000);
g.fillRect(0,880,1000,20);
g.fillRect(980,0,20,880);
}
public void displayRandomBars(Graphics g)
{
g.setColor(Color.red);
for(int k = 0; (k+1) <= 47; k++)
{
g.fillRect(30+(k*20),barHeight[k],10,(880 - barHeight[k]));
}
}
public void sortBars(Graphics g)
{
int b;
g.setColor(Color.blue);
for(int k = 0; k < 47; k++)
{
Expo.delay(20);
for(int d = 0; d < 46; d++)
{
if(barHeight[d] < barHeight[d+1])
{
b = barHeight[d];
barHeight[d] = barHeight[d+1];
barHeight[d+1] = b;
}
g.fillRect(30+(k*20),barHeight[k],10,(880 - barHeight[k]));
}
}
}
public void clearRedBars(Graphics g)
{
g.setColor(Color.white);
for(int k = 0; (k+1) <= 47; k++)
{
Expo.delay(40);
g.fillRect(30+(k*20),barHeight[k],10,(880 - barHeight[k]));
}
}
}
import java.awt.*;
import java.applet.*;
public class Lab15 extends Applet
{
private int numBars;
int barHeight[];
int sortDelay;
public void init()
{
numBars = 47;
sortDelay = 10;
barHeight = new int[numBars];
getBarValues();
}
public void getBarValues()
{
Expo.startSeed(3333);
for(int k = 0;k < numBars; k++)
{
barHeight[k] = Expo.seedRandom(10,600);
}
}
public void paint(Graphics g)
{
showFrame(g);
displayRandomBars(g);
clearRedBars(g);
sortBars(g);
}
public void showFrame(Graphics g)
{
g.fillRect(0,0,1300,20);
g.fillRect(0,0,20,1000);
g.fillRect(0,880,1000,20);
g.fillRect(980,0,20,880);
}
public void displayRandomBars(Graphics g)
{
g.setColor(Color.red);
for(int k = 0; (k+1) <= 47; k++)
{
g.fillRect(30+(k*20),barHeight[k],10,(880 - barHeight[k]));
}
}
public void sortBars(Graphics g)
{
int b;
g.setColor(Color.blue);
for(int k = 0; k < 47; k++)
{
Expo.delay(20);
for(int d = 0; d < 46; d++)
{
if(barHeight[d] < barHeight[d+1])
{
b = barHeight[d];
barHeight[d] = barHeight[d+1];
barHeight[d+1] = b;
}
g.fillRect(30+(k*20),barHeight[k],10,(880 - barHeight[k]));
}
}
}
public void clearRedBars(Graphics g)
{
g.setColor(Color.white);
for(int k = 0; (k+1) <= 47; k++)
{
Expo.delay(40);
g.fillRect(30+(k*20),barHeight[k],10,(880 - barHeight[k]));
}
}
}
Friday, April 22, 2011
Palindrome Finder
CHANGE THE CODE A LITTLE SO I DONT GET IN TROUBLE
public class Lab14
{
public static void main(String args[])
{
System.out.println("100 POINT VERSION,");
boolean finished = false;
do
{
System.out.println("===============================================================");
System.out.print("Enter a string ===>> ");
Palindrome p = new Palindrome(Expo.enterString());
p.displayData();
System.out.print("Do you wish to repeat this program [Y/N]? ===>> ");
char repeat = Expo.enterChar();
finished = (repeat != 'Y' && repeat != 'y');
System.out.println();
}
while (!finished);
}
}
class Palindrome
{
private String str;
private String str2 = "";
private int d = 0;
public Palindrome(String s)
{
str = s;
}
public boolean isPal()
{
int s = str.length() - 1;
int k = (s/2);
for (int i = s; i >= 0; i--)
{
str2 += str.charAt(i);
}
if(str.equals(str2)){
d = 1;
return true;
}
else{
return false;
}
}
public boolean almostPal()
{
purge();
if(d == 1){
return false;
}
else if(str.equals(str2)){
return true;
}
else{
return false;
}
}
public String purge()
{
str = str.replace(" ","");
str2 = str2.replace(" ","");
str = str.replace(",","");
str2 = str2.replace(",","");
str = str.replace("'","");
str2 = str2.replace("'","");
str = str.replace(".","");
str2 = str2.replace(".","");
str = str.replace("!","");
str2 = str2.replace("!","");
str = str.toUpperCase();
str2 = str2.toUpperCase();
return "";
}
public void displayData()
{
System.out.println();
System.out.println("String: " + str);
System.out.println("Palindrome: " + isPal());
System.out.println("Almost Palindrome: " + almostPal());
System.out.println("===============================================================");
System.out.println();
d = 0;
}
}
public class Lab14
{
public static void main(String args[])
{
System.out.println("100 POINT VERSION,");
boolean finished = false;
do
{
System.out.println("===============================================================");
System.out.print("Enter a string ===>> ");
Palindrome p = new Palindrome(Expo.enterString());
p.displayData();
System.out.print("Do you wish to repeat this program [Y/N]? ===>> ");
char repeat = Expo.enterChar();
finished = (repeat != 'Y' && repeat != 'y');
System.out.println();
}
while (!finished);
}
}
class Palindrome
{
private String str;
private String str2 = "";
private int d = 0;
public Palindrome(String s)
{
str = s;
}
public boolean isPal()
{
int s = str.length() - 1;
int k = (s/2);
for (int i = s; i >= 0; i--)
{
str2 += str.charAt(i);
}
if(str.equals(str2)){
d = 1;
return true;
}
else{
return false;
}
}
public boolean almostPal()
{
purge();
if(d == 1){
return false;
}
else if(str.equals(str2)){
return true;
}
else{
return false;
}
}
public String purge()
{
str = str.replace(" ","");
str2 = str2.replace(" ","");
str = str.replace(",","");
str2 = str2.replace(",","");
str = str.replace("'","");
str2 = str2.replace("'","");
str = str.replace(".","");
str2 = str2.replace(".","");
str = str.replace("!","");
str2 = str2.replace("!","");
str = str.toUpperCase();
str2 = str2.toUpperCase();
return "";
}
public void displayData()
{
System.out.println();
System.out.println("String: " + str);
System.out.println("Palindrome: " + isPal());
System.out.println("Almost Palindrome: " + almostPal());
System.out.println("===============================================================");
System.out.println();
d = 0;
}
}
Wednesday, March 30, 2011
Sunday, March 6, 2011
lessBy10
public boolean lessBy10(int a, int b, int c) {
if(a-b>=10 || a-c>=10 || b-a>=10 || b-c>=10 || c-a>=10 || c-b>=10){
return true;
}
return false;
}
if(a-b>=10 || a-c>=10 || b-a>=10 || b-c>=10 || c-a>=10 || c-b>=10){
return true;
}
return false;
}
love6
public boolean love6(int a, int b) {
if(a == 6 || b == 6){
return true;
}
if(a + b == 6 || a - b == 6 || b - a == 6){
return true;
}
return false;
}
if(a == 6 || b == 6){
return true;
}
if(a + b == 6 || a - b == 6 || b - a == 6){
return true;
}
return false;
}
front11
public int[] front11(int[] a, int[] b) {
if(a.length == 0 && b.length == 0){
int[] c = new int[] {};
return c;
}
if(a.length == 0){
int[] c = new int[1];
c[0] = b[0];
return c;
}
if(b.length == 0){
int[] c = new int[1];
c[0] = a[0];
return c;
}
else{
int[] c = new int[2];
c[0] = a[0];
c[1] = b[0];
return c;
}
}
if(a.length == 0 && b.length == 0){
int[] c = new int[] {};
return c;
}
if(a.length == 0){
int[] c = new int[1];
c[0] = b[0];
return c;
}
if(b.length == 0){
int[] c = new int[1];
c[0] = a[0];
return c;
}
else{
int[] c = new int[2];
c[0] = a[0];
c[1] = b[0];
return c;
}
}
reverse3
public int[] reverse3(int[] nums) {
int[] r = new int[3];
r[0] = nums[2];
r[1] = nums[1];
r[2] = nums[0];
return r;
}
int[] r = new int[3];
r[0] = nums[2];
r[1] = nums[1];
r[2] = nums[0];
return r;
}
commonEnd
public boolean commonEnd(int[] a, int[] b) {
if(a[0] == b[0] || a[a.length - 1] == b[b.length - 1]){return true;}
else{return false;}}
if(a[0] == b[0] || a[a.length - 1] == b[b.length - 1]){return true;}
else{return false;}}
Wednesday, February 16, 2011
code lab12
//at least try to figure out how it works
import java.util.Arrays;
public class Lab12
{
public static void main(String args[])
{
System.out.println("\nLAB12 AWESOME VERSION\n");
System.out.print("Enter the quantity of random numbers ===>> ");
int listSize = Expo.enterInt();
Statistics intList = new Statistics(listSize);
intList.randomize();
intList.computeMean();
intList.computeMedian();
intList.computeMode();
intList.displayStats();
}
}
class Statistics
{
private int list[];
private int size;
private double mean;
private double median;
private int mode;
private int count = 0;
private int count1;
private int value2;
public Statistics(int s)
{
list = new int[s];
size = s;
}
public void randomize()
{
Expo.startSeed(12345);
for(int k = 0; k < size; k++)
{
int rndNumber = Expo.seedRandom(10,20);
list[k] = rndNumber;
}
}
public void computeMean()
{
mean = 0;
for(int k = 0; k < size; k++)
{
mean += list[k];
}
mean = mean / size;
}
public void computeMedian()
{
Arrays.sort(list);
if (size%2 == 1)
{
median = list[((size / 2))];
}
else
{
int r = list[(size / 2)] + list[((size / 2) + 1)];
median = r / 2;
}
}
public void computeMode()
{
for(int k = 0; k + 1 < size - 1; k++)
{
int value1 = list[(k)];
if(k >= size)
{
mode = list[k];
count1 = count;
}
if(k+1 <= size)
{
value2 = list[(k+1)];
if(value1 == value2)
{
count += 1;
}
else
{
if(count > count1)
{
mode = value1;
count1 = count;
count = 0;
}
else
{
count = 0;
}
}
}
}
}
public void displayStats()
{
System.out.println();
System.out.println();
System.out.println(Arrays.toString(list));
System.out.println("Mean: " + mean);
System.out.println("Median: " + median);
System.out.println("Mode: " + mode);
}
}
import java.util.Arrays;
public class Lab12
{
public static void main(String args[])
{
System.out.println("\nLAB12 AWESOME VERSION\n");
System.out.print("Enter the quantity of random numbers ===>> ");
int listSize = Expo.enterInt();
Statistics intList = new Statistics(listSize);
intList.randomize();
intList.computeMean();
intList.computeMedian();
intList.computeMode();
intList.displayStats();
}
}
class Statistics
{
private int list[];
private int size;
private double mean;
private double median;
private int mode;
private int count = 0;
private int count1;
private int value2;
public Statistics(int s)
{
list = new int[s];
size = s;
}
public void randomize()
{
Expo.startSeed(12345);
for(int k = 0; k < size; k++)
{
int rndNumber = Expo.seedRandom(10,20);
list[k] = rndNumber;
}
}
public void computeMean()
{
mean = 0;
for(int k = 0; k < size; k++)
{
mean += list[k];
}
mean = mean / size;
}
public void computeMedian()
{
Arrays.sort(list);
if (size%2 == 1)
{
median = list[((size / 2))];
}
else
{
int r = list[(size / 2)] + list[((size / 2) + 1)];
median = r / 2;
}
}
public void computeMode()
{
for(int k = 0; k + 1 < size - 1; k++)
{
int value1 = list[(k)];
if(k >= size)
{
mode = list[k];
count1 = count;
}
if(k+1 <= size)
{
value2 = list[(k+1)];
if(value1 == value2)
{
count += 1;
}
else
{
if(count > count1)
{
mode = value1;
count1 = count;
count = 0;
}
else
{
count = 0;
}
}
}
}
}
public void displayStats()
{
System.out.println();
System.out.println();
System.out.println(Arrays.toString(list));
System.out.println("Mean: " + mean);
System.out.println("Median: " + median);
System.out.println("Mode: " + mode);
}
}
Tuesday, February 15, 2011
Code
//this code will have no purpose. whatsoever
public class JavaPractice001
{
public static void main(String args[])
{
int a = 25;
int b = 10;
int c = 5;
int d = 2;
int e = 0;
e = b + a;
System.out.println(a + "+" + b + "=" + e);
System.out.println("this is something I cant say in school:");
System.out.println("potato tits rat shit bat shit dirty old cunt 69 assholes tied in a knot hooray lizard piss FUCK");
}
}
public class JavaPractice001
{
public static void main(String args[])
{
int a = 25;
int b = 10;
int c = 5;
int d = 2;
int e = 0;
e = b + a;
System.out.println(a + "+" + b + "=" + e);
System.out.println("this is something I cant say in school:");
System.out.println("potato tits rat shit bat shit dirty old cunt 69 assholes tied in a knot hooray lizard piss FUCK");
}
}
Wednesday, December 22, 2010
Steam holiday sales
i bought bioshock 2 but now i have to wait for like 5 hours while it downloads. frowney face
Tuesday, December 21, 2010
Monday, December 20, 2010
Subscribe to:
Posts (Atom)