R
Robocop
Dear Folks:
I would extremely appreciate your advices, as it would help me make my
decisions. Please spare some time to read the following.
Here is what happened with me. We had to do an assignment worth only
2%. In it we had to make 7 classes one of them is below.
After spending hours I completed the entire assgn. and I had a little
bug in one of the class given below, so I decided to go to a forum.
There we discussed the problem and one person gave the code GIVEN
BELOW. So I ran it with my other classes and it worked, when I looked
at the code written by the person from the forum I quickly realized
what the _mistake_ in my code was and what changes it needed, as that
mistake was pretty much "trivial" and mediocre; I didn't bother to
correct that mistake in my code and I sent the code from the forum
given below as according to me it was no big deal as no one was ever
going to SEE the code and mark it and also the implementation of the
method in the code given by the person in the forum was pretty good
and no. of lines were few compared to MINE so I favored that code and
NOT mine . Moreover, the code was ONLY going to be marked by a
"TESTDRIVER" AUTOMATICALLY based on the OUTPUTS of the methods.
If you look at the code below (from the forum) and the one after it
(MINE). BOTH the codes will give SAME OUTPUTS if tested by the
TESTDRIVER, so it doesn't matter which code I used.
I've ALSO POSTED THE "method" (at the bottom) in the class written by
me which compelled me to take OUTSIDE HELP.
Now I am charged with >>>"ACADEMIC DISHONESTY"<<< I don't know what to
do now. I thinks its just laughable to be charged for such simple
thing; also me being a first year student, I don't think its fair.
FOR 2% THIS MUCH? I have to lose 5% now because of this.
There were 7 classes and just due to ONE METHOD which accounts to
about 0.2% of the entire assignment.!!!
SO, for thing of 0.2% I've to LOSE 5%????
I could have avoided this whole thing had I known that "we have to add
the name and the address of the reference" from where the segment of
the class was taken from. But being a NOVICE I wasn't aware.
I had with the people in the FORUM and the few things I said about the
INSTITUTION.
SHOULD I GO FOR A FORMAL HEARING IN FRONT OF LOT MORE PEOPLE TO PROVE
MYSELF INNOCENT OR SHOULD I ACCEPT THE CHARGES AND PLEAD *GUILTY* AND
ACCEPT 5% DECREASE IN MY OVERALL RESULT???
PLEASE ADVICE.
/* Folowing is the code that I got from the FORUM*/
import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;
public class Train {
public static final String BERTH = "berth";
public static final String SEAT = "seat";
private Collection railCars = new ArrayList();
// yuck.
public Train(int numSaloonCars, int nSeats, int numSleepingCars,
int nBerths) {
if (numSaloonCars < 0 || nSeats < 0 || numSleepingCars < 0 ||
nBerths < 0)
throw new IllegalArgumentException("No values less than
zero allowed");
if (numSaloonCars + numSleepingCars == 0)
throw new IllegalArgumentException("Gotta have railCars,
baby");
if (nSeats > SaloonCar.MAX_SEATS)
throw new IllegalArgumentException("Too many seats");
if (nBerths > SleepingCar.MAX_BERTHS)
throw new IllegalArgumentException("Too many berths");
railCars = new ArrayList();
for (int i = 0; i < numSaloonCars; i++) {
SaloonCar car = new SaloonCar(nSeats);
railCars.add(car);
}
for (int i = 0; i < numSleepingCars; i++) {
SleepingCar car = new SleepingCar(nBerths);
railCars.add(car);
}
}
// double yuck.
/*RELEVANT PART <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
public String reserveSpace(String spaceType, int numP) throws
TrainFullException {
if (!spaceType.equals(SEAT) && !spaceType.equals(BERTH))
throw new IllegalArgumentException("invalid spacetype");
if (numP < 1) throw new IllegalArgumentException("numP must be
Iterator cars = railCars.iterator();
while (cars.hasNext()) {
RailCar car = (RailCar) cars.next();
if ( (spaceType.equals(SEAT) && car instanceof SaloonCar)
||
(spaceType.equals(BERTH) && car instanceof
SleepingCar) ) {
if (car.getAvailableSpace() >= numP) {
try {
return car.addPassengers(numP);
} catch (CarFullException cfe ) { /* not gonna
happen */ }
}
}
}
// if we get here, nothing's been allocated, so...
throw new TrainFullException();
}
public String toString() {
StringBuffer buf = new StringBuffer("Train[");
Iterator cars = railCars.iterator();
int count = 0;
while (cars.hasNext()) {
if (count++ > 0) buf.append(",");
buf.append(cars.next());
}
return buf.append("]").toString();
}
}
****FOLLOWING IS CODE WRITTEN BY ME, AFTER REVIEWING THE ABOVE CODE, I
JUST NEED TO ADDED >TRY AND CATCH< BLOCKS.
public class Train {
public Train(int numSaloonCars, int nSeats, int numSleepingCars,
int nBerths) {
if((numSaloonCars + numSleepingCars) <= 0
|| (nSeats + nBerths) <= 0 || numSaloonCars < 0 ||
numSleepingCars < 0) {
throw new IllegalArgumentException("input valid data!");
} else {
for(int i = 0; i < numSaloonCars; i++) {
atotal.add(new SaloonCar(nSeats));
}
for(int m = 0; m < numSleepingCars; m++) {
btotal.add(new SleepingCar(nBerths));
}
}
}
/* RELEVANT PART<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
public String reserveSpace(String spaceType, int numP) {
StringBuffer buf = new StringBuffer();
if(( !spaceType.equals(BERTH) && !spaceType.equals(SEAT))
|| (numP <= 0)) {
throw new IllegalArgumentException("enter proper data!");
} else if(spaceType.equals(SEAT)) {
List train = new LinkedList(atotal);
int found = 0;
for(int i = 0; i < train.size(); i++) {
if(((SaloonCar) train.get(i)).getAvailableSpace()>=
numP)
{
found = i;
}
}
try{
buf.append(((SaloonCar)
train.get(found)).addPassengers(numP));
} catch (CarFullException e) {throw new
TrainFullException();}
}
else if(spaceType.equals(BERTH)) {
List train2 = new LinkedList(btotal);
int found2 = 0;
for(int m = 0; m < train2.size(); m++) {
if( ((SleepingCar) train2.get(m)).getAvailableSpace()
found2 = m;
}
}
try{
buf.append(((SleepingCar)
train2.get(found2)).addPassengers(numP));
} catch (CarFullException e) {throw new TrainFullException();}
}
return buf.toString();
}
*/
public String toString() {
StringBuffer buf = new StringBuffer("Train [");
List list = new LinkedList(atotal);
List list2 = new LinkedList(btotal);
for(int i = 0; i < list.size(); i++) {
buf.append(" SaloonCar[ ");
buf.append(((SaloonCar) list.get(i)).toString() + " ]");
}
for(int m = 0; m < list2.size(); m++) {
buf.append(" SleepingCar[ ");
buf.append(((SleepingCar) list2.get(m)).toString() + "
]");
}
return buf.toString();
}
private List atotal = new LinkedList();
private List btotal = new LinkedList();
public static final String BERTH = "berth";
public static final String SEAT = "seat";
}
//////////////////////////////////////////////////////////////////////
/*BELOW IS THE CODE WRITTEN BY ME *BEFORE* GOING TO THE FORUM*/
YOU CAN NOTICE THE ONLY ADDITION IS THE "TRY AND CATCH" BLOCKS.
public String reserveSpace(String spaceType, int numP) {
StringBuffer buf = new StringBuffer();
if(( !spaceType.equals(BERTH) && !spaceType.equals(SEAT))
|| (numP <= 0)) {
throw new IllegalArgumentException("enter proper data!");
} else if(spaceType.equals(SEAT)) {
List train = new LinkedList(atotal);
for(int i = 0; i < train.size(); i++) {
if(numP == ((SaloonCar)
train.get(i)).getAvailableSpace()) {
buf.append(
((SaloonCar)
train.get(i)).addPassengers(numP));
} else if(numP
< ((SaloonCar)
train.get(i)).getAvailableSpace()) {
buf.append(((RailCar)
train.get(i)).addPassengers(numP));
} else {
throw new TrainFullException("Train's Full!");
}
}
} else if(spaceType.equals(BERTH)) {
List train2 = new LinkedList(btotal);
for(int m = 0; m < train2.size(); m++) {
if(numP == ((SleepingCar) train2.get(
m)).getAvailableSpace()) {
buf.append(
((SleepingCar)
train2.get(m)).addPassengers(numP));
} else if(numP
< ((SleepingCar) train2.get(
m)).getAvailableSpace()) {
buf.append(
((SleepingCar)
train2.get(m)).addPassengers(numP));
} else {
throw new TrainFullException("Train's Full!");
}
}
}
return buf.toString();
}
I would extremely appreciate your advices, as it would help me make my
decisions. Please spare some time to read the following.
Here is what happened with me. We had to do an assignment worth only
2%. In it we had to make 7 classes one of them is below.
After spending hours I completed the entire assgn. and I had a little
bug in one of the class given below, so I decided to go to a forum.
There we discussed the problem and one person gave the code GIVEN
BELOW. So I ran it with my other classes and it worked, when I looked
at the code written by the person from the forum I quickly realized
what the _mistake_ in my code was and what changes it needed, as that
mistake was pretty much "trivial" and mediocre; I didn't bother to
correct that mistake in my code and I sent the code from the forum
given below as according to me it was no big deal as no one was ever
going to SEE the code and mark it and also the implementation of the
method in the code given by the person in the forum was pretty good
and no. of lines were few compared to MINE so I favored that code and
NOT mine . Moreover, the code was ONLY going to be marked by a
"TESTDRIVER" AUTOMATICALLY based on the OUTPUTS of the methods.
If you look at the code below (from the forum) and the one after it
(MINE). BOTH the codes will give SAME OUTPUTS if tested by the
TESTDRIVER, so it doesn't matter which code I used.
I've ALSO POSTED THE "method" (at the bottom) in the class written by
me which compelled me to take OUTSIDE HELP.
Now I am charged with >>>"ACADEMIC DISHONESTY"<<< I don't know what to
do now. I thinks its just laughable to be charged for such simple
thing; also me being a first year student, I don't think its fair.
FOR 2% THIS MUCH? I have to lose 5% now because of this.
There were 7 classes and just due to ONE METHOD which accounts to
about 0.2% of the entire assignment.!!!
SO, for thing of 0.2% I've to LOSE 5%????
I could have avoided this whole thing had I known that "we have to add
the name and the address of the reference" from where the segment of
the class was taken from. But being a NOVICE I wasn't aware.
I had with the people in the FORUM and the few things I said about the
INSTITUTION.
SHOULD I GO FOR A FORMAL HEARING IN FRONT OF LOT MORE PEOPLE TO PROVE
MYSELF INNOCENT OR SHOULD I ACCEPT THE CHARGES AND PLEAD *GUILTY* AND
ACCEPT 5% DECREASE IN MY OVERALL RESULT???
PLEASE ADVICE.
/* Folowing is the code that I got from the FORUM*/
import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;
public class Train {
public static final String BERTH = "berth";
public static final String SEAT = "seat";
private Collection railCars = new ArrayList();
// yuck.
public Train(int numSaloonCars, int nSeats, int numSleepingCars,
int nBerths) {
if (numSaloonCars < 0 || nSeats < 0 || numSleepingCars < 0 ||
nBerths < 0)
throw new IllegalArgumentException("No values less than
zero allowed");
if (numSaloonCars + numSleepingCars == 0)
throw new IllegalArgumentException("Gotta have railCars,
baby");
if (nSeats > SaloonCar.MAX_SEATS)
throw new IllegalArgumentException("Too many seats");
if (nBerths > SleepingCar.MAX_BERTHS)
throw new IllegalArgumentException("Too many berths");
railCars = new ArrayList();
for (int i = 0; i < numSaloonCars; i++) {
SaloonCar car = new SaloonCar(nSeats);
railCars.add(car);
}
for (int i = 0; i < numSleepingCars; i++) {
SleepingCar car = new SleepingCar(nBerths);
railCars.add(car);
}
}
// double yuck.
/*RELEVANT PART <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
public String reserveSpace(String spaceType, int numP) throws
TrainFullException {
if (!spaceType.equals(SEAT) && !spaceType.equals(BERTH))
throw new IllegalArgumentException("invalid spacetype");
if (numP < 1) throw new IllegalArgumentException("numP must be
0");
Iterator cars = railCars.iterator();
while (cars.hasNext()) {
RailCar car = (RailCar) cars.next();
if ( (spaceType.equals(SEAT) && car instanceof SaloonCar)
||
(spaceType.equals(BERTH) && car instanceof
SleepingCar) ) {
if (car.getAvailableSpace() >= numP) {
try {
return car.addPassengers(numP);
} catch (CarFullException cfe ) { /* not gonna
happen */ }
}
}
}
// if we get here, nothing's been allocated, so...
throw new TrainFullException();
}
public String toString() {
StringBuffer buf = new StringBuffer("Train[");
Iterator cars = railCars.iterator();
int count = 0;
while (cars.hasNext()) {
if (count++ > 0) buf.append(",");
buf.append(cars.next());
}
return buf.append("]").toString();
}
}
****FOLLOWING IS CODE WRITTEN BY ME, AFTER REVIEWING THE ABOVE CODE, I
JUST NEED TO ADDED >TRY AND CATCH< BLOCKS.
public class Train {
public Train(int numSaloonCars, int nSeats, int numSleepingCars,
int nBerths) {
if((numSaloonCars + numSleepingCars) <= 0
|| (nSeats + nBerths) <= 0 || numSaloonCars < 0 ||
numSleepingCars < 0) {
throw new IllegalArgumentException("input valid data!");
} else {
for(int i = 0; i < numSaloonCars; i++) {
atotal.add(new SaloonCar(nSeats));
}
for(int m = 0; m < numSleepingCars; m++) {
btotal.add(new SleepingCar(nBerths));
}
}
}
/* RELEVANT PART<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
public String reserveSpace(String spaceType, int numP) {
StringBuffer buf = new StringBuffer();
if(( !spaceType.equals(BERTH) && !spaceType.equals(SEAT))
|| (numP <= 0)) {
throw new IllegalArgumentException("enter proper data!");
} else if(spaceType.equals(SEAT)) {
List train = new LinkedList(atotal);
int found = 0;
for(int i = 0; i < train.size(); i++) {
if(((SaloonCar) train.get(i)).getAvailableSpace()>=
numP)
{
found = i;
}
}
try{
buf.append(((SaloonCar)
train.get(found)).addPassengers(numP));
} catch (CarFullException e) {throw new
TrainFullException();}
}
else if(spaceType.equals(BERTH)) {
List train2 = new LinkedList(btotal);
int found2 = 0;
for(int m = 0; m < train2.size(); m++) {
if( ((SleepingCar) train2.get(m)).getAvailableSpace()
{= numP)
found2 = m;
}
}
try{
buf.append(((SleepingCar)
train2.get(found2)).addPassengers(numP));
} catch (CarFullException e) {throw new TrainFullException();}
}
return buf.toString();
}
*/
public String toString() {
StringBuffer buf = new StringBuffer("Train [");
List list = new LinkedList(atotal);
List list2 = new LinkedList(btotal);
for(int i = 0; i < list.size(); i++) {
buf.append(" SaloonCar[ ");
buf.append(((SaloonCar) list.get(i)).toString() + " ]");
}
for(int m = 0; m < list2.size(); m++) {
buf.append(" SleepingCar[ ");
buf.append(((SleepingCar) list2.get(m)).toString() + "
]");
}
return buf.toString();
}
private List atotal = new LinkedList();
private List btotal = new LinkedList();
public static final String BERTH = "berth";
public static final String SEAT = "seat";
}
//////////////////////////////////////////////////////////////////////
/*BELOW IS THE CODE WRITTEN BY ME *BEFORE* GOING TO THE FORUM*/
YOU CAN NOTICE THE ONLY ADDITION IS THE "TRY AND CATCH" BLOCKS.
public String reserveSpace(String spaceType, int numP) {
StringBuffer buf = new StringBuffer();
if(( !spaceType.equals(BERTH) && !spaceType.equals(SEAT))
|| (numP <= 0)) {
throw new IllegalArgumentException("enter proper data!");
} else if(spaceType.equals(SEAT)) {
List train = new LinkedList(atotal);
for(int i = 0; i < train.size(); i++) {
if(numP == ((SaloonCar)
train.get(i)).getAvailableSpace()) {
buf.append(
((SaloonCar)
train.get(i)).addPassengers(numP));
} else if(numP
< ((SaloonCar)
train.get(i)).getAvailableSpace()) {
buf.append(((RailCar)
train.get(i)).addPassengers(numP));
} else {
throw new TrainFullException("Train's Full!");
}
}
} else if(spaceType.equals(BERTH)) {
List train2 = new LinkedList(btotal);
for(int m = 0; m < train2.size(); m++) {
if(numP == ((SleepingCar) train2.get(
m)).getAvailableSpace()) {
buf.append(
((SleepingCar)
train2.get(m)).addPassengers(numP));
} else if(numP
< ((SleepingCar) train2.get(
m)).getAvailableSpace()) {
buf.append(
((SleepingCar)
train2.get(m)).addPassengers(numP));
} else {
throw new TrainFullException("Train's Full!");
}
}
}
return buf.toString();
}