Skip to content

Commit 4b0f310

Browse files
committed
Activity [ IP ]
1 parent 0339a10 commit 4b0f310

File tree

9 files changed

+269
-0
lines changed

9 files changed

+269
-0
lines changed

LabInput1/.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"java.project.sourcePaths": ["src"],
3+
"java.project.outputPath": "bin",
4+
"java.project.referencedLibraries": [
5+
"lib/**/*.jar"
6+
]
7+
}

LabInput1/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Getting Started
2+
3+
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
4+
5+
## Folder Structure
6+
7+
The workspace contains two folders by default, where:
8+
9+
- `src`: the folder to maintain sources
10+
- `lib`: the folder to maintain dependencies
11+
12+
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
13+
14+
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
15+
16+
## Dependency Management
17+
18+
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).

LabInput1/src/LabInput1.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* LabInput1.java
3+
* Time Converter Activity #1
4+
* @author PP-Namias
5+
* Licensed under MIT License
6+
*/
7+
/**
8+
* @param [input] the scanner for user input.
9+
* @param [seconds] The number of seconds input.
10+
* @param [hours] the number of hours.
11+
* @param [minutes] the number of minutes.
12+
* @param [secondsRemainder] the number of seconds remainder.
13+
* @param [exit] the boolean to check if the program will exit.
14+
*/
15+
/*
16+
* Write a program that accepts input to varible seconds.
17+
* The program will then output the equivalent time in hours:minutes:seconds format.
18+
* use labInput1 as classname and filename.
19+
*
20+
* Test ouput:
21+
* Please enter number of seconds: 4870
22+
* 4870 seconds = 1:21:10
23+
*/
24+
import java.util.Scanner;
25+
26+
public class LabInput1 {
27+
public static void main(String[] args) {
28+
Scanner input = new Scanner(System.in);
29+
int seconds, hours, minutes, secondsRemainder;
30+
boolean exit = false;
31+
32+
while (!exit) {
33+
try {
34+
System.out.print("Please enter number of seconds or enter '0' to quit: ");
35+
seconds = input.nextInt();
36+
if (seconds == 0) {
37+
System.out.print("Exiting the program! Thank you for using this program!");
38+
exit = true;
39+
}
40+
else {
41+
hours = seconds / 3600;
42+
minutes = (seconds % 3600) / 60;
43+
secondsRemainder = (seconds % 3600) % 60;
44+
System.out.println(seconds + " seconds = " + hours + ":" + minutes + ":" + secondsRemainder);
45+
}
46+
} catch (Exception e) {
47+
System.out.println("Please enter the correct input.");
48+
}
49+
}
50+
input.close();
51+
}
52+
}

LabInput2/.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"java.project.sourcePaths": ["src"],
3+
"java.project.outputPath": "bin",
4+
"java.project.referencedLibraries": [
5+
"lib/**/*.jar"
6+
]
7+
}

LabInput2/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Getting Started
2+
3+
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
4+
5+
## Folder Structure
6+
7+
The workspace contains two folders by default, where:
8+
9+
- `src`: the folder to maintain sources
10+
- `lib`: the folder to maintain dependencies
11+
12+
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
13+
14+
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
15+
16+
## Dependency Management
17+
18+
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).

LabInput2/src/LabInput2.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* LabInput2.java
3+
* Time Interpreter Activity #2
4+
* @author PP-Namias
5+
* Licensed under MIT License
6+
*/
7+
/**
8+
* @param [input] the scanner for user input.
9+
* @param [num] the number that indicates the number of that needs to be interperted.
10+
* @param [hundreds] the number of hundreds.
11+
* @param [tens] the number of tens.
12+
* @param [ones] the number of ones.
13+
* @param [exit] the boolean to check if the program will exit.
14+
*/
15+
/*
16+
* Write a program that inputs a three-digit value into variable num
17+
* and then display each digit with the corresponding place value. A
18+
* sample output is given below. Use LabInput2 as classname and filename
19+
*
20+
* Test output:
21+
* Please enter a three-digit integer: 487
22+
* The value of num = 487
23+
* 4 hundreds 8 tens and 7 ones
24+
*/
25+
import java.util.Scanner;
26+
27+
public class LabInput2 {
28+
public static void main(String[] args) {
29+
Scanner input = new Scanner(System.in);
30+
int num, hundreds, tens, ones;
31+
boolean exit = false;
32+
33+
while (!exit) {
34+
try {
35+
System.out.print("Please enter a three-digit integer or enter '0' to quit: ");
36+
num = input.nextInt();
37+
if (num == 0) {
38+
System.out.print("Exiting the program! Thank you for using this program!");
39+
exit = true;
40+
}
41+
else {
42+
hundreds = num / 100;
43+
tens = (num % 100) / 10;
44+
ones = (num % 100) % 10;
45+
System.out.println("The value of num = " + num);
46+
if (hundreds == 0) {
47+
System.out.println(tens + " tens and " + ones + " ones");
48+
}
49+
else if (hundreds == 1) {
50+
System.out.println(hundreds + " hundred " + tens + " tens and " + ones + " ones");
51+
}
52+
else if (tens == 0) {
53+
System.out.println(hundreds + " hundreds and " + ones + " ones");
54+
}
55+
else if (tens == 1) {
56+
System.out.println(hundreds + " hundreds " + tens + " ten and " + ones + " ones");
57+
}
58+
else if (ones == 0) {
59+
System.out.println(hundreds + " hundreds " + tens + " tens");
60+
}
61+
else if (ones == 1) {
62+
System.out.println(hundreds + " hundreds " + tens + " tens and " + ones + " one");
63+
}
64+
else{
65+
System.out.println(hundreds + " hundreds " + tens + " tens and " + ones + " ones");
66+
}
67+
}
68+
} catch (Exception e) {
69+
System.out.println("Please enter the correct input.");
70+
}
71+
}
72+
input.close();
73+
}
74+
}

LabInput4/.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"java.project.sourcePaths": ["src"],
3+
"java.project.outputPath": "bin",
4+
"java.project.referencedLibraries": [
5+
"lib/**/*.jar"
6+
]
7+
}

LabInput4/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Getting Started
2+
3+
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
4+
5+
## Folder Structure
6+
7+
The workspace contains two folders by default, where:
8+
9+
- `src`: the folder to maintain sources
10+
- `lib`: the folder to maintain dependencies
11+
12+
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
13+
14+
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
15+
16+
## Dependency Management
17+
18+
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).

LabInput4/src/LabInput4.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* LabInput4.java
3+
* Inflation Rate Calculator Activity #4
4+
* @author PP-Namias
5+
* Licensed under MIT License
6+
*/
7+
/**
8+
* @param [input] the scanner for user input.
9+
* @param [itemName] the name of the item.
10+
* @param [priceLastYear] the price of the last year
11+
* @param [priceThisYear] the price of this year
12+
* @param [inflationRate] the inflation rate
13+
* @param [exit] the boolean to check if the program will exit.
14+
*/
15+
/*
16+
* Write a program to gauge the amount of inflation over the past year.
17+
* The program asks for the item name (such as notebook or a printer),
18+
* price of an item both one yeaar ago and today.
19+
* It estimates the inflation rate as the diffreence in price divided by the last year's price.
20+
* Use LabInput4 as classname and filename
21+
*
22+
* Test Output:
23+
* Please enter the name of the item: netbook
24+
* Enter its price last year: 15000
25+
* Enter its price this year: 13500
26+
* The inflation rate of notebook: -0.1
27+
*
28+
* -----------------------------------------
29+
* Please enter the name of the item: chicken
30+
* Enter its price last year: 125
31+
* Enter its price this year: 150
32+
* The inflation rate of notebook: 0.2
33+
*/
34+
import java.util.Scanner;
35+
36+
public class LabInput4 {
37+
public static void main(String[] args) {
38+
Scanner input = new Scanner(System.in);
39+
String itemName;
40+
double priceLastYear, priceThisYear, inflationRate;
41+
boolean exit = false;
42+
43+
while (!exit) {
44+
try {
45+
System.out.print("Please enter the name of the item or enter 'exit' to quit: ");
46+
itemName = input.nextLine();
47+
if (itemName.equalsIgnoreCase("exit")) {
48+
System.out.print("Exiting the program! Thank you for using this program!");
49+
exit = true;
50+
}
51+
else {
52+
System.out.print("Enter its price last year: ");
53+
priceLastYear = input.nextDouble();
54+
System.out.print("Enter its price this year: ");
55+
priceThisYear = input.nextDouble();
56+
input.nextLine(); // consume the remaining newline character in the buffer
57+
inflationRate = (priceThisYear - priceLastYear) / priceLastYear;
58+
System.out.println("The inflation rate of " + itemName + ": " + inflationRate);
59+
System.out.println("-----------------------------------------");
60+
System.out.println("");
61+
}
62+
} catch (Exception e) {
63+
System.out.println("Please enter the correct input.");
64+
}
65+
}
66+
input.close();
67+
}
68+
}

0 commit comments

Comments
 (0)