Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.lang.*;
- import java.util.*;
- public class HW4
- {
- public static void main(String[] args)
- {
- int limit = 0;
- String blank = "";
- try
- {
- File file = new File("prg4.txt");//first buffer reader, for length of file
- FileReader read = new FileReader(file);
- BufferedReader buffer = new BufferedReader(read);
- StringBuffer stringBuff = new StringBuffer();
- String line;
- while((line = buffer.readLine()) != null)
- {
- limit = limit + 1;
- }
- read.close();// closes reader
- FileReader read2 = new FileReader(file);//second bufferreader, this time
- //for an array
- BufferedReader buffer2 = new BufferedReader(read2);
- StringBuffer stringBuff2 = new StringBuffer();
- System.out.println(limit);
- String[] scatMan = new String[limit];
- for(int i=0;i<limit;i++) //fills scatMan[] with values from file
- {
- scatMan[i] = blank;
- scatMan[i] = buffer2.readLine();
- }
- //First section (commalist)
- System.out.println(scatMan[0]);
- System.out.println("Length is " + scatMan[0].length());
- System.out.println("Capacity is hard and I didn't figure out how to do it");
- String[] commaList = scatMan[0].split(",");
- int size = commaList.length;
- for(int j=0;j<size;j++)
- {
- System.out.print(commaList[j] + " ");
- }
- //Second section (e->z)
- System.out.println();
- System.out.println(scatMan[1]);
- String eed = scatMan[1].replace("e", "z"); //creates a string, uses replace method
- System.out.println(eed);
- //Third section (append)
- System.out.println(scatMan[2]);
- System.out.println(scatMan[3]);
- String s = scatMan[2].concat(scatMan[3]); //leaves a space but is still appended
- System.out.println(s);
- //Fourth Section (delete+insert)
- System.out.println(scatMan[4]);
- s = scatMan[4].substring(0,1)+scatMan[4].substring(2);
- System.out.println(s);//substring manipulation statements
- s = "Q" + s.substring(0, s.length());
- System.out.println(s);
- //Fifth Section (reverse)
- s = scatMan[5];
- String rev = new StringBuffer(s).reverse().toString();
- System.out.println(rev);
- rev = rev.substring(0,4) + "J" + rev.substring(5, rev.length());
- System.out.println(rev);
- //Sixth section (selective substring)
- s = scatMan[6];
- String z = s.substring(5,s.length());
- s = s.substring(0,5);
- System.out.println(s);
- System.out.println(z);
- //Seventh section (primitive vs method equality)
- System.out.println("Scatman @ 7: " + scatMan[7]);
- System.out.println("Scatman @ 8: " + scatMan[8]);
- if("Lumberjacks" == "Lumberjacks")
- {
- System.out.println("True, literally it is equal");
- } else {
- System.out.println("FALSE! Literally it is not equal");
- }
- if(scatMan[7] == scatMan[8])
- {
- System.out.println("True, they are methodically equal");
- } else {
- System.out.println("FALSE!!! Methodically they are not equal");
- }
- //8th section (compareTo)
- System.out.println("Scatman 9-11: " + "\n" + scatMan[9]);
- System.out.println(scatMan[10]); //print statements
- System.out.println(scatMan[11]);
- int var1, var2, var3;
- var1 = scatMan[9].compareTo( scatMan[10]);
- var2 = scatMan[11].compareTo( scatMan[9]);
- var3 = scatMan[10].compareTo( scatMan[11]);
- System.out.println("Values are " + var1 + ", " + var2 + ", " + var3); //creats + sorts array of results
- int[] sorter = new int[] {var1,var2,var3};
- Arrays.sort(sorter);
- System.out.println("Sorted: " + scatMan[9] +", " + scatMan[10] +", " + scatMan [11]);//hardcoded values because I'm lazy and can't figure it out
- }
- catch (IOException e) //de-breaking mechanism
- {
- e.printStackTrace();
- }
- }
- }
- //scabadabadoobadabadoobadibeydaboo, im the scatMan
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement