Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Daniel on 4/6/2016.
- */
- //Project 1
- public class project1ChristmasTrees {
- public static void main (String[] args){
- tree(3,5);
- }
- public static void tree(int segments,int height){
- for(int seg =1; seg <= segments; seg++){
- for(int lines = 1; lines<= height;lines++){
- for(int i = 1; i<= lines*-1 + (height)+segments-seg; i++ ){ //lines - 1
- System.out.print(" ");
- }
- for(int i = 1; i <= lines*2 +seg*2 -3;i++){
- System.out.print("*");
- }
- System.out.println();
- }
- }
- //height - segments // (height*2 -1)*(2*segments)
- for(int i = 1;i <=((height*2 -1)+(2*segments-2))/2;i++){
- System.out.print(" ");
- }
- System.out.println("*");
- for(int i = 1;i <=((height*2 -1)+(2*segments-2))/2;i++){
- System.out.print(" ");
- }
- System.out.println("*");
- for(int i = 1;i <=((height*2 -1)+(2*segments-2))/2-3;i++){
- System.out.print(" ");
- }
- System.out.println("*******");
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //project 2
- /**
- * Created by Daniel on 4/7/2016.
- */
- import java.util.*;
- public class project2interest {
- public static void main(String[] args){
- Scanner console = new Scanner(System.in);
- System.out.println("Calcuate interest rates!\n");
- System.out.print("What is your interest rate?");
- double interest = console.nextDouble();
- System.out.print("Over how many years?");
- int years = console.nextInt();
- System.out.print("What is your investment?");
- double investment = console.nextDouble();
- System.out.print("What is your yearly deposit?");
- double deposit = console.nextDouble();
- System.out.println("Results:\n");
- interestRate(interest,years,investment,deposit);
- }
- public static void interestRate(double interest, int years, double investment, double deposit){
- System.out.println("Year: Current Balance: Interest: New Deposit: New Balance:");
- for(int i = 1; i<= years; i++){
- System.out.print(i);
- String I = "" + i;
- int lengthI = I.length();
- spaces(15-lengthI);
- double tempinv = (int) (investment*100);
- System.out.print(tempinv /100);
- String inv ="" + tempinv /100;
- int lengthInv = inv.length();
- spaces(26 - lengthInv);
- double tempint = (int) (interest * 100);
- System.out.print(tempint /100);
- String inte = "" + tempint/100;
- int lengthInte = inte.length();
- spaces(19-lengthInte);
- double tempdep = (int) (deposit *100);
- System.out.print(tempdep/100);
- String dep = "" + tempdep/100;
- int lengthDep = dep.length();
- spaces(22-lengthDep);
- investment += investment * .065;
- double tempbal = (int) (investment*100);
- System.out.println(tempbal/100);
- investment += deposit;
- }
- }
- public static void spaces(int n){
- for(int i =1; i<= n; i++){
- System.out.print(" ");
- }
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //project 3
- /**
- * Created by Daniel on 4/10/2016.
- */
- public class project3twelvedays {
- public static void main(String[]args){
- presents(12);
- }
- public static void presents(int days){
- System.out.println("Day Presents Received Total Presents");
- int presents = 0;
- for(int i =1;i<= days;i++){
- System.out.print(i);
- String ii = "" + i;
- spaces(18 - ii.length());
- System.out.print(i);
- presents += i;
- spaces(32 - ii.length());
- System.out.println(presents);
- }
- }
- public static void spaces(int n){
- for(int i =1; i<= n; i++){
- System.out.print(" ");
- }
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //project 6
- /**
- * Created by Daniel on 4/4/2016.
- */
- import java.util.*;
- public class project6calendars {
- public static void main(String[] args){
- Scanner console = new Scanner(System.in);
- System.out.println("Create a calendar:\n");
- System.out.print("How many days?");
- int days = console.nextInt();
- System.out.print("When is the first Sunday?");
- int firstSunday = console.nextInt();
- System.out.println("Calendar:\n");
- calendar(days,firstSunday);
- }
- public static void calendar(int days, int firstSunday){
- System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
- line();
- int counter = 7;
- int column =1;
- int spaces = 0;
- for(int blank = 1 ;blank <= firstSunday*-1 + 8&& firstSunday != 1;blank++) {
- System.out.print("| ");
- counter = 7 - (firstSunday*-1 + 8);
- spaces++;
- }
- for (int mdays = 0; mdays < days;){
- for( int col = 1; col <=counter; col++) {
- for(int i = 1; mdays*i < days;i = days){
- mdays++;
- System.out.print("|" + padded(mdays, 4) + " ");
- }
- }
- if(mdays != days) {
- System.out.println("|");
- column++;
- }
- counter = 7; //6 its 2, 7, 7, its 3
- }
- int blank = 1;
- //firstSunday -4
- for( blank = 1 ;blank <= (7*column)- spaces - days ;blank++) {
- System.out.print("| ");
- }
- if(blank >= firstSunday-4){
- System.out.println("|");
- }
- line();
- }
- public static void line(){
- for(int i =1; i <= 7; i++){
- System.out.print("+------");
- }
- System.out.println("+");
- }
- public static String padded(int n, int width){
- String s = "" + n;
- for(int i = s.length(); i< width;i++){
- s = " " + s;
- }
- return s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment