Make your own free website on Tripod.com
« November 2017 »
S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
You are not logged in. Log in
Entries by Topic
All topics  «
AP 1
Javabat
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
AP Computer Science
Wednesday, 5 November 2008
DISCLAIMER

THE CONTENT PROVIDED ON THIS SITE IS NOT TO BE HANDED IN OR COPIED FOR PERSONAL USE. IT IS JUST A REFERENCE FOR STUDENTS THAT NEED HELP WITH CERTAIN ASSIGNMENTS. THE CREATORS OF THIS SITE IS NOT RESPONSIBLE FOR THE MISUSE OF INFORMATION PROVIDED. DO NOT USE THIS SITE FOR CHEATING.

 

BY VISITING THIS WEBSITE AND LOOKING AT THE ANSWERS PROVIDED, YOU TAKE FULL RESPONSIBILITY FOR THE CONSEQUENCES. 

 

-The Creators 

 

 


Posted by mcleancompsci at 9:36 AM EST
Updated: Friday, 7 November 2008 8:10 AM EST
String 2 Solutions
Topic: Javabat

doubleChar

public String doubleChar(String str) {
  String s = "";
  char ch;
  for(int j = 0; j < str.length(); j++){
  ch = str.charAt(j);
  s=s+ch+ch;
  }
  return s;
}

 

countHi

public int countHi(String str) {
  int count = 0;
  for(int i = 1; i < str.length(); i ++){
  if(str.substring(i-1,i+1).equals("hi"))count ++;
  }
  return count;
}

 

catDog

public boolean catDog(String str) {
  int catcount = 0;
  int dogcount = 0;
  for(int i = 2; i < str.length(); i ++){
  if(str.substring(i-2,i+1).equals("cat"))catcount ++;
  if(str.substring(i-2,i+1).equals("dog"))dogcount ++;
  }
  if(catcount != dogcount){
  return false;
  }
  else{
  return true;
  }
}


Posted by mcleancompsci at 9:34 AM EST
Array 2 Solutions
Topic: Javabat

countEvens 

public int countEvens(int[] nums) {
int count = 0;
for(int i = 0; i < nums.length; i ++){
if(Math.abs(nums[i]%2) != 1){
count ++;
}
}
return count;
}

 

bigDiff

public int bigDiff(int[] nums) {
int big = 0;
int small = 1000;
for(int i = 0; i < nums.length; i ++){
if(nums[i] > big) big = nums[i];

if(nums[i]< small) small = nums[i];
}
return big-small;
}

 

sum13

public int sum13(int[] nums) {
int empty = 0;
if(nums.length ==0){
return empty;
}else{
for(int i =0; i < nums.length; i ++){
if(nums[i] <13){
empty += nums[i];
}else{
i ++;
}
}
}
return empty;
}
 


Posted by mcleancompsci at 9:32 AM EST
String 1 Solutions
Topic: Javabat

helloName

public String helloName(String name) {
  return "Hello " + name+ "!";
}

 

makeAbba

public String makeAbba(String a, String b) {
  return (a + b + b + a);
}

 

makeTags

public String makeTags(String tag, String word) {
  return "<" + tag + ">" + word + "</" + tag + ">";
}

 

makeOutWord

public String makeOutWord(String out, String word) {
  
   String a = out.substring(0, 2);
   String b = out.substring(2, 4);
   return a + word + b;
}

 

extraEnd

public String extraEnd(String str) {
  String a = str.substring(str.length() - 2, str.length());
  return a + a + a;
}

 

firstTwo

public String firstTwo(String str) {
  if(str.length() < 2){
  return str;
  }
  if(str.length() >= 2){
  String a = str.substring(0, 2);
  return a;
  }
  else{
  return "";
  }
}

 

firstHalf

 public String firstHalf(String str) {
  String a = str.substring(0, str.length() / 2);
  return a;
}

 

withoutEnd

public String withoutEnd(String str) {
 String a = str.substring(1, str.length() - 1);
 return a;
}

 

nonStart

public String nonStart(String a, String b) {
  String a1 = a.substring(1, a.length());
  String b1 = b.substring(1, b.length());
  return a1 + b1;
}

 

withouEnd2

public String withouEnd2(String str) {
  if(str.length() >= 2){
  String a = str.substring(1, str.length() - 1);
  return a;
  }
  if(str.length() < 2){
    return "";
  }
  else{
  return "";}
}

 

middleTwo

public String middleTwo(String str) {
  if(str.length() >= 2){
  String a = str.substring(str.length() / 2 - 1, str.length() / 2 + 1);
  return a;
  }
  else{
  return "";}
  }

 

endsLy

public boolean endsLy(String str) {
 
  String a = str.substring(str.length() - 2, str.length());
  if(str.length() >= 2 && a == "ly"){
  return true;
  }
  else{
  return false;
  }
  }


Posted by mcleancompsci at 9:27 AM EST
Updated: Wednesday, 5 November 2008 9:32 AM EST
Logic Solutions
Topic: Javabat

cigarParty

public boolean cigarParty(int cigars, boolean isWeekend) {

if(isWeekend && cigars >= 40){
return true;
}
if(!isWeekend && cigars >= 40 && cigars <= 60){
return true;
}
else{
return false;
}
}

 

squirrelPlay

public boolean squirrelPlay(int temp, boolean isSummer) {

if(isSummer && temp <= 100 && temp >= 60){
return true;
}
if(!isSummer && temp >= 60 && temp <= 90){
return true;
}
else{
return false;
}
}

 

caughtSpeeding

public int caughtSpeeding(int speed, boolean isBirthday) {
 
  if(!isBirthday && speed <= 60){
  return 0;
  }
  if(!isBirthday && speed >= 61 && speed <= 80){
  return 1;
  }
  if(!isBirthday && speed >= 81){
  return 2;
  }
  if(isBirthday && speed <= 65){
  return 0;
  }
  if(isBirthday && speed >= 66 && speed <= 85){
  return 1;
  }
  if(isBirthday && speed >= 86){
  return 2;
  }
  else{
  return 0;}
  }

 

sortaSum

public int sortaSum(int a, int b) {
  if(a+b>=10 && a+b<=19){
  return 20;
  }
  else{
  return a+b;} 
}

 

answerCell

public boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep) {
 
  if(isAsleep){
  return false;
  }
  if(isMorning && isMom){
  return true;
  }
  if(isMorning && !isMom){
  return false;
  }
  if(!isMorning){
  return true;
  }
  else{
  return true;
  }
}

 

twoAsOne

public boolean twoAsOne(int a, int b, int c) {
  if(a + b == c){
  return true;
  }
  if(b + c == a){
  return true;
  }
  if(a + c == b){
  return true;
  }
  else{
  return false;
  }
}

 

redTicket

public int redTicket(int a, int b, int c) {
  if(a + b + c == 6){
  return 10;
  }
  if(a == b && a == c && b == c){
  return 5;
  }
  if(a != b && a != c){
  return 1;
  }
  else{
  return 0;
  }
}

 

luckySum

 public int luckySum(int a, int b, int c) {
  if(a==13){
  return 0;
  }
  if(b==13){
  return a;
  }
  if(c==13){
  return a+b;
  }
  else{
  return a+b+c;
  }
}

 

blackJack

public int blackjack(int a, int b) {
  if(a>b && a <= 21){
  return a;
}
if(b>a && b <= 21){
return b;
}
if(a>21 && b<=21){
return b;
}
if(b>21 && a<=21){
return a;
}
if(a>21 && b>21){
return 0;
}
else{
return 0;
}
}

 

 

 

 


Posted by mcleancompsci at 9:22 AM EST
Updated: Wednesday, 5 November 2008 9:31 AM EST
Array 1 Solutions
Topic: Javabat

firstLast6

public boolean firstLast6(int[] nums) {
  if (nums[0]==6)
  return true;
  else if (nums[nums.length-1]==6)
  return true;
  else return false;
}

 

sameFirstLast

public boolean sameFirstLast(int[] nums) {
  int index;
if (nums.length <1)
return false;
else index =nums[0];
 if (nums.length >=1 && nums[0]==nums[nums.length-1])
  return true;
else  return false;
}

makePi

public int[] makePi(){

int[] x= new int[3];
x[0]=3;
x[1]=1;
x[2]=4;

return x;

}

 

commonEnd

public boolean commonEnd(int[] a, int[] b) {
  if (a[0]==b[0] || a[a.length-1] == b[b.length-1])
  return true;
  else return false;


}

 

sum3

 public int sum3(int[] nums) {
    int a = nums[0]+nums[1]+nums[2];
  return a;
}

 

rotateLeft3

public int[] rotateLeft3(int[] nums) {
int a = nums[0];
 
  for (int b = 1; b < 3; b++){
 nums[b-1]= nums[b];
  }
  nums[2]=a;
  return nums;
}

 

reverse3

 public int[] reverse3(int[] nums) {
  int a = nums[0];
  nums[0]= nums[2];
  nums[2]=a;
  return nums;
}

 

maxEnd3

public int[] maxEnd3(int[] nums) {
  int max = 0;
  for (int a = 0; a < 3; a+=2){
  if (nums[a] > max)
  max = nums[a];
  }
  for (int b = 0; b < 3; b++){
  nums[b] = max;
  }
  return nums;
}

 

sum2

public int sum2(int[] nums) {
 if (nums.length >= 2)
  return nums[0]+nums[1];
 else
 if (nums.length == 0)
 return 0;
 else
 return nums[0];
 
}

 

middleWay

public int[] middleWay(int[] a, int[] b) {
  int mid = a[1];
  int mid2 = b[1];
  int[] my = new int[2];
  my[0] = mid;
  my[1] = mid2;
  return my;
}

 

makeEnds

public int[] makeEnds(int[] nums) {
  int first = nums[0];
  int last = nums[nums.length-1];
  int[] my = new int[2];
  my[0] = first;
  my[1] = last;
  return my;
 
}

 

start1

public int start1(int[] a, int[] b) {
  int first=0;
  int sec=0;
  if (a.length > 0)
  first = a[0];
  if (b.length > 0)
  sec = b[0];
  if(first == 1 && sec ==1)
  return 2;
  else
  if(first ==1 || sec==1)
  return 1;
  else
  return 0;
}

 

biggerTwo

public int[] biggerTwo(int[] a, int[] b) {
  int sum = 0;
  int sum2 = 0;
for(int c = 0; c < a.length; c++){
sum += a[c];
}
for( int d = 0; d < b.length; d++){
sum2+= b[d];
}
if(sum2 > sum)
return b;
else
return a;
}

 

makeMiddle

public int[] makeMiddle(int[] nums) {
  int first = nums[nums.length / 2 -1];
  int sec = nums[nums.length / 2];
  int[] my = new int[2];
  my[0] = first;
  my[1] = sec;
return my;
}

 

plusTwo

 public int[] plusTwo(int[] a, int[] b) {
 int[] my = new int[4];
 my[0]= a[0];
 my[1]= a[1];
 my[2] = b[0];
 my[3] = b[1];
return my;
}

 

swapEnds

public int[] swapEnds(int[] nums) {
  int first = nums[0];
  nums[0]=nums[nums.length -1];
  nums[nums.length-1]=first;
  return nums;
 
}

 

midThree

public int[] midThree(int[] nums) {
  int first = nums[(nums.length -1) / 2 -1];
  int mid = nums[(nums.length -1) / 2];
  int last = nums[(nums.length -1) / 2 +1];
  int[] my = new int[3];
  my[0]=first;
  my[1]=mid;
  my[2]= last;
  return my;
}

 

maxTriple

public int maxTriple(int[] nums) {
  int first = nums[0];
  int mid = nums[(nums.length-1) / 2 ];
  int last = nums[nums.length -1];
  int max = first;
  if(mid > max)
  max = mid;
  if( last > max)
  max = last;
  return max;
}

 

frontPeice

public int[] frontPiece(int[] nums) {
  int[] my = new int[0];
  if(nums.length > 1){
 int[] my2 = new int[2];
  my2[0] = nums[0];
  my2[1] = nums[1];
  return my2;
  }
  else
  if(nums.length == 1){
int[] my3 = new int[1];
  my3[0]= nums[0];
  return my3;
 
  }
  return my;
 
}

 

unlucky1 

public boolean unlucky1(int[] nums) {
  if( nums.length < 2)
  return false;
  else
  if ( nums [0]==1 && nums[1]==3)
  return true;
  if (nums[nums.length-2]==1 && nums[nums.length-1]==3)
  return true;
  if (nums [1]==1 && nums[2]==3)
  return true;
  return false;
  }

 

 


Posted by mcleancompsci at 9:16 AM EST
AP1 Solutions
Topic: Javabat

scoresIncreasing

public boolean scoresIncreasing(int[] scores) {
boolean flag = true;
for(int s=1; s<scores.length; s++){
  if(scores[s-1]>scores[s]) flag=false;
}
return flag;

}

scores100 

public boolean scores100(int[] scores) {
boolean flag = false;
for (int i=1; i<scores.length; i++)
   if ( scores[i-1] ==100 && scores[i]==100)flag = true;
return flag;

scoresAverage

public int scoresAverage(int[] scores) {
int middle = scores.length / 2;

int sum1 = 0;
int sum2 = 0;

for (int i = 0; i < middle; i++) sum1+= scores[i];
int avg1 = sum1 / middle;
for (int i = middle; i < scores.length ; i++) sum2+= scores[i];
int avg2 = sum2 / (scores.length - middle);
return Math.max(avg1, avg2);

}

dividesSelf 

public boolean dividesSelf(int n) {
  String str= Integer.toString(n);

for (int i =0; i< str.length(); i++)
{
char a= str.charAt(i);
int c = Character.getNumericValue(a);
if (c ==0)
return false;

if (n%c !=0)
return false;

}
return true;
}

userCompare 

public int userCompare(String aName, int aId, String bName, int bId) {
  if ((aName.compareTo(bName) <0) || ((aName.compareTo(bName) ==0) && aId < bId))
return -1;
else if ((aName.compareTo(bName) >0)|| ((aName.compareTo(bName) ==0) && aId < bId))
return 1;
else if ((aName.compareTo(bName) ==0)&& aId == bId)
return 0;
else
return 1;
}

 


Posted by mcleancompsci at 9:12 AM EST
Updated: Wednesday, 5 November 2008 9:16 AM EST

Newer | Latest | Older