Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: line plot Print statements

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    30
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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:
    java.jpg

    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?
    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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    30
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: line plot Print statements

    Quote Originally Posted by Norm View Post
    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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. how to plot a line graph by reading the values from database?
    By priti in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2012, 01:39 AM
  2. How to plot line graph using jfreechart reading from text file
    By priti in forum Java Theory & Questions
    Replies: 9
    Last Post: March 31st, 2012, 01:39 PM
  3. how to plot the line graph using jfreechart reading from text file
    By priti in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 31st, 2012, 06:53 AM
  4. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  5. How to read from all files in a directory & plot the contents?
    By 123 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 11th, 2010, 12:43 PM