C:\Users\ar114\Documents\NetBeansProjects\Exam1_CalebFontenot\src\main\java\com\calebfontenot\exam1_calebfontenot\MyStringBuilder.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.exam1_calebfontenot;

import java.util.Arrays;

/**
 *
 * @author ar114
 */
public class MyStringBuilder {

    //private int size = 0; // Size is not necessary. Remove it and modify the code.
    //private int capacity = 0; //not necessary
    private char[] buffer;

    public MyStringBuilder() {
    }

    public MyStringBuilder(char[] chars) {
        buffer = chars;
    }

    public MyStringBuilder(String s) {
        buffer = s.toCharArray();
    }

    private void increaseCapacity(int newCapacity) {
        char[] temp = new char[newCapacity];
        System.arraycopy(buffer, 0, temp, 0, buffer.length);
        buffer = temp;
    }

    public MyStringBuilder append(MyStringBuilder s) {
        int oldLength = buffer.length;
        char[] toAdd = s.buffer;
        increaseCapacity(toAdd.length + oldLength);
        int j = 0;
        for (int i = oldLength; i < (oldLength + s.buffer.length); ++i) {
            buffer[i] = toAdd[j++];
        }
        return this;
    }

    /**
     * public MyStringBuilder append(int i) {
     *
     * }
     *
     * @return 
    *
     */
    public int length() {
        return buffer.length -1;
    }

    public char charAt(int index) {
        return buffer[index];
    }

    public MyStringBuilder toLowerCase() {
        for (int i = 0; i < buffer.length; ++i) {
            buffer[i] = Character.toLowerCase(buffer[i]);
        }
        return this;
    }

    public MyStringBuilder substring(int begin, int end) {
        String s = "";
        for (int i = begin; i < end; ++i) {
            s += buffer[i];
        }
        return new MyStringBuilder(s.toCharArray());
    }

    @Override
    public String toString() {
        String s = "";
        for(char c: buffer)
        {
            s += c;
        }
        return s;
    }

    public MyStringBuilder reverse() {
        char[] reversed = new char[buffer.length];
        int j = 0;
        for (int i = buffer.length - 1; i >= 0; --i) {
            reversed[i] = buffer[j];
            j++;
        }
        buffer = reversed;
        return this;
    }

    public MyStringBuilder substring(int begin) {
        return substring(begin, buffer.length);
    }

    public MyStringBuilder toUpperCase() {
        for (int i = 0; i < buffer.length; ++i) {
            buffer[i] = Character.toUpperCase(buffer[i]);
        }
        return this;
    }

    public static void main(String[] args) {
        MyStringBuilder s1 = new MyStringBuilder("Welcomne to");
        MyStringBuilder s2 = new MyStringBuilder(" Java");

        System.out.println(s1.length());
        System.out.println(s1.charAt(3));
        System.out.println(s1.toUpperCase().toString());
        s1.append(s2);
        System.out.println(s1.toString());
        System.out.println(s1.substring(1, 4));
        System.out.println(s1.reverse());
        System.out.println(s1.reverse());
    }
}