Skip to content

Commit 706ec52

Browse files
committed
School Activity { IP ]
1 parent 073caf1 commit 706ec52

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

LabInput1.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Seconds Converter Activity #1
3+
* @author PP-Namias
4+
* Licensed under MIT License
5+
*/
6+
7+
/*
8+
* Write a program that accepts input to varible seconds.
9+
* The program will then output the equivalent time in hours:minutes:seconds format.
10+
* use labInput1 as classname and filename.
11+
*
12+
* Test ouput:
13+
* Please enter number of seconds: 4870
14+
* 4870 seconds = 1:21:10
15+
*/
16+
import java.util.Scanner;
17+
18+
public class LabInput1 {
19+
public static void main(String[] args) {
20+
Scanner input = new Scanner(System.in);
21+
int seconds, hours, minutes, secondsRemainder;
22+
System.out.print("Please enter number of seconds: ");
23+
seconds = input.nextInt();
24+
hours = seconds / 3600;
25+
minutes = (seconds % 3600) / 60;
26+
secondsRemainder = (seconds % 3600) % 60;
27+
System.out.println(seconds + " seconds = " + hours + ":" + minutes + ":" + secondsRemainder);
28+
}
29+
}

LabInput2.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Write a program that inputs a three-digit value into variable num
3+
* and then display each digit with the correspobding place value. A
4+
* sample output is given below. Use LabInput2 as classname and filename
5+
*
6+
* Test output:
7+
* Please enter a three-digit integer: 487
8+
* The value of num = 487
9+
* 4 hundreds 8 tens and 7 ones
10+
*/
11+
import java.util.Scanner;
12+
13+
public class LabInput2 {
14+
public static void main(String[] args) {
15+
Scanner input = new Scanner(System.in);
16+
int num, hundreds, tens, ones;
17+
System.out.print("Please enter a three-digit integer: ");
18+
num = input.nextInt();
19+
hundreds = num / 100;
20+
tens = (num % 100) / 10;
21+
ones = (num % 100) % 10;
22+
System.out.println("The value of num = " + num);
23+
System.out.println(hundreds + " hundreds " + tens + " tens and " + ones + " ones");
24+
}
25+
}

LabInput4.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Write a program to gauge the amount of inflation over the past year.
3+
* The program asks for the itme name (such as notebook or a printer),
4+
* price of an item both one yeaar ago and today.
5+
* It estimates the inflation rate as the diffreence in price divided by the last year'sprice.
6+
* Use LabInput4 as classname and filename
7+
*
8+
* Test Output:
9+
* Please enter he name of the item: netbook
10+
* Enter its price last year: 15000
11+
* Enter its price this year: 13500
12+
* The inflation rate of notebook: -0.1
13+
*
14+
* ------------------------------
15+
* Please enter he name of the item: chicken
16+
* Enter its price last year: 125
17+
* Enter its price this year: 150
18+
* The inflation rate of notebook: 0.2
19+
*/
20+
import java.util.Scanner;
21+
22+
public class LabInput4 {
23+
public static void main(String[] args) {
24+
Scanner input = new Scanner(System.in);
25+
String itemName;
26+
double priceLastYear, priceThisYear, inflationRate;
27+
System.out.print("Please enter he name of the item: ");
28+
itemName = input.nextLine();
29+
System.out.print("Enter its price last year: ");
30+
priceLastYear = input.nextDouble();
31+
System.out.print("Enter its price this year: ");
32+
priceThisYear = input.nextDouble();
33+
inflationRate = (priceThisYear - priceLastYear) / priceLastYear;
34+
System.out.println("The inflation rate of " + itemName + ": " + inflationRate);
35+
}
36+
}

0 commit comments

Comments
 (0)