4 Replies - 158 Views - Last Post: 05 April 2013 - 06:43 AM Rate Topic: -----

#1 Droidx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-April 13

need help with figuring out how to plot a point at a specific location

Posted 05 April 2013 - 01:28 AM

Hey guys,

I got a problem i need help trying to work something out.
I am working on this assignment but i have no idea where to start.
It is the following problem.



Make a console application that can draw lines consisting of characters.

The way to do this is to fill an 2-dimensional char array (say A) with blanks.

The problem is i have no idea how to start programming the following
----> Plotting a point at location x, y happens by the assignment A [yMax-y-1,x] = "*". <----

Is there anyone one who could point me into the right direction?

Is This A Good Question/Topic? 0
  • +

Replies To: need help with figuring out how to plot a point at a specific location

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: need help with figuring out how to plot a point at a specific location

Posted 05 April 2013 - 03:35 AM

Here is your array filled with space
   char[][] a = new char[20][40];   // 20 row 40 columns
   for(int row = 0; row < a.length; ++row) {
       for(int col = 0; col < a[row].length; ++col) {
           a[row][col] = ' ';
        }
   }



you can always do a[10][20] '*';
ad use aother 2 loops to print your array

Happy coding
Was This Post Helpful? 0
  • +
  • -

#3 Droidx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-April 13

Re: need help with figuring out how to plot a point at a specific location

Posted 05 April 2013 - 04:14 AM

View Postpbl, on 05 April 2013 - 03:35 AM, said:

Here is your array filled with space
   char[][] a = new char[20][40];   // 20 row 40 columns
   for(int row = 0; row < a.length; ++row) {
       for(int col = 0; col < a[row].length; ++col) {
           a[row][col] = ' ';
        }
   }



you can always do a[10][20] '*';
ad use aother 2 loops to print your array

Happy coding



Hey thanks for the response.
Sorry but maybe i wasn't clear enough. Luckily i already found out how to create the array via Google.
My real question was actually concerning the plotting a point at a location:

Plotting a point at location x, y happens by the assignment A [yMax-y-1,x] = "*".
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: need help with figuring out how to plot a point at a specific location

Posted 05 April 2013 - 06:36 AM

a[someX][someY] = 'Z';

will print a Z at someY,someY when you'll print the array... else arounf will be spaces
Was This Post Helpful? 1
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: need help with figuring out how to plot a point at a specific location

Posted 05 April 2013 - 06:43 AM

		char[][] a = new char[5][7];
		for(int row = 0; row < a.length; ++row) {
			for(int col = 0; col < a[row].length; ++col) {
				a[row][col] = ' ';
			}
		}
		a[1][6] = '/';
		a[2][5] = '/';
		a[3][4] = '/';
		a[4][3] = 'V';
		a[3][2] = '\\';   // <--- this one is tricvkier :)/>
		for(int row = 0; row < a.length; ++row) {
			for(int col = 0; col < a[row].length; ++col) {
				System.out.print(a[row][col]);
			}
			System.out.println();
		}
				


yields
       
      /
     / 
  \ /  
   V   



Was This Post Helpful? 1
  • +
  • -

Page 1 of 1