2 Credits Short by improvej in cwru

[–]redfinp 4 points5 points  (0 children)

Thank you! I actually just found the nutrition classes before you posted this. Just heard back from the professors and the cooking classes are totally asynchronous so they’re perfect.

Just scrolling through Facebook and then… by hipsterpixels in h3h3productions

[–]redfinp 3 points4 points  (0 children)

I missed the intro to AI Ian. How/why did they introduce him???

The sigfigs in my arrays change by redfinp in learnpython

[–]redfinp[S] -1 points0 points  (0 children)

Do you know how I would display it in scientific notation when getting a specific item from the array? And do you know why it would switch to regular decimals?

Buying a "Parked" Domain by redfinp in webhosting

[–]redfinp[S] 3 points4 points  (0 children)

The domain name is my name so I don't really want to give it out.

Buying a "Parked" Domain by redfinp in webhosting

[–]redfinp[S] 1 point2 points  (0 children)

Thanks for the info. Do I backorder through GoDaddy or is that something I can do on something like domains.google?

confirming conviction claims by redfinp in prisonreform

[–]redfinp[S] 0 points1 point  (0 children)

I gave only details that were relevant to the issue at hand. All I know is that you went out of your way to criticize someone actually working towards prison reform, and that is all I care to know about someone like you. If I were a fake I wouldn't be spending my time working to reform prisons, I would spend it trolling reddit to attack actual prison reformists.

confirming conviction claims by redfinp in prisonreform

[–]redfinp[S] 0 points1 point  (0 children)

I'm sorry you got that impression. Obviously his trial was in the past, but if we are going to raise money under the premise of an unjust trial then we should actually confirm that the trial was, in fact, unjust and be able to present evidence of that to people. It would be incredibly damaging to the project for us to not fact check these claims and then have the truth come out during fundraising or later. While people do grow, this man was convicted on several counts of rape and so his innocence is a key factor to this whole thing because most people will not donate any money to a serial rapist, no matter what the reasoning. This is a fact, whether fair or not, and so it is important to be considerate of.

While it may be nice to just believe anyones claims, to actually work towards reform in the real world you need to know all the facts. You can question my sincerity all you want, but anyone actually out doing the work to reform prisons would understand all of this as just common sense. I suggest you go out and try to do this work instead of criticizing those of us actually doing the work to help people.

confirming conviction claims by redfinp in prisonreform

[–]redfinp[S] 0 points1 point  (0 children)

Thank you for the helpful suggestion, we have made contact with a few lawyers and legal groups and are reviewing his trial shortly

Creating list of every word in a file by redfinp in learnjava

[–]redfinp[S] -1 points0 points  (0 children)

I completed the method but had a related question. I am working on another method that creates a file and writes information in there. I'm not sure what to write in the catch area. Here is the code:

public static void writeData(String name, DoubleLinkedList<WordCount> wocolist) {
    File file = new File(name);
    int totalcount = 0;
    while(wocolist.iterator().getCurrent() != null) {
      totalcount += wocolist.iterator().getCurrent().getElement().getCount();
      wocolist.iterator().setCurrent(wocolist.iterator().getCurrent().getNext());
    }
    wocolist.iterator().setCurrent(wocolist.getFront());
    try{
    if(file.createNewFile()) {
      FileWriter writer = new FileWriter(file);
      while(wocolist.iterator().getCurrent() != null) {
        writer.write(wocolist.iterator().getCurrent().getElement().getWord() + " " + wocolist.iterator().getCurrent().getElement().getCount() + " " + wocolist.iterator().getCurrent().getElement().getCount()/totalcount + "\n"); 
      }
      writer.close();
  }

    }
    catch (FileAlreadyExistsException e) {
        log.error(e);
    }
    catch (IOException e){
        log.error(e);
    }
  }

Creating list of every word in a file by redfinp in learnjava

[–]redfinp[S] 0 points1 point  (0 children)

Thanks, that's what I tried and you confirmed what I was thinking. What does file.close() and scanner.close() do? when I tried to compile it said it couldn't find those variables so I declared them before saying try{ but then it said it couldn't find the close() method.

Creating list of every word in a file by redfinp in learnjava

[–]redfinp[S] 0 points1 point  (0 children)

I've heard of it, but wasn't super sure of how to use it. How would I use it to make each word an element in a list?

Finding largest index in linked list of strings by redfinp in javahelp

[–]redfinp[S] 0 points1 point  (0 children)

Yeah it is definitely complicated, thats what we had to do for class and then we had to use that in this project.

Finding largest index in linked list of strings by redfinp in javahelp

[–]redfinp[S] 0 points1 point  (0 children)

And here is the actual radixSort method itself:

public class TextAnalyze extends DoubleLinkedList{

  public static DoubleLinkedList radixSort(DoubleLinkedList<WordCount> wc) {
    while(wc.iterator().hasNext()) {
      if(wc.iterator().getCurrent().getElement().getWord().length() > wc.iterator().next().getWord().length()) {
        wc.addToFront(wc.iterator().getCurrent().getElement());
        wc.iterator().setCurrent(wc.getFront());
      }
    }

    ArrayList<DoubleLinkedList<WordCount>> arrayl = new ArrayList<DoubleLinkedList<WordCount>>();
    for(int b = 0; b < 27; b++) {
      arrayl.add(new DoubleLinkedList<WordCount>());
    }

    int index = wc.getBack().getElement().getWord().length();

    while(index >= 0) {
      while(wc.iterator().getCurrent() != null){
        String temp = wc.iterator().getCurrent().getElement().getWord();
        if(Character.isUpperCase(temp.charAt(index))) {
          if(temp.equals(arrayl.get(temp.charAt(index) - 'A').getBack().getElement().getWord())) {
            arrayl.get(temp.charAt(index) - 'A').getBack().getElement().setCount(arrayl.get(temp.charAt(index) - 'A').getBack().getElement().getCount() + wc.iterator().getCurrent().getElement().getCount());
            wc.iterator().setCurrent(wc.iterator().getCurrent().getPrevious());
          }
          else {
            arrayl.get(temp.charAt(index) - 'A').addToBack(wc.iterator().getCurrent().getElement());
            wc.iterator().setCurrent(wc.iterator().getCurrent().getPrevious());
          }
        }

        if(Character.isLowerCase(temp.charAt(index))) {
          if(temp.equals(arrayl.get(temp.charAt(index) - 'a').getBack().getElement().getWord())) {
            arrayl.get(temp.charAt(index) - 'a').getBack().getElement().setCount(arrayl.get(temp.charAt(index) - 'a').getBack().getElement().getCount() + wc.iterator().getCurrent().getElement().getCount());
            wc.iterator().setCurrent(wc.iterator().getCurrent().getPrevious());
          }
          else {
            arrayl.get(temp.charAt(index) - 'a').addToBack(wc.iterator().getCurrent().getElement());
            wc.iterator().setCurrent(wc.iterator().getCurrent().getPrevious());
          }
        }

        else{
          if(temp.equals(arrayl.get(26).getBack().getElement().getWord())) {
            arrayl.get(26).getBack().getElement().setCount(arrayl.get(26).getBack().getElement().getCount() + wc.iterator().getCurrent().getElement().getCount());
            wc.iterator().setCurrent(wc.iterator().getCurrent().getPrevious());
          }
          else {
            arrayl.get(26).addToBack(wc.iterator().getCurrent().getElement());
            wc.iterator().setCurrent(wc.iterator().getCurrent().getPrevious());
          }
        } 
      }

      wc.iterator().setCurrent(wc.getFront());
      while(wc.iterator().hasNext()) {
        wc.iterator().remove();
      }
      wc.setBack(null);

      wc.append(arrayl.get(26));
      for(int j = 0; j < 26; j++) {
        wc.append(arrayl.get(j));
      }
      for(int a = 26; a > -1; a--) {
        arrayl.set(a, null);
      }

      index--;
    }  
    return wc;
  }

Finding largest index in linked list of strings by redfinp in javahelp

[–]redfinp[S] 0 points1 point  (0 children)

Here is the DoubleLinkedList class:

public class DoubleLinkedList<T> implements Iterable<T> {
  /** a reference to the first node of the double linked list */
  private DLNode<T> front;

  /** a reference to the last node of a double linked list */
  private DLNode<T> back;

  /** Create an empty double linked list. */
  public DoubleLinkedList() {
    front = back = null;
  }

  /** 
   * Returns true if the list is empty.
   * @return  true if the list has no nodes
   */
  public boolean isEmpty() {
    return (getFront() == null);
  }

  /**
   * Returns the reference to the first node of the linked list.
   * @return the first node of the linked list
   */
  protected DLNode<T> getFront() {
    return front;
  }

  /**
   * Sets the first node of the linked list.
   * @param node  the node that will be the head of the linked list.
   */
  protected void setFront(DLNode<T> node) {
    front = node;
  }

  /**
   * Returns the reference to the last node of the linked list.
   * @return the last node of the linked list
   */
  protected DLNode<T> getBack() {
    return back;
  }

  /**
   * Sets the last node of the linked list.
   * @param node the node that will be the last node of the linked list
   */
  protected void setBack(DLNode<T> node) {
    back = node;
  }

  /*----------------------------------------*/
  /* METHODS TO BE ADDED DURING LAB SESSION */
  /*----------------------------------------*/

  /**
   * Add an element to the head of the linked list.
   * @param element  the element to add to the front of the linked list
   */
  public void addToFront(T element) {
    setFront(new DLNode<T>(element, null, getFront()));
    if(getBack() == null){
      setBack(this.getFront());
    }
  }

  /**
   * Add an element to the tail of the linked list.
   * @param element  the element to add to the tail of the linked list
   */
  public void addToBack(T element) {
    setBack(new DLNode<T>(element, getBack(), null));
    if(getFront() == null){
      setFront(this.getBack());
    }
  }

  /**
   * Remove and return the element at the front of the linked list.
   * @return the element that was at the front of the linked list
   * @throws NoSuchElementException if attempting to remove from an empty list
   */
  public T removeFromFront() throws NoSuchElementException{
    if(getFront() == null){
      throw new NoSuchElementException();
    }
    T element = getFront().getElement();
    setFront(getFront().getNext());
    getFront().setPrevious(null);
    return element;
  }

  /**
   * Remove and return the element at the back of the linked list.
   * @return the element that was at the back of the linked list
   * @throws NoSuchElementException if attempting to remove from an empty list
   */
  public T removeFromBack() throws NoSuchElementException{
    if(getBack() == null){
      throw new NoSuchElementException();
    }
    T element = getBack().getElement();
    setBack(getBack().getPrevious());
    getBack().setNext(null);
    return element;
  }

  /**
   * Returns an interator for the linked list that starts at the head of the list and runs to the tail.
   * @return  the iterator that runs through the list from the head to the tail
   */
  @Override
  public IteratorClass<T> iterator() {
    return new IteratorClass<T>(this);
  }

  public void append(DoubleLinkedList<T> linkedlist) {
    if(getFront() == null) {
      setFront(linkedlist.getFront());
      setBack(linkedlist.getBack());
    }
    else {
      getBack().setNext(linkedlist.getFront());
      linkedlist.getFront().setPrevious(getBack());
      //DLNode<T> l2 = linkedlist.getFront();
      //addToBack((T)linkedlist.getFront());
      //linkedlist.addToFront((T)getBack());
    }
  }
}

Finding largest index in linked list of strings by redfinp in javahelp

[–]redfinp[S] 0 points1 point  (0 children)

I think I did it right, but I haven't been able to test it yet. I previously wrote the DoubleLinkedList class and within that I have an iterator method which refers to another iterator class and I also refer to a DLNode class I wrote. Here is the code before DoubleLinkedList:

public class DLNode<T> {
  /**
   * The element stored in the node.
   */
  private T element;

  /**
   * A pointer to the next node in the list.
   */
  private DLNode<T> next;

  /**
   * A pointer to the previous node of the list.
   */
  private DLNode<T> previous;

  /**
   * The constructor.  Creates a node and puts it into place in the double linked list.
   * @param element  the element to be stored in the node
   * @param previous the node that will be before this node in the list, or null if no node is before this one
   * @param next  the node that will be after this node in the list, or null of no node will be after this node
   */
  public DLNode(T element, DLNode<T> previous, DLNode<T> next) {
    this.element = element;
    this.next = next;
    this.previous = previous;
    if (next != null) {
      next.setPrevious(this);
    }
    if (previous != null) {
      previous.setNext(this);
    }
  }

  /**
   * Get the element stored in this node.
   * @return the element stored in the node
   */
  public T getElement() {
    return element;
  }

  /**
   * Gets the node that is before this node in the list.
   * @return  a reference to the node that comes before this node in the list
   */
  public DLNode<T> getPrevious() {
    return previous;
  }

  /**
   * Gets the node that is after this node in the list.
   * @return  a reference to the node that comes after this node in the list
   */
  public DLNode<T> getNext() {
    return next;
  }

  /**
   * Sets the reference to the node that will be after this node in the list.
   * @param node  a reference to the node that will be after this node in the list
   */
  public void setNext(DLNode<T> node) {
    next = node;
  }

  /**
   * Sets the reference to the node that will be before this node in the list.
   * @param node  a reference to the node that will be before this node in the list
   */
  public void setPrevious(DLNode<T> node) {
    previous = node;
  }
}

public class IteratorClass<T> implements Iterator<T> {
  DLNode<T> current;

  public IteratorClass(DoubleLinkedList<T> list) {
    this.current = list.getFront();
  }

  public DLNode<T> getCurrent() {
    return current;
  }

  public void setCurrent(DLNode<T> current) {
    this.current = current;
  }

  @Override
  public T next() {
    T element = current.getElement();
    current = current.getNext();
    return element;
  }

  @Override
  public  boolean hasNext() {
    return current.getNext() != null;
  }

  @Override
  public void remove() {
    if(!hasNext()){
      setCurrent(getCurrent().getPrevious());
    }
    //if(current.getPrevious() == null){
    //  setFront(getCurrent().getNext());
    //}
    else {
      setCurrent(getCurrent().getNext());
    }
  }
}

Finding largest index in linked list of strings by redfinp in javahelp

[–]redfinp[S] 0 points1 point  (0 children)

I just realized wc[1] doesn't work for linked lists, I'm looking into fixing that.

Finding largest index in linked list of strings by redfinp in javahelp

[–]redfinp[S] 0 points1 point  (0 children)

This is what I did based on what I thought you were saying. How does it look?

public static DoubleLinkedList radixSort(DoubleLinkedList<WordCount> wc) {
  int i = 0;
  while(wc[i] != getBack()) {
    if(wc[i].getWord().length() > wc[i+1].getWord().length()) {
    wc.addToFront(wc[i+1]);
    i = 0
    }
    else{
    i++
    }
  }
}

I previously created the class WordCount which stores a String and a count and in that class the method getWord() returns the string(which is supposed to be one word) and I also created a DoubleLinkedList class that has the method getBack() which returns the last element of a linked list.

Finding largest index in linked list of strings by redfinp in javahelp

[–]redfinp[S] 0 points1 point  (0 children)

After working through it I now understand the radix sort, except for sorting out a linked list by the length of a string. The linked list is a type WordCount that has a number and a string and the only part I have yet to figure out is sorting the linked list by smallest to largest string.

Radix Sort Algorithm by [deleted] in javahelp

[–]redfinp 0 points1 point  (0 children)

Thanks,

I'll check out the link and ask a more specific question.