Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Project 3
- Write main program
- to call methods
- Make methods with nested for loops
- line
- top
- bot
- /*Barrett Winchell
- Project 3 chapter 2using for loops
- December 5, 2014*/
- public class project3
- { public static void main(String[] args)
- {
- line();
- top();
- bot();
- line();
- bot();
- top();
- line();
- }
- public static void line()
- {System.out.println("+---------+");
- }
- public static void top()
- {
- for (int x = 1; x <= 4; x++)
- {
- System.out.print("|");
- for (int a = x-1; a <= 3; a++)
- {
- System.out.print(" ");
- }
- for (int b = -1*(x-5); b <= 3; b++)
- {
- System.out.print("/");
- }
- {System.out.print("*");
- }
- for (int c = -1*x+5; c <= 3; c++)
- {
- System.out.print("\\");
- }
- for (int d = x; d <=4; d++)
- {
- System.out.print(" ");
- }
- {
- System.out.print("|");
- }
- {
- System.out.println();
- }
- }
- }
- public static void bot()
- {for (int x = 1; x <= 4; x++)
- {
- System.out.print("|");
- for (int a = x-1; a >= 0; a--)
- {
- System.out.print(" ");
- }
- for (int b = -1*x+3; b >= 0; b--)
- {
- System.out.print("\\");
- }
- {
- System.out.print("*");
- }
- for (int c = -1*x+3; c >= 0; c--)
- {
- System.out.print("/");
- }
- for (int d = x; d >= 1; d--)
- {
- System.out.print(" ");
- }
- {
- System.out.print("|");
- }
- {
- System.out.println();
- }
- }
- }
- }
- Project 4
- Write main program
- to call methods
- Make methods with nested for loops
- line
- top
- mid
- bot
- /*Barrett Winchell
- Project 4
- Practice using for loops
- December 5, 2014*/
- public class project4
- {
- public static void main(String[] args)
- {
- System.out.println("|\"\"\"\"\"\"\"\"\"\"|");
- top();
- System.out.println(" ||");
- bot();
- System.out.println("|\"\"\"\"\"\"\"\"\"\"|");
- }
- public static void top()
- {
- for (int line = 1; line <= 4; line++)
- {
- for (int a = 1; a <= line; a++)
- {System.out.print(" ");
- }
- {System.out.print("\\");
- }
- for (int b = 1; b <= -2*line+10; b++)
- {System.out.print(":");
- }
- {
- System.out.println("/");
- }
- }
- }
- public static void bot()
- {
- for (int line = 1; line <= 4; line++)
- {
- for (int a = 1; a <= 5-line; a++)
- {
- System.out.print(" ");
- }
- {System.out.print("/");
- }
- for (int b = 1; b <= line*2; b++)
- {
- System.out.print(":");
- }
- {
- System.out.println("\\");
- }
- }
- }
- }
- Space Needle
- Set class constant
- write main program to call methods
- Make methods with nested for loops so that size is controlled by class constant
- spire
- bot
- top
- line
- thing
- /*Barrett Winchell
- Space Needle
- Practice using for loops
- December 5, 2014*/
- public class Spaceneedle2
- {
- public static final int x = 4;
- public static void main(String[] args)
- {
- spire();
- top();
- line();
- bot();
- spire();
- thing();
- top();
- line();
- }
- public static void spire()
- {
- for (int a = 1; a <= x; a++)
- {
- for (int i = 1; i <= 3*x; i++)
- {System.out.print(" ");
- }
- for (int j = 1; j <= x/2; j++)
- {
- System.out.print("|");
- }
- System.out.println();
- }
- }
- public static void top()
- {
- for (int line = 1; line<=x; line++)
- {
- for (int b =1; b<=3*x-(line*3); b++)
- {
- System.out.print(" ");
- }
- {System.out.print("__/");
- }
- for (int c =1; c<= line*3-3; c++)
- {
- System.out.print(":");
- }
- for (int j = 1; j <= x/2; j++)
- {
- System.out.print("|");
- }
- for (int d =1; d<= line*3-3; d++)
- {
- System.out.print(":");
- }
- {System.out.println("\\__");
- }
- }
- }
- public static void bot()
- {
- for (int line = 1; line <= x; line++)
- {
- for (int a = 1; a <= line*2-2; a++)
- {
- System.out.print(" ");
- }
- {
- System.out.print("\\_");
- }
- for (int b = 1; b <= 3.25*x-(line*2); b++)
- {
- System.out.print("/\\");
- }
- {
- System.out.println("_/");
- }
- }
- }
- public static void line()
- {
- {
- System.out.print("|");
- }
- for (int a = 1; a <= 6*x; a++)
- {
- System.out.print("\"");
- }
- System.out.println("|");
- }
- public static void thing()
- {
- for (int line = 1; line <= x*4; line++)
- {for (double a = 1; a <= 2.25*x; a++)
- {
- System.out.print(" ");
- }
- {
- System.out.print("|");
- }
- for (double d = 1; d <= x/2; d++)
- {
- System.out.print("%");
- }
- for (int d = 1; d <= x/2; d++)
- {
- System.out.print("|");
- }
- for (int d = 1; d <= x/2; d++)
- {
- System.out.print("%");
- }
- {
- System.out.println("|");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement