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

Java Programs for Discount Calculations

The document contains 11 solved Java programs related to input, calculations, and other basic programming concepts. The programs cover topics like discounts, compound interest, time conversions, profit/loss calculations, and swapping variable values. Each program includes sample inputs, outputs, and code to perform the given task.

Uploaded by

Ayush Shaw
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)
41 views7 pages

Java Programs for Discount Calculations

The document contains 11 solved Java programs related to input, calculations, and other basic programming concepts. The programs cover topics like discounts, compound interest, time conversions, profit/loss calculations, and swapping variable values. Each program includes sample inputs, outputs, and code to perform the given task.

Uploaded by

Ayush Shaw
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

ICSE COMPUTER APPLICATION

CLASS IX
SOLVED PROGRAMS
CHAPTER-INPUT

Program 1. A shopkeeper offers 30% discount on purchasing articles whereas the other
shopkeeper offers two successive discounts 20% and 10% for purchasing the same
articles. Write a program in Java to compute and display the discounts.
Take the price of an article as the input.
import [Link].*;

public class Discount


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter price ");
double price = [Link]();
double d1 = price * 30 / 100.0;
double amt1 = price - d1;
[Link]("30% discount = " + d1);
[Link]("Amount after 30% discount = " + amt1);
double d2 = price * 20 / 100.0;
double amt2 = price - d2;
double d3 = amt2 * 10 / 100.0;
amt2 =amt2- d3;
[Link]("20% discount = " + d2);
[Link]("10% discount = " + d3);
[Link]("Amount after successive discounts = " + amt2);
}
}
Program2. A shopkeeper offers 10% discount on the printed price of a Digital Camera.
However, a customer has to pay 6% GST on the remaining amount. Write a program in
Java to calculate the amount to be paid by the customer taking printed price as an input.

import [Link].*;

public class CameraPrice


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter printed price of Digital Camera:");
double mrp = [Link]();
double dis = mrp * 10 / 100.0;
double price = mrp - dis;
double gst = price * 6 / 100.0;
price = price+gst;
[Link]("Amount to be pai= " + price);
}
}
Program 3. The time period of a Simple Pendulum is given by the formula:
T = 2π√(l/g)
Write a program to calculate the time period of a Simple Pendulum by taking length
and acceleration due to gravity (g) as inputs.

import [Link].*;
public class Pendulum_scan
{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter length: ");
double l = [Link]();
[Link]("Enter g ");
double g = [Link]();
double t = 2 * (22.0 / 7.0) * [Link](l/g);
[Link]("T = " + t); }}
Program 4. Write a program by using class 'Employee' to accept Basic Pay of an
employee.
Calculate the allowances/deductions as given below.

Allowance / Deduction Rate


Dearness Allowance (DA) 30% of Basic Pay
House Rent Allowance (HRA) 15% of Basic Pay
Provident Fund (PF) 12.5% of Basic Pay

Finally, find and print the Gross and Net pay.


Gross Pay = Basic Pay + Dearness Allowance + House Rent Allowance
Net Pay = Gross Pay - Provident Fund
import [Link].*;

public class Employee


{

public static void main(String arg[]) {


Scanner in = new Scanner([Link]);
[Link]("Enter Basic Pay: ");
double bp = [Link]();
double da = 0.3 * bp;
double hra = 0.15 * bp;
double pf = 0.125 * bp;
double gp = bp + da + hra;
double np = gp - pf;
[Link]("Gross Pay = " + gp);
[Link]("Net Pay = " + np);
}}
Program 5. Mr. Agarwal invests certain sum at 5% per annum compound interest for
three years. Write a program in Java to calculate:

(a) the interest for the first year


(b) the interest for the second year
(c) the amount after three years.
Take sum as an input from the user.
Sample Input: Principal = Rs.5000, Rate =10%, Time = 3 yrs
Sample Output: Interest for the first year: Rs.500
Interest for the second year: Rs.550
Interest for the third year: Rs.605

import [Link].*;
public class Compound_Interest{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter sum of money: ");
double p = [Link]();
double interest = p * 5 * 1 / 100.0;
[Link]("Interest for the first year = " + interest);
p =p+ interest;
interest = p * 5 * 1 / 100.0;
[Link]("Interest for the second year = " + interest);
p =p+ interest;
interest = p * 5 * 1 / 100.0;
[Link]("Interest for the third year = " + interest);
}
}
Program 6. A businessman wishes to accumulate 3000 shares of a company. However,
he already has some shares of that company valuing ₹10 (nominal value) which yield
10% dividend per annum and receive ₹2000 as dividend at the end of the year. Write a
program in Java to calculate the number of shares he has and how many more shares
to be purchased to make his target.
Hint: No. of share = (Annual dividend * 100) / (Nominal value * div %)
public class Shares_Divident
{
public static void main(String args[]) {
int s_held = (2000 * 100)/(10 * 10);
[Link]("No. of shares held currently = " + s_held);
int s_required = 3000 - s_held;
[Link]("No. of shares to purchase = " + s_required);
}
}

Program 7. Write a program to input the time in seconds. Display the time after
converting them into hours, minutes and seconds.
Sample Input: Time in seconds 5420
Sample Output: 1 Hour 30 Minutes 20 Seconds

public class Second


{
public static void main(int sec) {

long hrs = sec / 3600;


sec =sec% 3600;
long mins = sec / 60;
sec =sec% 60;
[Link](hrs + " Hours " + mins + " Minutes " + sec + " Seconds");
}}

Program 8. A shopkeeper sells two calculators for the same price. He earns 20% profit
on one and suffers a loss of 20% on the other. Write a program to find his total cost
price of the calculators by taking selling price as input.
Hint: CP = (SP / (1 + (profit / 100))) (when profit)
CP = (SP / (1 - (loss / 100))) (when loss)
import [Link].*;

public class Shop


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter the selling price: ");
double sp = [Link]();
double cp1 = (sp / (1 + (20 / 100.0)));
double cp2 = (sp / (1 - (20 / 100.0)));
double total_cp = cp1 + cp2;
[Link]("Total Cost Price = " + total_cp);
}
}

Program 9. A certain amount is invested at the rate 10% per annum for 3 years.
Find the difference between Compound Interest (CI) and Simple Interest (SI).
Write a program to take amount as an input.
Hint: SI = (P * R * T) / 100
A = P * (1 + (R/100))T
CI = A - P

import [Link].*;
public class SI_CI
{
public static void main(String args[])
{
Scanner in = new Scanner([Link]);
[Link]("Enter Amount: ");
double p = [Link]();
double si = p * 10 * 3 / 100;
double ciAmt = p * [Link](1 + (10/100.0), 3);
[Link]("Difference between CI & SI: " +ciAmt);
double ci = ciAmt - p;
[Link]("Difference between CI & SI: " + (ci - si));
}
}

Program 10. Write a program to input two unequal numbers. Display the numbers
after swapping their values in the variables without using a third variable.
Sample Input: a = 23, b = 56
Sample Output: a = 56, b = 23

class Swap
{
public static void main(String args[])
{
int a=23,b=56;
a =a+ b;
b = a - b;
a =a- b;
[Link]("a = " + a + ", b = " + b);
}
}
Program 11. Write a program to input two unequal numbers. Display the numbers
after swapping their values in the variables using a third variable.
Sample Input: a = 23, b = 56
Sample Output: a = 56, b = 23

class Swap1
{
public static void main(String args[])
{
int a=23,b=56,t=0;
t=a;
a=b;
b=t;
[Link]("a = " + a + ", b = " + b);
}
}

Common questions

Powered by AI

Gross Pay is calculated by adding Basic Pay with Dearness Allowance (DA) at 30% and House Rent Allowance (HRA) at 15% of Basic Pay. Net Pay is derived by subtracting the Provident Fund (PF) deduction, 12.5% of Basic Pay, from Gross Pay. This method evaluates total financial obligations and entitlements, reflecting normal payroll processes by accumulating allowances before applying mandatory deductions .

Calculate Simple Interest (SI) using SI = (P * R * T) / 100. For Compound Interest (CI), compute the amount using A = P * (1 + R/100)^T then subtract the principal to get CI, and finally, find the difference as CI - SI. This approach highlights the cumulative impact of interest on investments, showcasing the benefits and drawbacks between simple and compound techniques .

Convert seconds to hours by dividing the total by 3600 (seconds per hour). Next, calculate minutes by dividing the remainder by 60 (seconds per minute). Remaining seconds form the final component. This conversion decomposes total seconds into more perceivable time units, aiding practical time management .

Calculate the number of Mr. Agarwal's current shares using (Annual Dividend * 100) / (Nominal Value * Dividend %). Subtract the owned shares from the target of 3000 to determine additional required purchases. This step-by-step calculation method helps strategically adjust holdings toward targeted goals through structured equity acquisition .

Compute the cost price for the calculator sold at a profit by applying CP = SP / (1+profit%). For the one sold at a loss, use CP = SP / (1-loss%). Add these to obtain the total cost price. This illustrates decision-making in a business context, where differential pricing strategies affect overall profitability despite identical selling prices .

Swapping without an extra variable involves arithmetic operations: sum the two numbers, then individually subtract each from the sum to isolate their values in opposite variables. Conversely, using a third variable allows directly assigning one value to it, thereby facilitating straightforward assignment swaps. Each method emphasizes differing manipulation strengths through arithmetic versus straightforward temporary holds .

First, apply a 10% discount on the camera's printed price by reducing it to 90% of the original. On this reduced price, add a 6% GST, calculated as 6% of 90% of the original price. The final price is the sum of the discounted price and the GST amount. This approach computes the final amount paid by the customer, factoring both the discount and tax sequentially .

To compute the effective discount from two successive discounts of 20% and 10%, first apply the 20% discount, reducing the original price to 80% of its value. Then, apply a 10% discount on the resulting amount, which equates to an additional 8% discount, totaling 28% effectively. Compare this to a 30% single discount which gives a larger reduction of the initial price. Hence, a single 30% discount is more beneficial than successive discounts of 20% and 10% as it results in a greater absolute price reduction .

The time period of a simple pendulum is calculated using the formula T = 2π√(l/g), where l is the length of the pendulum and g is the acceleration due to gravity. The formula derives from the principles of harmonic motion, where the period is proportional to the square root of the pendulum's length divided by gravitational acceleration. This reflects how pendulum length and gravity influence oscillation duration, crucial for understanding pendulum behavior .

To calculate Mr. Agarwal's compound interest over three years, begin with the first year interest as 5% of the initial principal. For the second year, compute 5% of the new principal, which includes the first year's interest. Repeat this for the third year. Compound interest involves reinvesting interest each year, creating increasing annual interest amounts due to compounding upon both the initial principal and prior interest .

You might also like