Commit b7f6c6f3 authored by austin.blanke's avatar austin.blanke

Origin

parents
import java.nio.file.attribute.FileOwnerAttributeView;
public class App {
public static void main(String[] args) throws Exception {
/*
Week 2 exercises, 14/2/2022, made by Austin Blanke
*/
int month = 1;
countDays();
Circumference(3);
System.out.println(inigoSpeech(10));
System.out.println(isItALeapYear(2021));
/*
month = 1;
do{
switch (month){
case 1: System.out.println("January");
break;
case 2: System.out.println("February");
break;
case 3: System.out.println("March");
break;
case 4: System.out.println("April");
break;
case 5: System.out.println("May");
break;
case 6: System.out.println("June");
break;
case 7: System.out.println("July");
break;
case 8: System.out.println("August");
break;
case 9: System.out.println("September");
break;
case 10: System.out.println("October");
break;
case 11: System.out.println("November");
break;
case 12: System.out.println("December");
break;
default: System.out.println("Not a valid month");
break;
}
month ++;
}while (month < 14);
month = 1;
while(month < 14){
switch (month){
case 1: System.out.println("January");
break;
case 2: System.out.println("February");
break;
case 3: System.out.println("March");
break;
case 4: System.out.println("April");
break;
case 5: System.out.println("May");
break;
case 6: System.out.println("June");
break;
case 7: System.out.println("July");
break;
case 8: System.out.println("August");
break;
case 9: System.out.println("September");
break;
case 10: System.out.println("October");
break;
case 11: System.out.println("November");
break;
case 12: System.out.println("December");
break;
default: System.out.println("Not a valid month");
break;
}
month ++;
}
for(month = 1; month < 14; month++){
switch (month){
case 1: System.out.println("January");
break;
case 2: System.out.println("February");
break;
case 3: System.out.println("March");
break;
case 4: System.out.println("April");
break;
case 5: System.out.println("May");
break;
case 6: System.out.println("June");
break;
case 7: System.out.println("July");
break;
case 8: System.out.println("August");
break;
case 9: System.out.println("September");
break;
case 10: System.out.println("October");
break;
case 11: System.out.println("November");
break;
case 12: System.out.println("December");
break;
default: System.out.println("Not a valid month");
break;
}
} */
}
public static void countDays(){
int daysPerWeek = 7; // Ex 2.1
int numberOfWeeks = 6; // Ex 2.2
int totalDays = daysPerWeek * numberOfWeeks; // Ex 2.3
boolean onHoliday = false; // Ex 2.4
if(onHoliday){System.out.println("On holiday");}
else {System.out.println("Not on holiday");}
}
public static void Circumference(int radius){
double approxPI = 3.14; // Ex 2.5
System.out.println("Circumference: " + (2 * approxPI * radius * radius));
}
public static String inigoSpeech(int numFingers){
String greetingString = "Hello"; // Ex 2.7
String introductionString = "My name is Inigo Montoya"; // Ex 2.8
String reminderString = "You killed my father"; // Ex 2.9
String threatString = "Prepare to die!"; // Ex 2.10
int fingersOnRightHand = numFingers - 5;
if (fingersOnRightHand == 6){
return (greetingString + ", " + introductionString + ", " + reminderString + ", " + threatString);
}
else{
return ("5 fingers, you're good");
}
}
public static Boolean isItALeapYear(int year){
if (year % 4 == 0){return true;}
else {return false;}
}
public static int daysInYear(int year){
if (isItALeapYear(year)){return 366;}
else {return 365;}
}
public static int daysInYearFrom(int day, int month, int year){
int days = 0;
for(month = month++; month < 13; month ++){
switch (month){
case 1: days = days + 31;
break;
case 2: days = days + 28;
break;
case 3: days = days + 31;
break;
case 4: days = days + 30;
break;
case 5: days = days + 31;
break;
case 6: days = days + 30;
break;
case 7: days = days + 31;
break;
case 8: days = days + 31;
break;
case 9: days = days + 30;
break;
case 10: days = days + 31;
break;
case 11: days = days + 30;
break;
case 12: days = days + 31;
break;
}
}
}
public static int daysBetween(int startDay, int startMonth, int startYear, int endDay, int endMonth, int endYear){
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment