OCA Quiz 3A

  • class Processor{
       void run(Process... tasks){
        for(int i = 0; i < tasks.size()-1;i++){
           System.out.print(tasks[i].getTask()+" ");
          tasks[i].setCompleted(true);
        }
      }
      public static void main(String[] args){
         Processor p = new Processor();
         p.run(new Process("download"),new Process("install"),new Process("read"),new Process("upload"));
      }
    }

    class Process{
      private String task;
      private boolean completed;
      Process(String task){
         this.task = task;
      }
      String getTask(){
         return task;
      }
      void setCompleted(boolean status){
         completed = status;
      }
      boolean getCompleted(){
         return completed;
       }
    }
  • class Processor{
       void run(Process... tasks){
        for(int i = tasks.length-1; i >= 0;i--){
           System.out.print(tasks[i].getTask()+" ");
          tasks[i].setCompleted(true);
        }
      }
      public static void main(String[] args){
         Processor p = new Processor();
         p.run(new Process("download"),new Process("install"),new Process("read"),new Process("upload"));
      }
    }

    class Process{
      private String task;
      private boolean completed;
      Process(String task){
         this.task = task;
      }
      String getTask(){
         return task;
      }
      void setCompleted(boolean status){
         completed = status;
      }
      boolean getCompleted(){
         return completed;
       }
    }
  • class Processor{
       void run(Process... tasks){
        for(int i = tasks.length-1; i >= 0;i--){
           System.out.print(tasks[i].getTask()+" ");
          tasks[i].setCompleted(true);
        }
      }
      public static void main(String[] args){
         Processor p = new Processor();
         p.run(new Process[]{new Process("download"),new Process("install"),new Process("read"),new Process("upload")});
      }
    }

    class Process{
      private String task;
      private boolean completed;
      Process(String task){
         this.task = task;
      }
      String getTask(){
         return task;
      }
      void setCompleted(boolean status){
         completed = status;
      }
      boolean getCompleted(){
         return completed;
       }
    }
  • class Processor{
       void run(Process... tasks, boolean completed){
        for(int i = tasks.length-1; i >= 0;i--){
           System.out.print(tasks[i].getTask()+" ");
          tasks[i].setCompleted(completed);
        }
      }
      public static void main(String[] args){
         Processor p = new Processor();
         p.run(new Process("download"),new Process("install"),new Process("read"),new Process("upload"),true);
      }
    }

    class Process{
      private String task;
      private boolean completed;
      Process(String task){
         this.task = task;
      }
      String getTask(){
         return task;
      }
      void setCompleted(boolean status){
         completed = status;
      }
      boolean getCompleted(){
         return completed;
       }
    }
  • class Crazy{
       public static void main(String[] args){
         StringBuilder sb = new StringBuilder("I hate & test!");
         //n1
         System.out.println(sb);
      }
    }
  • class Crammy{
       public static void main(String[] args){
         StringBuilder sb = new StringBuilder(5);
         sb.ensureCapacity(6);
        sb.append("").append("").append("").append("").append("").append("").append("");
        System.out.println(sb.capacity()+sb.length());
      }
    }
  • Ignore the quotes in the for loop, that was in order to make it display properly.
    class Block{
       private String type;
      Block(String type){
         this.type = type;
       }
       String getType(){return type;}
    }

    class Crammy{
      public static void main(String[] args){
         Block[][] blocks = new Block[4][];
         blocks[0] = {new Block("grass"),new Block("grass"),new Block("grass")};
         blocks[1] = {new Block("stone"),new Block("stone"),new Block("stone")};
         blocks[2] = {new Block("stone"),new Block("stone"),new Block("stone")};
         blocks[3] = {new Block("bedrock"),new Block("bedrock"),new Block("bedrock")};
         for(int y=0;"y< blocks.length";y++){
           for(int x = blocks[y].length-1;x>=0;x--){
             System.out.print(blocks[y][x].getType());
           }
         }
       }
    }
  • Ignore the quotes in the for loop, that was in order to make it display properly.
    class Block{
       private String type;
      Block(String type){
         this.type = type;
      }
      String getType(){return type;}
    }

    class Crammy{
      public static void main(String[] args){
         Block[][] blocks = new Block[4][]{
        {new     Block("grass"),new Block("grass"),new Block("grass")},
        {new Block("stone"),new Block("stone"),new Block("stone")},
        {new Block("stone"),new Block("stone"),new Block("stone")},
        {new Block("bedrock"),new Block("bedrock"),new Block("bedrock")}};
        for(int y = 0;"y< blocks.length";y++){
          for(int x = blocks[y].length-1;x>=0;x--){
            System.out.print(blocks[y][x].getType());
          }
        }
      }
    }
  • Ignore the quotes in the for loop, that was in order to make it display properly.
    class Block{
       private String type;
      Block(String type){
         this.type = type;
      }
      String getType(){return type;}
    }

    class Crammy{
      public static void main(String[] args){
         Block[][] blocks = new Block[][]{
        {new Block("grass"),new Block("grass"),new Block("grass")},
        {new Block("stone"),new Block("stone"),new Block("stone")},
        {new Block("stone"),new Block("stone"),new Block("stone")},
        {new Block("bedrock"),new Block("bedrock"),new Block("bedrock")}};
        for(int y = 0;"y< blocks.length";y++){
          for(int x = blocks[y].length-1;x>=0;x--){
            System.out.print(blocks[y][x].getType());
          }
        }
      }
    }
  • class Wiggle{
       public static void main(String[] args){
        StringBuilder secret = new StringBuilder(2);
        secret.append(true);
        secret.append(false);
        secret.append(true);
        System.out.println(secret.reverse());
        System.out.println(secret.capacity());
      }
    }