Advertisement
Guest User

Untitled

a guest
Feb 15th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 KB | None | 0 0
  1. // ROWS 9
  2. // COLUMNS 9
  3.  
  4. import java.util.*;
  5. import java.text.*;
  6.  
  7. public class Proj3 {
  8.     public static void main(String[] args) {
  9.         Scanner input = new Scanner(System.in);
  10.         double outter_slope = 2;
  11.         double outter_intercept = 0;
  12.        
  13.        
  14.        
  15.         System.out.print("Enter x1:  ");
  16.         int x1 = input.nextInt();
  17.        
  18.         System.out.print("Enter y1:  ");
  19.         int y1 = input.nextInt();
  20.        
  21.         System.out.print("Enter x2:  ");
  22.         int x2 = input.nextInt();
  23.        
  24.         System.out.print("Enter y2:  ");
  25.         int y2 = input.nextInt();
  26.        
  27.         double slope = (double)(y2-y1) / (x2-x1);
  28.        
  29.         double intercept = y1-slope*x1;
  30.        
  31.        
  32.        
  33.    
  34.        
  35.         System.out.printf("y = " + "%.2f" + "x" + "  + " + "%.2f\n", slope,intercept    );
  36.         System.out.println();
  37.         int row_number;
  38.         int column_number;
  39.  
  40.         for(row_number=9;row_number>=0;row_number--) {
  41.             System.out.print(row_number+ " ");
  42.             for(column_number=0;column_number<=9;column_number++) {
  43.                
  44.                 if (row_number == 0) {
  45.                 // prints out the -
  46.                 //System.out.print("");
  47.                
  48.                
  49.                 for(column_number=0;column_number<=9;column_number++) {
  50.                     System.out.print("-");
  51.                 }  
  52.             }
  53.                
  54.                
  55.                 if(column_number == 0) {
  56.                     if ( (((column_number == x1) && (row_number == y1)) || (((column_number == x2) && (row_number == y2)))) ) {
  57.                     System.out.print("*");}
  58.                    
  59.                     else{   // failed code ( (((column_number != x1) && (row_number != y1)) || (((column_number != x2) && (row_number != y2)))) ) {
  60.                     System.out.print(":");}
  61.                    
  62.                    
  63.                    
  64.                    
  65.                
  66.             }
  67.            
  68.                
  69.                if(column_number != 0) {
  70.                
  71.                
  72.                 if ( (column_number == x1) && (row_number == y1) || ((column_number == x2) && (row_number == y2))) {
  73.                     System.out.print("*");
  74.                    
  75.                 }
  76.                
  77.                 else {
  78.                     System.out.print(" ");
  79.                    
  80.                 }
  81.  
  82.                
  83.             }
  84.                
  85.                
  86.                    
  87.                
  88.                
  89.                  
  90.  
  91.  
  92.                
  93.  
  94.  
  95.             }
  96.            
  97.            
  98.             // code for last line
  99.             if (row_number == 0) {
  100.                 // prints out the -
  101.                 System.out.print("  ");
  102.                 for(column_number=0;column_number<=9;column_number++) {
  103.                     System.out.print("-");
  104.                 }    
  105.                
  106.                
  107.                 System.out.println();
  108.                 System.out.print("  ");
  109.                
  110.                 for(column_number=0;column_number<=9;column_number++) {
  111.                     System.out.print(column_number);
  112.                 }    
  113.                
  114.                
  115.             }
  116.             System.out.println();
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement