Commit b096720b authored by Arminas Lietuvnikas's avatar Arminas Lietuvnikas

Week 2 Work

parents
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
File added
File added
//These are my exercises for week 2 of programming.
//14/02/2022
//Made by: Arminas Lietuvnikas
public class App
{
public static void main(String[] args) throws Exception
{
//System.out.println("Days per week: " + daysPerWeek);
//System.out.println("Number of weeks: " + numberOfWeeks);
//System.out.println("Total days: " + totalDays);
countDays();
holiday();
pi();
monthnum();
monthnum2();
monthnum3();
inigoSpeech();
isItALeapYear();
daysBetween();
}
public static void holiday()
{
boolean onHoliday = false;//Ex 2.4
if (onHoliday == false)
{
System.out.println("On holiday? No");
}
else
{
System.out.println("On holiday? Yes");
}
}
public static void pi()
{
double approxPI = 3.14;//Ex 2.5
int radius = 3;
System.out.println("Circumference of Circle with radius 3: " + (2 * approxPI * radius));
}
public static void monthnum()
{
int month = 2;//Ex 5.1
for (int i = 0; i < 15; i++)
{
switch (i)
{
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;
case 13: System.out.println("Not a valid month");
return;
}
}
}
public static void monthnum2()
{
int i = 0;//Ex 7.1
while(i < 14)
{
i++;
switch (i)
{
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;
case 13: System.out.println("Not a valid month");
return;
}
}
}
public static void monthnum3()
{
int i = 0;//Ex 7.2
do
{
i++;
switch (i)
{
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;
case 13: System.out.println("Not a valid month");
return;
}
} while(i < 14);
}
public static void countDays()
{
int daysPerWeek = 7;//Ex 2.1
int numberOfWeeks = 6;//Ex 2.2
int totalDays = daysPerWeek * numberOfWeeks;//Ex 2.3
System.out.println("Total days: " + totalDays);
}
public static void inigoSpeech()
{
int numFingers = 5;//Ex 4.1
if (numFingers == 6)
{
System.out.println("Fingers on right hand: " + numFingers);
}
else;
{
System.out.println("I am searching for the man who killed my father.");
}
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
System.out.println(greetingString +", "+ introductionString +", "+ reminderString +", "+ threatString);
}
public static void isItALeapYear()
{
int year = 366;
if (year == 366)
{
System.out.println("Is it a leap year? True");
}
else
{
System.out.println("Is it a leap year? False");
}
}
public static void daysBetween()
{
int startDay = 26;
int startMonth = 2;
int startYear = 1;
int endDay = 28;
int endMonth = 2;
int endYear = 1;
int sDays = 0;
int eDays = 0;
int daysInBetween = 0;
if (startMonth == 1)
{
sDays = sDays + 31;
}
else if (startMonth == 2)
{
sDays = sDays + 31 + 28;
}
else if (startMonth == 3)
{
sDays = sDays + 31 + 28 + 31;
}
else if (startMonth == 4)
{
sDays = sDays + 31 + 28 + 31 + 30;
}
else if (startMonth == 5)
{
sDays = sDays + 31 + 28 + 31 + 30 + 31;
}
else if (startMonth == 6)
{
sDays = sDays + 31 + 28 + 31 + 30 + 31 + 30;
}
else if (startMonth == 7)
{
sDays = sDays + 31 + 28 + 31 + 30 + 31 + 30 + 31;
}
else if (startMonth == 8)
{
sDays = sDays + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
}
else if (startMonth == 9)
{
sDays = sDays + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
}
else if (startMonth == 10)
{
sDays = sDays + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
}
else if (startMonth == 11)
{
sDays = sDays + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
}
else if (startMonth == 12)
{
sDays = sDays + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31;
}
if (endMonth == 1)
{
eDays = eDays + 31;
}
else if (endMonth == 2)
{
eDays = eDays + 31 + 28;
}
else if (endMonth == 3)
{
eDays = eDays + 31 + 28 + 31;
}
else if (endMonth == 4)
{
eDays = eDays + 31 + 28 + 31 + 30;
}
else if (endMonth == 5)
{
eDays = eDays + 31 + 28 + 31 + 30 + 31;
}
else if (endMonth == 6)
{
eDays = eDays + 31 + 28 + 31 + 30 + 31 + 30;
}
else if (endMonth == 7)
{
eDays = eDays + 31 + 28 + 31 + 30 + 31 + 30 + 31;
}
else if (endMonth == 8)
{
eDays = eDays + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
}
else if (endMonth == 9)
{
eDays = eDays + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
}
else if (endMonth == 10)
{
eDays = eDays + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
}
else if (endMonth == 11)
{
eDays = eDays + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
}
else if (endMonth == 12)
{
eDays = eDays + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31;
}
startYear = startYear * 365;
sDays = sDays + startYear;
sDays = sDays - startDay;
endYear = endYear * 365;
eDays = eDays + endYear;
eDays = eDays - endDay;
daysInBetween = sDays - eDays;
System.out.println(daysInBetween + " days in between");
System.out.println(sDays);
System.out.println(eDays);
System.out.println(startDay);
System.out.println(endDay);
System.out.println(startMonth);
System.out.println(endMonth);
}
}
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