William Nyqvister

Greenhorn

Posts: 7

1

posted 2 years ago

Hi guys! I am at the edge of finishing my math program. It's a program where you can choose what to do. For example calculate sphere volume, fractions, linear equations etc..

Well i have a major problem: My linear equation method isn't working at all. Well.. i don't know what to. I am kind of lost at this point. Have tried a bunch of things, but i think i screwed it up even more than before.

There is surely some more issues with the code, but I'm very new to this.. It isn't as obvious as for you guys. I would be very pleased and grateful if you could help me. If you see something else, tell me!

Here is the code!

Well i have a major problem: My linear equation method isn't working at all. Well.. i don't know what to. I am kind of lost at this point. Have tried a bunch of things, but i think i screwed it up even more than before.

There is surely some more issues with the code, but I'm very new to this.. It isn't as obvious as for you guys. I would be very pleased and grateful if you could help me. If you see something else, tell me!

Here is the code!

William Nyqvister

Greenhorn

Posts: 7

1

posted 2 years ago

I don't call it, cause i don't know how, and what to do..

The data that is returned from calcLine should be sent into printLine, that handles the output. But I don't know how I do it. The previous methods returns a value that i can output easily. But this confuses me..

Stevens Miller wrote:At what line do you call your linear equation method?

I don't call it, cause i don't know how, and what to do..

The data that is returned from calcLine should be sent into printLine, that handles the output. But I don't know how I do it. The previous methods returns a value that i can output easily. But this confuses me..

posted 2 years ago

Me too .

Looking at your calcLine method, it's not immediately clear what it's supposed to do. We can probably be of some help if you describe, in words, what you are trying to accomplish.

William Nyqvister wrote:But this confuses me..

Me too .

Looking at your calcLine method, it's not immediately clear what it's supposed to do. We can probably be of some help if you describe, in words, what you are trying to accomplish.

"Il y a peu de choses qui me soient impossibles..."

William Nyqvister

Greenhorn

Posts: 7

1

posted 2 years ago

haha okey ill give the full details!

1: I'm supposed to create a method that takes integer values x, k and m. The method calculates and returns the value of y(x) = kx+m. The method should be called calcPoint, cause it calculates a point (x, y) of the line. If x=5, k=1 and m=2 the result of 1*5+2 is returned 7.

2: Now we create a method called calcLine, to calculate a line, all y of range from 1 to n, where n is the largest x value that is calculated. So if n is 5, x starts at 1 and ends at 5. The method also takes integer values of k and m, and uses calcPoint to calculate the value of y. The results are returned back to the main method in a integer array, where the position represents x. If n=5, k=1 and m=2 the following should be returned: {0, 3, 4, 5, 6, 7}. Note that position 1 (index 0) is not used when x starts at 1.

3: The last method printLine handles the printing form y(x) = kx + m. It receives the integer array with the y values and outputs it into the console. one point per line. If n = 5, k = 1 and m = 2 the output should be.

y(1) = 3

y(2) = 4

y(3) = 5

y(4) = 6

y(5) = 7

These three methods are tested by the user by inputting the values for n, k and m. The data that is returned from calcLine that sends it to printLine, which manages the output.

Well you should receive an Oscar if you understand xD

We can probably be of some help if you describe, in words

haha okey ill give the full details!

1: I'm supposed to create a method that takes integer values x, k and m. The method calculates and returns the value of y(x) = kx+m. The method should be called calcPoint, cause it calculates a point (x, y) of the line. If x=5, k=1 and m=2 the result of 1*5+2 is returned 7.

2: Now we create a method called calcLine, to calculate a line, all y of range from 1 to n, where n is the largest x value that is calculated. So if n is 5, x starts at 1 and ends at 5. The method also takes integer values of k and m, and uses calcPoint to calculate the value of y. The results are returned back to the main method in a integer array, where the position represents x. If n=5, k=1 and m=2 the following should be returned: {0, 3, 4, 5, 6, 7}. Note that position 1 (index 0) is not used when x starts at 1.

3: The last method printLine handles the printing form y(x) = kx + m. It receives the integer array with the y values and outputs it into the console. one point per line. If n = 5, k = 1 and m = 2 the output should be.

y(1) = 3

y(2) = 4

y(3) = 5

y(4) = 6

y(5) = 7

These three methods are tested by the user by inputting the values for n, k and m. The data that is returned from calcLine that sends it to printLine, which manages the output.

Well you should receive an Oscar if you understand xD

posted 2 years ago

Welcome to the Ranch, William, nice to see you around.

Probably first thing i'd go for, is - rename methods, so the method name would reveal actual its intention.

For example

Lines 66, 67, 68. What these n, k and m mean? What these numbers are?

Probably you chose not quite right strategy of doing all this. You mentioned that one of your methods not working, so why you decided to go further without sorting it first.

[edit] Apart from calcLine method, the rest working as expected?

Probably first thing i'd go for, is - rename methods, so the method name would reveal actual its intention.

For example

*sumThis*, maybe call it better as*triangularNumber*. And the base case probably should be 1, not 0. With ternary operators you could get 1 line method.Lines 66, 67, 68. What these n, k and m mean? What these numbers are?

Probably you chose not quite right strategy of doing all this. You mentioned that one of your methods not working, so why you decided to go further without sorting it first.

[edit] Apart from calcLine method, the rest working as expected?

William Nyqvister

Greenhorn

Posts: 7

1

posted 2 years ago

What do you mean by "lines 66, 67, 68"? You tell me! That is what the assignment says.. I guess the x is called n in the method to not confuse the user of the code with something else. I think the code works, but how to i get an output? :/

Everything else is working! The "linear equation" method is the only one not working. Well that is the instructions for the task. I tried to make one of my own, cause i didn't really understand. But the output should be:

y(1) = 3

y(2) = 4

y(3) = 5

y(4) = 6

y(5) = 7

..after the user inputs kx+m to get the y. Well well, this one was to hard for me i guess

Lines 66, 67, 68. What these n, k and m mean? What these numbers are?

What do you mean by "lines 66, 67, 68"? You tell me! That is what the assignment says.. I guess the x is called n in the method to not confuse the user of the code with something else. I think the code works, but how to i get an output? :/

Apart from calcLine method, the rest working as expected?

Everything else is working! The "linear equation" method is the only one not working. Well that is the instructions for the task. I tried to make one of my own, cause i didn't really understand. But the output should be:

y(1) = 3

y(2) = 4

y(3) = 5

y(4) = 6

y(5) = 7

..after the user inputs kx+m to get the y. Well well, this one was to hard for me i guess

posted 2 years ago

No, you got wrong at least one more method after the calcLine. But let's don't take everything in one go - that is too much.

Requirements of your method is above. And below is the code you have got.

Please read your requirements once again, and review the code you came up. Please state what comes to your mind, what have you missed and what have you interpreted in your way, even tho it was stated differently in the requirements.

I think you'll need to start over with this method and probably the next one.

William Nyqvister wrote:2: Now we create a method called calcLine, to calculate a line, all y of range from 1 to n, where n is the largest x value that is calculated. So if n is 5, x starts at 1 and ends at 5. The method also takes integer values of k and m, and uses calcPoint to calculate the value of y. The results are returned back to the main method in a integer array, where the position represents x. If n=5, k=1 and m=2 the following should be returned: {0, 3, 4, 5, 6, 7}. Note that position 1 (index 0) is not used when x starts at 1.

Requirements of your method is above. And below is the code you have got.

Please read your requirements once again, and review the code you came up. Please state what comes to your mind, what have you missed and what have you interpreted in your way, even tho it was stated differently in the requirements.

I think you'll need to start over with this method and probably the next one.

posted 2 years ago

Few more hints to give a start:

Why you decided

Why you decided

Why your loop starts from the end of x, if requirements says

Why you are not using

I would name your current parameter

It says: n is the largest x value that is needed to be calculated. i.e. if n = 4 then your x at some point will have value of 1, then of 2, then of 3 and finally value of 4.

Why you decided

__to use__array of strings?Why you decided

__not to use__array of integers?Why your loop starts from the end of x, if requirements says

__"if n is 5, x starts at 1 and ends at 5"__?Why you are not using

__calcPoint__method inside calcLine method, if you have been asked to do so?Probably you're mistaken here.William Nyqvister wrote:I guess the x is called n in the method to not confuse the user of the code with something else.

I would name your current parameter

**x**as**n**. x and n are not the same.It says: n is the largest x value that is needed to be calculated. i.e. if n = 4 then your x at some point will have value of 1, then of 2, then of 3 and finally value of 4.