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