package mid2helper;

import processing.core.PApplet;

public class Mid2Helper extends PApplet {

	public void setup() {
		question1();
		question2();
		question3();
		question4();
		question5();
		question6();
	}
	
	public void question1() {
		int[] nums = {8,6,7,5,3,0,9};

		System.out.println("\n1A");
		int k = 1;
		while (k < nums.length) {
			if (k > 5 && k < 9) {
				System.out.println(k + "," + nums[k]);
			}
			k++;
		}

		System.out.println("\n1B");
		for (k = 1; k < nums.length; k++) {
			if (nums[k-1] > nums[k]) {
				System.out.println(k + "," + nums[k]);
			}
		}

		System.out.println("\n1C");
		k = 1;
		while (k < nums.length) {
			int val = nums[k] + 10;
			System.out.println(val);
			k = k + 2;
		}

		System.out.println("\n1D");
		int c = nums.length;
		for (k = 0; k < nums.length; k++) {
			if (nums[k] % 2 == 1) {
				c--;
				System.out.println(c + "," + nums[k]);
			}
		}
	}

	public void question2() {
		String s = "More Sample Midterm Questions | CSC 130";
		String t = "m";
		int k = -1;
		int p = -1;
		int q = -1;

		System.out.println("\n2A");
		k = s.indexOf(t, 0);
		System.out.println(k);

		k = s.indexOf(t, 10);
		System.out.println(k);

		k = s.indexOf(t, 20);
		System.out.println(k);

		k = s.indexOf(t, 30);
		System.out.println(k);

		k = t.indexOf(s, 0);
		System.out.println(k);

		System.out.println("\n2B");
		t = s.substring(0, 3);
		System.out.println(t);

		q = s.length();
		t = s.substring(q-7, q);
		System.out.println(t);

		t = t + s.substring(11, 19);
		System.out.println(t);

		System.out.println("\n2C");
		for (k = 0; k < s.indexOf("|", 0); k++) {
			t = s.substring(k, k+1);
			t = t.toLowerCase();
			if (s.indexOf(t, k) != k) {
				System.out.println(k + "," + t);
			}
		}
	}

	public void question3() {
		// public int median(int[] vals)
		// public boolean[] slice(boolean[] vals, int a, int b)
	}

	public void question4() {
		// double[] vals = new double[51];
	}

	public void question5() {
		// nothing here
	}

	public void question6() {
		int[] nums = {8,6,7,5,3,0,9};
		String s = "all your base are belong to us";
		String t = "base";
		
		// UNCOMMENT THESE ONE AT A TIME FOR TESTING
		
//		// 6A: determine the sum of the numbers
//		int suma = 0;
//		for (int k = 0; k <= nums.length; k++) {
//			suma = suma + nums[k];
//		}
//
//		// 6B: determine the sum of the numbers
//		int sumb = 0;
//		for (int k = nums.length - 1; k >= 0; k--) {
//			sumb = sumb + nums[k];
//		}
//
//		// 6C: determine the sum of the numbers
//		int sumc = 0;
//		for (int k = 0; k < nums.length; k++) {
//			sumc = sumc + nums(k);
//		}
//
//		// 6D: join two strings and convert to upper case
//		//		     for example "Red" and "Blue" becomes "REDBLUE"
//		String newstr = s + t.toUpperCase();
//
//		// 6E: join two strings and convert to upper case
//		//		     for example "Red" and "Blue" becomes "REDBLUE"
//		String joinstr = s + t;
//		joinstr.toUpperCase();
//
//		// 6F: if t appears inside of s, take t out of s
//		if (s.indexOf(t, 0) > -1)
//			s = s – t;
//
//		// 6G: set t to be the characters of s in reverse
//		//		     for example "Red" becomes "deR"
//		t = s.substring(s.length-1, 0);
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	int dk = 0;
	int db = 0;
	
	public void draw() {
		dk = (dk + 1) % 90;
		if (dk == 0) {
			db = (db + 10) % 256;
			background(db);
		}
	}
}
