Advertisement
Barrettwinchell

Chapter 2 Projects

Dec 19th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.35 KB | None | 0 0
  1. Project 3
  2.  
  3. Write main program
  4.  to call methods
  5.  
  6. Make methods with nested for loops
  7. line
  8. top
  9. bot
  10.  
  11. /*Barrett Winchell
  12. Project 3 chapter 2using for loops
  13. December 5, 2014*/
  14.  
  15. public class project3
  16.    { public static void main(String[] args)
  17.      {
  18.       line();
  19.       top();
  20.       bot();
  21.       line();
  22.       bot();
  23.       top();
  24.       line();
  25.       }
  26.    public static void line()
  27.       {System.out.println("+---------+");
  28.       }
  29.    public static void top()
  30.       {
  31.       for (int x = 1; x <= 4; x++)
  32.          {
  33.          System.out.print("|");
  34.          for (int a = x-1; a <= 3; a++)
  35.             {
  36.             System.out.print(" ");
  37.             }
  38.          for (int b = -1*(x-5); b <= 3; b++)
  39.             {
  40.             System.out.print("/");
  41.             }
  42.         {System.out.print("*");
  43.          }
  44.          for (int c = -1*x+5; c <= 3; c++)
  45.             {
  46.             System.out.print("\\");
  47.             }
  48.          for (int d = x; d <=4; d++)
  49.             {
  50.             System.out.print(" ");
  51.             }
  52.          {
  53.          System.out.print("|");
  54.          }
  55.          {
  56.          System.out.println();
  57.          }
  58.          }
  59.        }
  60.      
  61.    public static void bot()
  62.      {for (int x = 1; x <= 4; x++)
  63.         {
  64.         System.out.print("|");
  65.         for (int a = x-1; a >= 0; a--)
  66.            {
  67.            System.out.print(" ");
  68.            }
  69.         for (int b = -1*x+3; b >= 0; b--)
  70.            {
  71.            System.out.print("\\");
  72.            }
  73.         {
  74.         System.out.print("*");
  75.         }
  76.         for (int c = -1*x+3; c >= 0; c--)
  77.            {
  78.            System.out.print("/");
  79.            }
  80.         for (int d = x; d >= 1; d--)
  81.          {
  82.          System.out.print(" ");
  83.          }
  84.        {
  85.         System.out.print("|");
  86.         }  
  87.         {
  88.         System.out.println();
  89.         }
  90.         }
  91.   }    
  92.   }
  93.    
  94.  
  95.      
  96.    
  97.  
  98.  
  99.  
  100. Project 4
  101.  
  102. Write main program
  103.  to call methods
  104.  
  105. Make methods with nested for loops
  106. line
  107. top
  108. mid
  109. bot
  110.  
  111. /*Barrett Winchell
  112. Project 4
  113. Practice using for loops
  114. December 5, 2014*/
  115.  
  116. public class project4
  117.    {
  118.       public static void main(String[] args)
  119.       {
  120.          System.out.println("|\"\"\"\"\"\"\"\"\"\"|");
  121.          top();
  122.          System.out.println("     ||");
  123.          bot();
  124.          System.out.println("|\"\"\"\"\"\"\"\"\"\"|");
  125.          }
  126.       public static void top()
  127.          {
  128.          for (int line = 1; line <= 4; line++)
  129.             {
  130.             for (int a = 1; a <= line; a++)
  131.                {System.out.print(" ");
  132.                }
  133.             {System.out.print("\\");
  134.             }
  135.             for (int b = 1; b <= -2*line+10; b++)
  136.                {System.out.print(":");
  137.                }
  138.             {
  139.             System.out.println("/");
  140.             }
  141.          }
  142.         }
  143.        public static void bot()
  144.          {
  145.          for (int line = 1; line <= 4; line++)
  146.             {
  147.            for (int a = 1; a <= 5-line; a++)
  148.                {
  149.                System.out.print(" ");
  150.                }
  151.             {System.out.print("/");
  152.             }
  153.             for (int b = 1; b <= line*2; b++)
  154.                {
  155.                System.out.print(":");
  156.                }
  157.             {
  158.             System.out.println("\\");
  159.             }
  160.           }
  161.         }
  162.       }
  163.  
  164.  
  165. Space Needle
  166.  
  167. Set class constant
  168.  
  169. write main program to call methods
  170.  
  171. Make methods with nested for loops so that size is controlled by class constant
  172.  
  173. spire
  174. bot
  175. top
  176. line
  177. thing
  178.  
  179. /*Barrett Winchell
  180. Space Needle
  181. Practice using for loops
  182. December 5, 2014*/
  183.  
  184. public class Spaceneedle2
  185.    {
  186.    public static final int x = 4;
  187.      public static void main(String[] args)
  188.       {
  189.       spire();
  190.       top();
  191.       line();
  192.       bot();
  193.       spire();
  194.       thing();
  195.       top();
  196.       line();
  197.       }
  198.    public static void spire()
  199.     {
  200.     for (int a = 1; a <= x; a++)
  201.        {
  202.        for (int i = 1; i <= 3*x; i++)
  203.          {System.out.print(" ");
  204.          }
  205.        for (int j = 1; j <= x/2; j++)  
  206.          {
  207.          System.out.print("|");
  208.             }
  209.           System.out.println();
  210.       }
  211.      }
  212.      public static void top()
  213.       {
  214.          for (int line = 1; line<=x; line++)
  215.          {  
  216.             for (int b =1; b<=3*x-(line*3); b++)
  217.                {
  218.                System.out.print(" ");
  219.               }
  220.             {System.out.print("__/");
  221.             }
  222.             for (int c =1; c<= line*3-3; c++)
  223.                {
  224.                System.out.print(":");
  225.                }
  226.             for (int j = 1; j <= x/2; j++)  
  227.                {
  228.                System.out.print("|");
  229.                }
  230.             for (int d =1; d<= line*3-3; d++)
  231.                {
  232.                System.out.print(":");
  233.                }
  234.             {System.out.println("\\__");
  235.             }
  236.           }
  237.        }
  238.      public static void bot()
  239.       {
  240.          for (int line = 1; line <= x; line++)
  241.          {
  242.             for (int a = 1; a <= line*2-2; a++)
  243.                {
  244.                System.out.print(" ");
  245.                }
  246.             {
  247.             System.out.print("\\_");
  248.             }
  249.             for (int b = 1; b <= 3.25*x-(line*2); b++)
  250.                {
  251.                System.out.print("/\\");
  252.                }
  253.             {
  254.             System.out.println("_/");
  255.             }
  256.          }
  257.       }
  258.      public static void line()
  259.       {
  260.          {
  261.          System.out.print("|");
  262.          }
  263.          for (int a = 1; a <= 6*x; a++)
  264.             {
  265.             System.out.print("\"");
  266.             }
  267.          System.out.println("|");
  268.          }
  269.      public static void thing()
  270.       {
  271.         for (int line = 1; line <= x*4; line++)
  272.             {for (double a = 1; a <= 2.25*x; a++)
  273.                {
  274.                System.out.print(" ");
  275.                }
  276.             {
  277.             System.out.print("|");
  278.             }
  279.              for (double d = 1; d <= x/2; d++)  
  280.                {
  281.                System.out.print("%");
  282.                }
  283.              for (int d = 1; d <= x/2; d++)  
  284.                {
  285.                System.out.print("|");
  286.                }
  287.              for (int d = 1; d <= x/2; d++)  
  288.               {
  289.                System.out.print("%");
  290.                }
  291.             {
  292.             System.out.println("|");
  293.             }
  294.          }
  295.        }
  296.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement