0% found this document useful (0 votes)
18 views7 pages

ITP Activity Week 8

The document discusses two Java programs - one that calculates inflation rate between item prices from last year and this year, and another that calculates an electricity bill based on hourly wattage used and cost per kilowatt. It provides sample input and output for testing each program.

Uploaded by

juencyzalty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views7 pages

ITP Activity Week 8

The document discusses two Java programs - one that calculates inflation rate between item prices from last year and this year, and another that calculates an electricity bill based on hourly wattage used and cost per kilowatt. It provides sample input and output for testing each program.

Uploaded by

juencyzalty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Name: Dela Cruz, Franc Alvenn T.

Rating: _________
Year and Section: BSIT 1-A Professor / Instructor: Prof. Herliza Estrada
Due of Submission:

Week No. 8
JAVA BASIC INPUT AND OUTPUT

1. Write a program to gauge the amount of inflation over the past year. The
program asks for the item name (such as notebook or a printer), price of the
item both one year ago and today. It estimates the inflation rate as the
difference in price divided by last year's price.

Test Output
Item name: Notebook
Price Last Year : 11.50
Price This Year: 12.50
Inflation rate of Notebook: 0.09

2.Write a Java program to calculate Electricity bill. The program will


allow the user enter the consumed watts per hour daily and the cost per
kilowatt hour. Compute the electricity bill for one month. Display the
result

Test Output:
Total watt s used per hour 500
Cost Per kilowatt : 5
Total watt s used monthly : 360 000
Total kilo watts used: 360
Total Overdue: 1800
Week No. 1
OVERVIEW OF PROGRAMMING
Answer Sheet:

Number 1:
Source Code :
package itpacts;
import java.util.Scanner;
public class Week8 {

public static void main(String[] args) {

//Program to calculate the inflation over the past year


Scanner x = new Scanner(System.in);
System.out.print("Item name: ");
String itemName = x.nextLine();
System.out.print("Price Last Year: ");
double priceLastYear = x.nextDouble();
System.out.print("Price This Year: ");
double priceThisYear = x.nextDouble();

//calculates the inflation rate


double inflationRate = (priceThisYear - priceLastYear)/priceLastYear;

//rounds off the inflation rate


double roundOff = (double)Math.round(inflationRate * 100)/100;

//outputs results
System.out.println("Here are the result:");
System.out.println("Item Name: " + itemName);
System.out.println("Price Last Year: " + priceLastYear);
System.out.println("Price This Year: " + priceThisYear);
System.out.println("Inflation rate of " + itemName + "this Year: " + roundOff);
}
}
Output :
Input: Here are the result:
Item Name: Notebook Item Name: Notebook
Price Last Year: 11.50 Price Last Year: 11.50
Price This Year: 12.50 Price This Year: 12.50
Inflation rate of Cellphonethis Year: 0.09
Week No. 1
OVERVIEW OF PROGRAMMING
Answer Sheet:

Source Code :
Week No. 1
OVERVIEW OF PROGRAMMING
Answer Sheet:

Source Code :
Week No. 1
OVERVIEW OF PROGRAMMING
Answer Sheet:

Number 2:
Source Code :
ppackage itpacts;
import java.util.Scanner;
public class Week8 {

public static void main(String[] args) {


//Program to calculate the Electricity Bill
Scanner x = new Scanner(System.in);
System.out.print("Total kilowatts used per hour: ");
int totalwattsPerHour = x.nextInt();
System.out.print("Cost per kilowatt: ");
int costPerKilowatt = x.nextInt();

int totalwattsPerMonth = (totalwattsPerHour * 24)*30;


int totalKilowattsUsed = totalwattsPerMonth / 1000;
int totalOverdue = totalKilowattsUsed * costPerKilowatt;

System.out.println("Total watts used per month: " + totalwattsPerMonth);


System.out.println("Total kilowatts used: " + totalKilowattsUsed);
System.out.println("Total Overdue: " + totalOverdue);
}
}

Output :
Total kilowatts used per hour: 500
Cost per kilowatt: 5
Total watts used per month: 360000
Total kilowatts used: 360
Total Overdue: 1800
Week No. 1
OVERVIEW OF PROGRAMMING
Answer Sheet:

Number 2:
Source Code :
Week No. 1
OVERVIEW OF PROGRAMMING
Answer Sheet:

Number 2:
Source Code :

You might also like