daniel_lawson9999

Daniel Lawson Java 1, Projects 1,2,3,6

Apr 10th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.55 KB | None | 0 0
  1. /**
  2.  * Created by Daniel on 4/6/2016.
  3.  */
  4. //Project 1
  5. public class project1ChristmasTrees {
  6.     public static void main (String[] args){
  7.         tree(3,5);
  8.     }
  9.  
  10.  
  11.     public static void tree(int segments,int height){
  12.         for(int seg =1; seg <= segments; seg++){
  13.             for(int lines = 1; lines<= height;lines++){
  14.                 for(int i = 1; i<= lines*-1 + (height)+segments-seg; i++ ){ //lines - 1
  15.                     System.out.print(" ");
  16.                 }
  17.                 for(int i = 1; i <= lines*2 +seg*2 -3;i++){
  18.                     System.out.print("*");
  19.                 }
  20.                 System.out.println();
  21.             }
  22.         }
  23.         //height  - segments // (height*2 -1)*(2*segments)
  24.         for(int i = 1;i <=((height*2 -1)+(2*segments-2))/2;i++){
  25.             System.out.print(" ");
  26.         }
  27.         System.out.println("*");
  28.         for(int i = 1;i <=((height*2 -1)+(2*segments-2))/2;i++){
  29.             System.out.print(" ");
  30.         }
  31.         System.out.println("*");
  32.         for(int i = 1;i <=((height*2 -1)+(2*segments-2))/2-3;i++){
  33.             System.out.print(" ");
  34.         }
  35.         System.out.println("*******");
  36.  
  37.     }
  38. }
  39. //-------------------------------------------------------------------------------------------------------------------------------------
  40. //project 2
  41. /**
  42.  * Created by Daniel on 4/7/2016.
  43.  */
  44. import java.util.*;
  45. public class project2interest {
  46.     public static void main(String[] args){
  47.         Scanner console = new Scanner(System.in);
  48.         System.out.println("Calcuate interest rates!\n");
  49.         System.out.print("What is your interest rate?");
  50.         double interest = console.nextDouble();
  51.         System.out.print("Over how many years?");
  52.         int years = console.nextInt();
  53.         System.out.print("What is your investment?");
  54.         double investment = console.nextDouble();
  55.         System.out.print("What is your yearly deposit?");
  56.         double deposit = console.nextDouble();
  57.         System.out.println("Results:\n");
  58.         interestRate(interest,years,investment,deposit);
  59.     }
  60.     public static void interestRate(double interest, int years, double investment, double deposit){
  61.         System.out.println("Year:          Current Balance:          Interest:          New Deposit:          New Balance:");
  62.         for(int i = 1; i<= years; i++){
  63.  
  64.            System.out.print(i);
  65.            String I = "" + i;
  66.            int lengthI = I.length();
  67.            spaces(15-lengthI);
  68.  
  69.             double tempinv = (int) (investment*100);
  70.            System.out.print(tempinv /100);
  71.             String inv ="" + tempinv /100;
  72.            int lengthInv = inv.length();
  73.            spaces(26 - lengthInv);
  74.  
  75.             double tempint = (int) (interest * 100);
  76.            System.out.print(tempint /100);
  77.            String inte = "" + tempint/100;
  78.            int lengthInte = inte.length();
  79.             spaces(19-lengthInte);
  80.  
  81.            double tempdep = (int) (deposit *100);
  82.            System.out.print(tempdep/100);
  83.             String dep = ""  + tempdep/100;
  84.             int lengthDep = dep.length();
  85.             spaces(22-lengthDep);
  86.  
  87.            investment += investment * .065;
  88.             double tempbal = (int) (investment*100);
  89.            System.out.println(tempbal/100);
  90.            investment += deposit;
  91.  
  92.         }
  93.  
  94.     }
  95.    public static void spaces(int n){
  96.        for(int i =1; i<= n; i++){
  97.            System.out.print(" ");
  98.        }
  99.    }
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106. //-------------------------------------------------------------------------------------------------------------------------------------
  107. //project 3
  108. /**
  109.  * Created by Daniel on 4/10/2016.
  110.  */
  111. public class project3twelvedays {
  112.     public static void main(String[]args){
  113.         presents(12);
  114.     }
  115.     public static void presents(int days){
  116.         System.out.println("Day               Presents Received               Total Presents");
  117.         int presents = 0;
  118.         for(int i =1;i<= days;i++){
  119.             System.out.print(i);
  120.             String ii = "" + i;
  121.             spaces(18 - ii.length());
  122.             System.out.print(i);
  123.             presents += i;
  124.             spaces(32 - ii.length());
  125.             System.out.println(presents);
  126.         }
  127.     }
  128.     public static void spaces(int n){
  129.         for(int i =1; i<= n; i++){
  130.             System.out.print(" ");
  131.         }
  132.     }
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. //-------------------------------------------------------------------------------------------------------------------------------------
  143. //project 6
  144. /**
  145.  * Created by Daniel on 4/4/2016.
  146.  */
  147. import java.util.*;
  148. public class project6calendars {
  149.     public static void main(String[] args){
  150.         Scanner console = new Scanner(System.in);
  151.         System.out.println("Create a calendar:\n");
  152.         System.out.print("How many days?");
  153.         int days = console.nextInt();
  154.         System.out.print("When is the first Sunday?");
  155.         int firstSunday = console.nextInt();
  156.         System.out.println("Calendar:\n");
  157.         calendar(days,firstSunday);
  158.     }
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.     public static void calendar(int days, int firstSunday){
  166.         System.out.println("  Sun    Mon    Tue    Wed    Thu    Fri    Sat");
  167.         line();
  168.         int counter = 7;
  169.         int column =1;
  170.         int spaces = 0;
  171.         for(int blank = 1 ;blank <= firstSunday*-1 + 8&& firstSunday != 1;blank++) {
  172.             System.out.print("|      ");
  173.             counter =  7 - (firstSunday*-1 + 8);
  174.             spaces++;
  175.         }
  176.  
  177.         for (int mdays = 0; mdays < days;){
  178.             for( int col = 1; col <=counter; col++) {
  179.                 for(int i = 1; mdays*i < days;i = days){
  180.                     mdays++;
  181.                     System.out.print("|" + padded(mdays, 4) + "  ");
  182.  
  183.                 }
  184.  
  185.             }
  186.             if(mdays != days) {
  187.                 System.out.println("|");
  188.                 column++;
  189.             }
  190.  
  191.  
  192.          counter = 7; //6 its 2, 7, 7, its 3
  193.          }
  194.         int blank = 1;
  195.         //firstSunday -4
  196.         for( blank = 1 ;blank <= (7*column)- spaces - days ;blank++) {
  197.             System.out.print("|      ");
  198.  
  199.  
  200.         }
  201.         if(blank >= firstSunday-4){
  202.             System.out.println("|");
  203.         }
  204.         line();
  205.     }
  206.  
  207.  
  208.     public static void line(){
  209.         for(int i =1; i <= 7; i++){
  210.             System.out.print("+------");
  211.         }
  212.         System.out.println("+");
  213.     }
  214.     public static String padded(int n, int width){
  215.         String s = "" + n;
  216.         for(int i = s.length(); i< width;i++){
  217.             s = " " + s;
  218.         }
  219.         return s;
  220.     }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment