[go: up one dir, main page]

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

StdIX CH 4&5 Programs

Uploaded by

nilkanthamaji52
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)
42 views7 pages

StdIX CH 4&5 Programs

Uploaded by

nilkanthamaji52
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

Sacred Heart School, Adra

Date: 09/07/24 Std IX


Dear students, kindly go through the following programs and note them down in your class
notebooks.

Chapter 4:Operators
Q. Unsolved Java Programming:-

1. Write a program to find and display the value of the given expression:

(x + 3) / 6 - (2x + 5) / 3;

taking the value of x = 5

Ans: public class Expression

public static void main(String args[]) {

int x = 5;

double value = ((x + 3) / 6.0) - ((2 * x + 5) / 3.0);

System.out.println("Result = " + value);

2. A person is paid ₹350 for each day he works and fined ₹30 for each day he remains absent.

Write a program to calculate and display his monthly income, if he is present for 25 days and

remains absent for 5 days.

Ans: public class Salary

public static void main(String args[])

int salary = 25 * 350;

int fine = 5 * 30;

int netSalary = salary - fine;

System.out.println("Monthly Income = " + netSalary);

3. Write a program to find and display the percentage difference, when a number is updated
from 7.5 to 7.2

Ans: public class PercentIncrease

public static void main(String args[])

double orgNum = 7.5;

double newNum = 7.2;

double inc = newNum - orgNum;

double p = inc / orgNum * 100;

System.out.println("Percentage Difference = " + p + "%");

4. The normal temperature of human body is 98.6°F. Write a program to convert the

temperature into degree Celsius and display the output.

Hint: c / 5 = f - 32 / 9

Ans: public class Celsius

public static void main(String args[])

double f = 98.6;

double c = 5 * (f - 32) / 9.0;

System.out.println("Temperature in Degree Celsius = " + c);

5.The angles of a quadrilateral are in the ratio 3:4:5:6. Write a program to find and display all of

its angles. [Hint: The sum of angles of a quadrilateral = 360°]

Ans: public class QuadRatio

public static void main(String args[])

int r1 = 3, r2 = 4, r3 = 5, r4 = 6;
double x = 360 / (double)(r1 + r2 + r3 + r4);

double a = r1 * x;

double b = r2 * x;

double c = r3 * x;

double d = r4 * x;

System.out.println("Angle A = " + a);

System.out.println("Angle B = " + b);System.out.println("Angle C = " + c);

System.out.println("Angle D = " + d);

}
Chapter 5: Input in Java
V. Java Programming:

1.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.

Solution

import java.util.Scanner;

public class SimplePendulum

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter length: ");

double l = in.nextDouble();

System.out.print("Enter g: ");

double g = in.nextDouble();

double t = 2 * (22.0 / 7.0) * Math.sqrt(l/g);

System.out.println("T = " + t);

2.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 PayProvident 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

Solution:

import java.util.Scanner;

public class Employee


{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter Basic Pay: ");

double bp = in.nextDouble();

double da = 0.3 * bp;

double hra = 0.15 * bp;

double pf = 0.125 * bp;

double gp = bp + da + hra;

double np = gp - pf;

System.out.println("Gross Pay = " + gp);

System.out.println("Net Pay = " + np);

3. 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.

Solution:

import java.util.Scanner;

public class CameraPrice

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("Enter printed price of Digital Camera:");

double mrp = in.nextDouble();

double disc = mrp * 10 / 100.0;

double price = mrp - disc;

double gst = price * 6 / 100.0;

price += gst;

System.out.println("Amount to be paid: " + price);

}
4. 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.

Solution:

import java.util.Scanner;

public class Discounts

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print(“Enter price of article: “);

double price = in.nextDouble();

double d1 = price * 30 / 100.0;

double amt1 = price – d1;

System.out.println(“30% discount = “ + d1);

System.out.println(“Amount after 30% discount = “ + amt1);

double d2 = price * 20 / 100.0;

double amt2 = price – d2;

double d3 = amt2 * 10 / 100.0;

Amt2 -= d3;

System.out.println(“20% discount = “ + d2);

System.out.println(“10% discount = “ + d3);

System.out.println(“Amount after successive discounts = “ + amt2);

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 = ₹5000, Rate =10%, Time = 3 yrs


Sample Output: Interest for the first year: ₹500

Interest for the second year: ₹550

Interest for the third year: ₹605

Solution:

import java.util.Scanner;

public class CompoundInterest

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter sum of money: ");

double p = in.nextDouble();

double interest = p * 5 * 1 / 100.0;

System.out.println("Interest for the first year = " + interest);

p += interest;

interest = p * 5 * 1 / 100.0;

System.out.println("Interest for the second year = " + interest);

p += interest;

interest = p * 5 * 1 / 100.0;

System.out.println("Interest for the third year = " + interest);

}
}

You might also like