Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   i think i found a cheater (http://www.programmingforums.org/showthread.php?t=11472)

bigrodey77 Oct 3rd, 2006 5:34 PM

i think i found a cheater
 
Hello,

While this may seem petty to some, I would like to know what some people think about these 2 sets of code. Here is the story.

I finished an assignment for my Java class and was helping another kid in my class on his. I put my thumb drive in the computer he was working on to pull up my code to check something. Long story short, I forget to get my thumb drive back until about an hour later when I remembered.

I told the kid when I was helping him if he needed anything to IM me. Now he's asking for help and he sent me his code and it's really similiar to mine. I know some of it will be similiar because I told him the way I did mine and showed him my code, but he can barely write complete if/else and basic import statements.

The code consists of 4 total classes:
2 classes from my project
2 classes from his project
I have all the code here and if some of you could take a look at it and let me know what you think about the similarities, I'd appreciate it. I'm not failing a class or taking a zero because he can't do the assignment on his own.

Sorry if I sound petty, I'm really not. I just don't like when people copy my work and then ask me questions on how to do something like they did it on their own.

I guess I should probably include what the program does. It's just a small simulator for "Paper, Scissors, Rock" where you create two hands, assign them values, compare them, then report the winner. If anyone wants me to post the assignment, let me know.

Thanks!

My Code: HandThrow Class
:

package rps;

import java.io.*;
import java.util.*;

public class HandThrow {
    public static void main(String args[]) {
        Hand hand1 = new Hand(); //Throws hands strategically
        Hand hand2 = new Hand(); //Throws hands randomly
        Random r = new Random();
        int amountWon = 0;  //Records how many times hand1 won
        int amountLost = 0; //Records how many times hand1 lost
        int amountPush = 0; //Records how many times the hands pushed
        int test;

        for (int i = 0; i < 50; i++) {
            hand1.setState( (i+3) % 3 ); //Throws in the order Rock, Paper, Scissors
            hand2.setState( r.nextInt(3) ); //Throws randomly

            test = hand1.winner(hand1,hand2); //Returns 1 if hand1 won, 0 if hand1 loses, -1 if push

            if (test == 1)
                amountWon++;
            else if (test == 0)
                amountLost++;
            else if (test == -1)
                amountPush++;
        }

        System.out.println("Hand1 won : " + amountWon);
        System.out.println("Hand1 lost: " + amountLost);
        System.out.println("Pushes    : " + amountPush);
    }
}


My Code: Hand Class
:

package rps;

//Ryan Rodemoyer
//Assignment02

import java.util.*;
import java.io.*;

public class Hand {
    private String state;

    public Hand() {
        state = null;
    }

    //Sets the state to either rock, paper, or scissors
    public void setState(int thrown) {
        switch (thrown) {
        case 0: state = "Rock"; break;
        case 1: state = "Paper"; break;
        case 2: state = "Scissors"; break;

        default: state = "ERROR";
        }
    }

    public String getState() {
        return state;
    }

    public int winner(Hand hand1, Hand hand2) {
        //Return values
        //1  --> hand1 won
        //0  --> hand1 lost
        //-1 --> push

        int outcome = 0;
        String hand1Thrown, hand2Thrown;

        hand1Thrown = hand1.getState();
        hand2Thrown = hand2.getState();

        if (hand1Thrown == "Rock") {
            if (hand2Thrown == "Rock") //Push
                outcome = -1;
            else if (hand2Thrown == "Paper") //Lost
                outcome = 0;
            else if (hand2Thrown == "Scissors") //Won
                outcome = 1;
        }
        else if (hand1Thrown == "Paper") {
            if (hand2Thrown == "Rock") //Won
              outcome = 1;
          else if (hand2Thrown == "Paper") //Push
              outcome = -1;
          else if (hand2Thrown == "Scissors") //Lost
              outcome = 0;
        }
        else if (hand1Thrown == "Scissors") {
            if (hand2Thrown == "Rock") //Took the big 'L'
              outcome = 0;
          else if (hand2Thrown == "Paper") //Smash'd em
              outcome = 1;
          else if (hand2Thrown == "Scissors") //Pushed :-/
              outcome = -1;
        }
        return outcome;
    }
}


His Code: assign02 class (my HandThrow Class)
:

package testrps;

import java.util.Random;
import java.io.*;
import java.util.*;

public class assign02 {
  public static void main(String[] args) {
    hand hand1 = new hand();
    hand hand2 = new hand();
    int wins;
    int losses;
    int ties;
    int tester;

    if (hand1 == 0)
        hand1 = "rock";
    else if (hand1 == 1)
        hand1 = "paper";
    else if (hand1 == 2)
        hand1 = "scissors";

    for(tester = 1; tester <=50; tester++){
        Random r = new Random();
        hand hand1 = (r.Random(3));
        hand hand2 = (2);
    }
System.out.print("wins:" + wins);
System.out.print("\n" + "losses:" + losses);
System.out.print("\n" + "ties:"  + ties);
 }
}


His Code: hand class
:

package testrps;

import java.util.*;
import java.io.*;
public class hand{
  String rps;
  hand() {
      rps = null;
  }

    public void setstate(int handthrow) {
      switch (handthrow) {
      case 0:
          rps = "rock";
          break;
      case 1:
          rps = "paper";
          break;
      case 2:
          rps = "scissors";
      default:
          rps = "invalid";
      }
  }

  public String getstate() {
      return rps;
  }
  public static String game(hand hand1, hand hand2) {
      String results="";
      String handthrow1, handthrow2;
      handthrow1 = hand1.getstate();
      handthrow2 = hand2.getstate();
      if (handthrow1 == "rock") {
          if (handthrow2 == "rock")
              results = "tie";
          else if (handthrow2 == "paper")
              results = "lost";
          else if (handthrow2 == "scissors")
              results = "won";
      }
      else if (handthrow1 == "paper") {
          if (handthrow2 == "rock")
              results = "won";
          else if (handthrow2 == "paper")
              results = "tie";
          else if (handthrow2 == "scissors")
              results = "lost";
      } else if (handthrow1 == "scissors") {
          if (handthrow2 == "rock")
              results = "lost";
          else if (handthrow2 == "paper")
              results = "won";
          else if (handthrow2 == "scissors")
              results = "tie";
      }
      return results;
  }
}


titaniumdecoy Oct 3rd, 2006 5:50 PM

From what I can tell from looking at the code, while it is entirely possible he copied from you, it is also possible that he wrote it himself. There are definitely many similarities, but that is to be expected for such a short program. If I were you, I would ask him; it can't hurt.

An unrelated point of interest: As you are treating the throws as 0, 1, and 2, it is possible to determine the winner (-1, 0, or 1) in less than 4 lines of code using simple arithmetic.

MBirchmeier Oct 3rd, 2006 5:58 PM

As much as getting validation that these may or may not be the same on an online forum might feel good, it gets nothing done toward potentially keeping you from failing.

A better approach might be to talk to your teacher, tell him you forgot your jump drive after helping a student (don't mention the name of the other student unless you must) and that you aren't sure if the code was copied or not, and show samples of each code.

If you're not comfortable going to your teacher, go to a teacher that teaches similar material, or an advisor for the program (if in college).

While titanium's suggestion of confronting the student might work, most likely the student will deny that there's a problem either way (either because he didn't realize he copied it or that he thought simply changing variable names would be sufficient, or because he truly did copy your code and doesn't want to get caught).

I'd be willing to bet though if you went to the teacher, told your concerns, the teacher would keep an eye out for such things, and not worry that you were cheating, since it matches your coding style, you know what the things do, and you were upfront about it.

-MBirchmeier

Sane Oct 3rd, 2006 5:59 PM

Quote:

Originally Posted by titaniumdecoy
As you are treating the throws as 0, 1, and 2, it is possible to determine the winner (-1, 0, or 1) in less than 4 lines of code using simple arithmetic.

titaniumdecoy is definitely correct. That's the smart way to go. Impress your teacher. ;)

bigrodey77 Oct 3rd, 2006 6:06 PM

This assignment is due tomorrow (Wednesday) and I turned my code in Friday. Not to be egotistical or anything, but this class is very easy to me. I transferred from a different school (this is my 5th year of college) and I did not get credit for this "advanced" programming class. The teacher knows I am ahead most of the students in the class in terms of skill. I "hope" she will know that I did not copy off of him and that I would not just blatanly give my work to someone. That's retarded.

DaWei Oct 3rd, 2006 6:25 PM

If you're that good, the teacher must realize that someone else won't spring to that level overnight. You only have to worry that the teacher might think you're so dumb as to give it away on purpose. MBirchmeier's post represents your best bet, in my opinion.

andro Oct 4th, 2006 4:50 AM

You should have made a Hand superclass and then created subclasses like RandomHand, StrategicHand, etc.. that inherited :P Let each class of hand worry about setting its state based on its strategy, rather than having the "driver" do it.

bigrodey77 Oct 4th, 2006 9:48 AM

Quote:

An unrelated point of interest: As you are treating the throws as 0, 1, and 2, it is possible to determine the winner (-1, 0, or 1) in less than 4 lines of code using simple arithmetic.
I was screwing around with that last night and wouldn't you need to add -2 and 2 to determine the winner instead of just -1, -0, 1?

MBirchmeier Oct 4th, 2006 10:06 AM

Quote:

Originally Posted by bigrodey77 (Post 115763)
I was screwing around with that last night and wouldn't you need to add -2 and 2 to determine the winner instead of just -1, -0, 1?

Answer = Answer mod 3 ;)

-MBirchmeier

bl00dninja Oct 5th, 2006 3:54 AM

i had a similar problem last semester when this guy always wanted to "work with me" on some project. fortunately that faggot changed his major or something. i do not collaborate with other students, google knows more than they do, and the prof is paid to help you if you need it. the only people i ever might ask for help from is ya'll, since ya'll do not have any real vested interest in the stuff i'm working on.

the blind leading the blind...

oh, and i have a wife and kid and job and shit, so realistically, i don't have time to waste helping others...WHICH SOUNDS AWFUL...but for real, i don't have time for myself, so i don't have time for them. i love video games and i think since the start of the semester 2 months ago, i've gotten to play 3 times...this christmas i WILL be playing the new splinter cell if it ever comes out...beat the last one last year during christmas break.

:)


All times are GMT -5. The time now is 1:14 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC