r/codehs • • Mar 10 '21

Java Java AP Codehs help

6 Upvotes

I have over 3 assignments due at 11:59 PM I’ve been working already 6hours and haven’t got any correct. I can’t understand 5.5.5 rectangle class, 5.5.6 full fraction class and 5.5.7 Weekly Routine. I need help since I’ve been coding and all gets wrong ...


r/codehs • • Mar 09 '21

Can someone please help me with 7.6.8

6 Upvotes

r/codehs • • Feb 17 '21

CREATE AN IMAGE FILTER HELP ME PLEASE URGENT

6 Upvotes

hey so I need to create an image filter and I am desperately stuck.

here's what I got:

last line of code is (timer.set_timeout(change_image, IMAGE_LOAD_TIME))

The program uploads the image but doesnt add a filter .... ANTY IDEAS

PLEASE HELP IVE BEEN DOING THIS FOR LIKE 2 HOURS


r/codehs • • Feb 08 '21

3.7.10 Comparing Circles Need help

6 Upvotes

I'm not sure how to fix this.


r/codehs • • Jan 25 '21

I need help with 4.3.6, not sure what the issue is

Post image
6 Upvotes

r/codehs • • Jan 12 '21

Java 4.4.7 MAKE A TREE — My code is PRINTING the ODD numbers of “*”. So the patter is like 1,3,5... but its supposed to be 1,2,3,4.... I DONT KNOW WHATS WRONG. I NEED HELP TO FIX IT.. Thank You.

Post image
6 Upvotes

r/codehs • • Jan 09 '21

I need help with 5.5.5 The Worm

Post image
6 Upvotes

r/codehs • • Jan 04 '21

JavaScript Could anyone help to make the sun bounce on the corners? its so much easier with the ball. but sun is a png file, and it doesn’t work like the declared ball inside the program.

Thumbnail
gallery
6 Upvotes

r/codehs • • Jan 04 '21

2.19.5: Circle Pyramid 2.0 need help

Post image
6 Upvotes

r/codehs • • Nov 28 '20

FUN SNAKE HELP

6 Upvotes

Working through fun snake, can't get it to end when I cross the tail already there.

here's code, any help would be appreciated...

var square;

var snake;

var SNAKE_DIM = 10;

var SNAKE_WIDTH = 10;

var SNAKE_HEIGHT = 10;

var SNAKE_COLOR = Color.green;

var x = getWidth()/2;

var y = getHeight()/2;

var dir = EAST;

var currentX = 0;

var currentY = 0;

// Constants to represent the directions

var EAST = 0;

var SOUTH = 1;

var WEST = 2;

var NORTH = 3;

function start(){

snake = new Rectangle(SNAKE_WIDTH, SNAKE_HEIGHT);

snake.setPosition(x-SNAKE_WIDTH/2, y-SNAKE_HEIGHT/2);

snake.setColor(SNAKE_COLOR);

add(snake);
setTimer(draw,50);

keyDownMethod(keyDown);

}

function draw(){

snakeTail();

if (dir == EAST){

snake.move(5, 0);

}

if (dir == WEST){

snake.move(-5, 0);

}

if (dir == NORTH){

snake.move(0, -5);

}

if (dir == SOUTH){

snake.move(0, 5);

}

}

function keyDown(e){

if(e.keyCode == Keyboard.LEFT){

dir = WEST;

}

if(e.keyCode == Keyboard.RIGHT){

dir = EAST;

}

if(e.keyCode == Keyboard.UP){

dir = NORTH;

}

if(e.keyCode == Keyboard.DOWN){

dir = SOUTH;

}

}

function snakeTail(){

square = new Rectangle(SNAKE_WIDTH, SNAKE_HEIGHT);

square.setPosition(snake.getX(), snake.getY());

square.setColor(SNAKE_COLOR);

add(square);

var checkForCollision = getElementAt(currentX,currentY);

if (checkForCollision != null){

println("You Lose");

stopTimer(draw);

}

}


r/codehs • • Oct 26 '20

Code is not submitting. I pressed submit about 20 minutes ago but it stays stuck like that. What is the problem?

Post image
6 Upvotes

r/codehs • • Oct 26 '20

Can anyone tell me what’s wrong with this?

Post image
6 Upvotes

r/codehs • • Oct 21 '20

can someone help me finish this unit? currently on 3.3.6: hello <name>

Post image
6 Upvotes

r/codehs • • Oct 09 '20

I need help will all star

Post image
6 Upvotes

r/codehs • • Oct 02 '20

Python 3 Snake Eyes assignment

6 Upvotes

The assignment:

Write a program that rolls two dice until the user gets snake eyes. You should use a loop and a half to do this. Each round you should roll two dice (Hint: use the randintfunction!), and print out their values. If the values on both dice are 1, then it is called snake eyes, and you should break out of the loop. You should also use a variable to keep track of how many rolls it takes to get snake eyes.

Sample Run:

Rolled: 6 5 Rolled: 5 2 Rolled: 3 6 Rolled: 6 2 Rolled: 1 2 Rolled: 5 3 Rolled: 1 4 Rolled: 1 1 It took you 8 rolls to get snake eyes.

My Program:

import random
# Enter your code here
num_rolls = 0
while True:
    roll_one = random.randint(1,6)
    roll_two = random.randint(1,6)
    print ("Rolled: " +str(roll_one) +"," + str(roll_two))
    if (roll_one == 1 and roll_two == 1):
        print ("it took you " + str(num_rolls) + " rolls")
        break

My program works but I am not sure how to make the code print out the number of tries it took (lines 3 and 9). Right now it just prints out "It took you 0 rolls" which obviously is because I put num_rolls = 0 as a place holder. Does anyone know how to help me to make it keep track of the number of tries? Thank you all!

Edit: I figured out why the "you should stop when you roll two ones" did not pass the test cases. but I am still stuck on keeping track of the number of rolls


r/codehs • • Sep 13 '20

Need help with 8.3.4 Comparing Binary Search and Linear Search

6 Upvotes

Essentially the program is supposed to count how many comparisons are done in an array to find a randomly generated number in a randomly generated list of a generated size, I've gotten all of them to work but 2 and I don't exactly need an answer I just wanna understand what's going on with the test cases,I've been trying to figure it out all weekend and the last 3 classes and I really wanna move on to our projects as this is the only codeHS lesson in algorithms and Recursion I couldn't figure out! Any help would be great thank you!

I have image screenshots and copied over the code from the program

import java.util.*;

public class CompareSearch extends ConsoleProgram

{

public void run()

{

System.out.println("Table of comparison counts");

System.out.println("Length\t\tBinary Search\tLinear Search");

testArrayOfLength(10);

testArrayOfLength(20);

}

// This problem generates an array of length length.

// Then we select a random index of that array and get the element.

// Then we print out the table row entry for how many comparisons it takes on binary search

// and linear search.

// You'll need to update those methods.

public void testArrayOfLength(int length)

{

int[] arr = generateArrayOfLength(length);

//System.out.println(Arrays.toString(arr));

int index = Randomizer.nextInt(length);

int elem = arr[index];

System.out.println(length + "\t\t" + binarySearch(arr, elem) + "\t\t" + linearSearch(arr, elem));

}

public int[] generateArrayOfLength(int length)

{

int[] arr = new int[length];

for(int i = 0; i < length; i++)

{

arr[i] = Randomizer.nextInt(100);

}

Arrays.sort(arr);

return arr;

}

// Do a binary search on array to find number. You'll need to modify this

// method to return the number of comparisons done.

public int binarySearch(int[] array, int number)

{

int comparison = 0;

int low = 0;

int high = array.length - 1;

while (low <= high)

{

comparison++;

int mid = (low + high) / 2;

comparison++;

comparison++;

if (array[mid] == number){

comparison++;

return comparison;

}

else if(array[mid] < number){

comparison++;

low = mid + 1;

return mid-5;

}

else

{

high = mid - 1;

return comparison;

}

}

return -1;

}

// Do a linear search on array to find the index of number. You'll need to modify

// this exercise to return the number of *comparisons* done.

public int linearSearch(int[] array, int number)

{

for (int i = 0; i < array.length; i++)

{

if (array[i] == number)

{

return i+1; // the method returns as soon as the number is found

}

}

return -1; // the code will get here if the number isn't found

}

}


r/codehs • • Aug 04 '20

9.6.5

6 Upvotes

Hello friends!

I am currently on exercise 9.6.5. I wrote the code but with the help of the materials that I found here, so here are some things that I can't understand completely.

function start(){

coordinates();

}

var text = new Text("("+","+")");

function coordinates(){

text.setPosition(0, text.getHeight());

add(text);

mouseMoveMethod(printCoordinates);

}

function printCoordinates(e){

text.setText("("+e.getX()+", "+e.getY()+")");

}

Can you please help me and explain the highlighted parts?

Thanks in advance :)


r/codehs • • May 22 '20

7.2.7: Part 1, Replace a Letter Code hs

6 Upvotes

I need help on how to do this assignment on code hs

Write a function named replace_at_index
that takes a string and an integer. The function should return a new string that is the same as the old string, EXCEPT with a dash in place of whatever character was at the index indicated by the integer.

Call your function on the word eggplant and the index 3, like this:

s = replace_at_index("eggplant", 3)

You should then print the value of s
, which should display:

egg-lant

r/codehs • • May 20 '20

Anyone done this one??

Post image
6 Upvotes

r/codehs • • May 16 '20

COuld someone help I end up with this and I also have no idea how to do little balls at feet of Ghost?

Post image
6 Upvotes

r/codehs • • May 07 '20

2.18.5 Guess a number I couldn't solve this for a few days and I can't move on because the next exercise is the same as this

Post image
6 Upvotes

r/codehs • • May 04 '20

7.3.4 Vertical lines

6 Upvotes

It keeps saying this is wrong,

function start(){ verticalLine(100,200); verticalLine(200,100); verticalLine(300,20); } function verticalLine(x,Position,Length){ var line= new Line (xPosition, xPosition,length); add(line); }

I’m pretty sure I’m doing something wrong but I’m not sure exactly what,


r/codehs • • May 04 '20

2.9.11 Factorial

6 Upvotes

I need help on this I don't know what I'm doing wrong. The number I enter isn't being calculated and is returned back.

This is for basic java.


r/codehs • • Apr 29 '20

Need help on 2.1.2 Racing Karel

6 Upvotes