You are on page 1of 3

COMPROG1: METHODS IN JAVA

LABORATORY ACTIVITY

WEEK 14-15 DUE DECEMBER 3, 2022


DATE

SCHEDULE AM/PM- 10:00-1:00PM/ 4:00-7:00PM SCORE

LEARNING OUTCOME

Apply METHODS in java programming.

MATERIAL/S

Java compiler (JCreator or any Java compiler available online)


MS Word or yellow paper (bond paper)

ACTIVITIES

General instruction: Solve the following programming problems. Copy and paste
the code/ solutions in MS Word or yellow paper and screenshot the created
program during runtime.

PART 1. PROGRAM TRACING

Consider the following:

tax= 6%
cost= 500
cost_with_tax= (cost * .06) + cost
cost_with_tax= (500 * .06) + 500
= 30 + 500 = 530
payment= 1000
change= 470

PROGRAM CODES:

import java.io.*;

public class Change1 {


public static InputStreamReader reader= new InputStreamReader
(System.in);
public static BufferedReader input= new BufferedReader (reader);
public static double cost;
public static double costtax;
public static double payment;
public static double change;

public static void main (String []args) throws Exception {


cost= getCost();
costtax= computeCostTax();
payment= getPayment();
change= computeChange();
printReceipt();
}

public static double getCost () throws Exception {


double c;
System.out.print("Enter your total cost: ");
c= Double.parseDouble(input.readLine());
return c; }

public static double computeCostTax() throws Exception {


double t;
t= (cost * .06) + cost; //cost_with_tax= (cost * .06) + cost
return t;
}

public static double getPayment() throws Exception {


double p;
System.out.print("Enter your payment: ");
p= Double.parseDouble (input.readLine());
return p; }

public static computeChange() {


double ch;
ch= payment- costtax;
return ch; }

public static void printReceipt () {


System.out.println("Payment: " + payment);
System.out.println("Cost: " + costtax);
System.out.println("Change: " + change);
}
}

Page 2 of 3
PART 2: PROGRAMMING

Problem 2.1 Create a java program that will compute and display the sum,
difference, product, and quotient of two numbers (user input) using methods.

Problem 2.2 Create a java program that will compute for the salary of an
employee. Apply the concept of methods.

Assuming the following variables:


Rate per hour: 100.00
Tax: 20% of the salary

Compute for the gross pay and net pay of the employee for a month.
Note: Underlined words/numbers are the only user inputs.

Sample Test Data:

Enter Month: July

July 1-15 Salary


Enter total days: 13
Enter hours per day: 8
Total hours: 104
Gross Pay: 10400.00
Tax: 2800.00
Net Pay: 7600.00

July 16-30 Salary


Enter total days: 10
Enter hours per day: 8
Total hours: 80
Gross Pay: 8000.00
Tax: 1600.00
Net Pay: 6400.00

Monthly Salary for the month of July is 14000.00

Process Completed.

Page 3 of 3

You might also like