1 Attachment(s)
line plot Print statements
Hello there :)
I have been giving a assignment at school were i have to be able to say what i want to. like 2x+3 or something like that. i'm in the beginning of programming and just started a month ago.
i have only mangede to make straigth slopes and straigth lines where i say they start from and end.
my teacher want me to make a program that gonna look something likes this:
Attachment 1429
with is an sinus curve. what should i do to make something like that?
Here is what i have been making. is there someone who can point me in the right direction? :)
Code :
import java.util.*;
public class Opgave4_ChristianSørensen{
public static void main (String [] args) {
System.out.println(" y-aksen");
System.out.println("- - - - - - - - - + + + + + + + + +");
System.out.println("9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9");
slope(0, 5);
slope(6, -7);
straight(5, -5);
System.out.println();
slope(5, -2);
}
public static void slope(int Start, int end) {
if (Start <= end) {
for (int i = Start; Start<= end; Start++){
if (Start == -9)
System.out.println("x |");
else if (Start == -8)
System.out.println(" x |");
else if (Start == -7)
System.out.println(" x |");
else if (Start == -6)
System.out.println(" x |");
else if (Start == -5)
System.out.println(" x |");
else if (Start == -4)
System.out.println(" x |");
else if (Start == -3)
System.out.println(" x |");
else if (Start == -2)
System.out.println(" x |");
else if (Start == -1)
System.out.println(" x |");
else if (Start == 0)
System.out.println(" x");
else if (Start == 1)
System.out.println(" | x");
else if (Start == 2)
System.out.println(" | x");
else if (Start == 3)
System.out.println(" | x");
else if (Start == 4)
System.out.println(" | x");
else if (Start == 5)
System.out.println(" | x");
else if (Start == 6)
System.out.println(" | x");
else if (Start == 7)
System.out.println(" | x");
else if (Start == 8)
System.out.println(" | x");
else if (Start == 9)
System.out.println(" | x");
else if (Start >=-9)
System.out.println("\n \n \n number has to be bewteen -9 og 9");
else if (Start <=9)
System.out.println("\n \n \n number has to be bewteen -9 og 9");
}
}
else {
for (int i = Start; Start>= end; Start--){
if (Start == -9)
System.out.println("x |");
else if (Start == -8)
System.out.println(" x |");
else if (Start == -7)
System.out.println(" x |");
else if (Start == -6)
System.out.println(" x |");
else if (Start == -5)
System.out.println(" x |");
else if (Start == -4)
System.out.println(" x |");
else if (Start == -3)
System.out.println(" x |");
else if (Start == -2)
System.out.println(" x |");
else if (Start == -1)
System.out.println(" x |");
else if (Start == 0)
System.out.println(" x");
else if (Start == 1)
System.out.println(" | x");
else if (Start == 2)
System.out.println(" | x");
else if (Start == 3)
System.out.println(" | x");
else if (Start == 4)
System.out.println(" | x");
else if (Start == 5)
System.out.println(" | x");
else if (Start == 6)
System.out.println(" | x");
else if (Start == 7)
System.out.println(" | x");
else if (Start == 8)
System.out.println(" | x");
else if (Start == 9)
System.out.println(" | x");
else if (Start >=-9)
System.out.println("\n \n \n number has to be bewteen -9 og 9");
else if (Start <=9)
System.out.println("\n \n \n number has to be bewteen -9 og 9");
}
}
}
public static void straight (int Start, int end){
if (Start < end){
for (int i = -9; i<= Start; i++){
System.out.print(" ");
if (Start >=-9)
System.out.print("\n \n \n number has to be bewteen -9 og 9");
else if (Start <=9)
System.out.print("\n \n \n number has to be bewteen -9 og 9");
}
for (int i = Start; Start<=end; Start++){
if (Start <= end)
System.out.print(" x");
}
}
else {
if (Start > end){
for (int i = -9; i<= end; i++){
System.out.print(" ");
if (Start <=-9)
System.out.print("\n \n \n number has to be bewteen -9 og 9");
else if (Start >=9)
System.out.print("\n \n \n number has to be bewteen -9 og 9");
}
for (int i = end; end<=Start; end++){
if (end <= Start)
System.out.print(" x");
}
}
}
}
}
Hope someone can help me :)
and thanks in advance :)
Re: line plot Print statements
Start with a piece of paper and draw the shapes. Find a trig function that will generate the x(columns) values as the y (row) values change. You will have to do some scaling (multiply by a factor) to get it to fit.
Re: line plot Print statements
Quote:
Originally Posted by
Norm
Start with a piece of paper and draw the shapes. Find a trig function that will generate the x(columns) values as the y (row) values change. You will have to do some scaling (multiply by a factor) to get it to fit.
is it possible you could give me a hint with some code? because i'm still pretty lost :S
Re: line plot Print statements
Have you found the trig function that will draw the shape you want?
I don't have any code that does that.
Scaling means taking values in the range of 0 to 1 and converting them to some other range say 200 to 600 by multiplying then by (600-200) and adding 200.