0% found this document useful (0 votes)
6 views27 pages

Computer Programming Projects for Grade 9

This document is a computer application project by Daksh Upreti, a 9th-grade student, which includes various programming exercises and their implementations in Java. The project covers topics such as arithmetic operations, simple interest calculation, and triangle area computation, among others. It also contains acknowledgments and variable description tables for each program.

Uploaded by

dakshupreti16
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)
6 views27 pages

Computer Programming Projects for Grade 9

This document is a computer application project by Daksh Upreti, a 9th-grade student, which includes various programming exercises and their implementations in Java. The project covers topics such as arithmetic operations, simple interest calculation, and triangle area computation, among others. It also contains acknowledgments and variable description tables for each program.

Uploaded by

dakshupreti16
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

Computer Application

Project AY 25-26

Daksh Upreti
Grade: 9
Section: H

1
Acknowledgement
I would like to express my special thanks of
gratitude to my computer teacher, Ms. Haritha,
for her able guidance and support in completing
my project. She has taken great pains to make us
understand the concepts and has always been
ready to help.
I would also like to thank my parents and friends
who helped me a lot in finalizing this project
within the limited time frame.

2
Index
Page Number Question
1 Write a program to initialize fractional
numbers 7.6, 3.2, 6.4. Print the sum and
product of the numbers.
3 Write a program to print the quotient and
remainder of integer 187 by integer 13.
5 Write a program to assign integers a, b, c with
values 3, 6, 9. Perform the operations and
print the results of the operations:
S=(a+b+c)/2 and V=(a²+b²)/c³
7 Write a program to accept Principal
amount(P), rate of interest (R) and Time (T)
through parameterized method. Calculate and
print the Simple Interest.
9 Write a program to accept values for variables
a and b through parameterized method. Swap
their values using a third variable. Display the
values after swapping.
11 Write a program to initialize a three-digit
number of a long integer type. Print the sum
and product of first and last digits of that
number.
13 Create a class Student_Info to input (Scanner
method) marks in English, Maths, Physics,
Chemistry, Biology, Computer Applications.
Print the marks obtained in all the subjects,
total marks and percentage. (Assume that the
maximum mark in each subject is 100)
15 Write a program to input three sides of a
triangle (Scanner method). Print the area of
the triangle using the given formula. The class
name is Triangle. (Area= √s(s-a)(s-b)(s-c))
17 Write a program to which inputs two integers
num1, num2 and operator, that contains an
arithmetic operator ('+', '-', '/', '*') only.
Perform and print the corresponding
operation on n1 and n2 on the basis of the
operator using the switch-case or user's

3
choice statement.
20 An XYZ mall has announced the festive
discounts on the purchase of items based on
the total cost of items as per the given
criteria. Write a program to input the name of
the customer, total cost of purchase, type of
the purchase (H for Home Appliances and F
for Furniture) using Scanner class. Compute
and display the amount to be paid by the
customer after availing the discount in the
following format: Name, Cost of the Purchase,
Discount (in Rs), Net Amount(in Rs.)

4
Program-01

Write a program to initialize fractional numbers 7.6, 3.2, 6.4. Print the sum and product of the
numbers.
public class pgm
{
public static void main(String[] args)
{
//initialize 1st number
double num1=7.6;
//initialize 2nd number
double num2=3.2;
//initialize 3rd number
double num3=6.4;
//calculate sum and product of the numbers
double sum=num1+num2+num3;
double product=num1*num2*num3;
[Link]("The sum is: "+sum);
[Link]("The product is:"+product);
}
}

1
Output

Variable Description Table


| Variable Name | Data Type | Variable Description |
| num1 | double | Stores the first number. |
| num2 | double | Stores the second number. |
| num3 | double | Stores the third number. |
| sum | double | Stores the sum of the three numbers. |
| product | double | Stores the product of the three numbers. |

2
Program-02

Write a program to print the quotient and remainder of integer 187 by integer 13.
public class pgm
{
public static void main (String[] args)
{
//initialize 1st number
int num1=187;
//initialize 2nd number
int num2=13;
//calculate quotient and remainders of the numbers
double quotient=num1/num2;
double remainder=num1%num2;
//print the values
[Link]("The quotient is: "+quotient);
[Link]("The remainder is:"+remainder);
}
}

3
Output

Variable Description Table


| Variable Name | Data Type | Variable Description |
| num1 | int | Stores the dividend. |
| num2 | int | Stores the divisor. |
| quotient | double | Stores the result of the division. |
| remainder | double | Stores the remainder of the division. |

4
Program-03

Write a program to assign integers a, b, c with values 3, 6, 9. Perform the operations and print
the results of the operations: S=(a+b+c)/2 and V=(a²+b²)/c³
public class pgm2
{
public static void main (String[] args)
{
//initialize 1st number
int a=3;
//initialize 2nd number
int b=6;
//initialize 3rd number
int c=9;
double s=(a+b+c)/2;
double v=([Link](a,2)+[Link](b,2))/[Link](c,3);
//print the values
[Link]("S= "+s);
[Link]("V= "+v);
}
}

5
Output

Variable Description Table


| Variable Name | Data Type | Variable Description |
|a | int | Stores the first integer value. |
|b | int | Stores the second integer value. |
|c | int | Stores the third integer value. |
|s | double | Stores the result of the first operation. |
|v | double | Stores the result of the second operation. |

6
Program-04

Write a program to accept Principal amount(P), rate of interest (R) and Time (T) through
parameterized method. Calculate and print the Simple Interest.
public class pgm4
{
public static void main (int p, int r, int t)
{
//Display the principal
[Link]("The principal is:"+p);
//Display the rate of interest
[Link]("The rate of interest is: "+r);
//Display time
[Link]("The time is: "+t);
//find simple interest
double SI=(p*r*t)/100;
[Link]("The simple interest is"+SI);
}
}

7
Output

Variable Description Table


| Variable Name | Data Type | Variable Description |
|p | int | Stores the principal amount. |
|r | int | Stores the rate of interest. |
|t | int | Stores the time period. |
| SI | double | Stores the calculated simple interest. |

8
Program-05

Write a program to accept values for variables a and b through parameterized method. Swap
their values using a third variable. Display the values after swapping.
public class pgm5
{
public static void swap(int n1, int n2)
{
//print numbers before swapping
[Link]("Before Swapping:n1="+n1+",n2="+n2);
// initialize temp and assign it a value
int temp=n1;
//swap numbers
n1=n2;
n2=temp;
//print output
[Link]("After swapping:n1="+n1+",n2="+n2);
}
}

9
Output

Variable Description Table


| Variable Name | Data Type | Variable Description |
| n1 | int | Stores the first number to be swapped. |
| n2 | int | Stores the second number to be swapped. |
| temp | int | A temporary variable to aid in swapping. |

10
Program-06

Write a program to initialize a three-digit number of a long integer type. Print the sum and
product of first and last digits of that number.
import [Link].*;
public class pgm6
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
//initialize a, firstdigit and lastdigit
long a, firstdigit, lastdigit;
[Link]("The number is: ");
a=[Link]();
//find first digit
firstdigit=a/100;
//find last digit
lastdigit=a%10;
//print output
[Link]("The first digit of the number is: "+firstdigit);
[Link]("The last digit of the number is: "+lastdigit);
}
}

11
Output

Variable Description Table


| Variable Name | Data Type | Variable Description |
|a | long | Stores the three-digit number entered by the user. |
| firstdigit | long | Stores the first digit of the number. |
| lastdigit | long | Stores the last digit of the number. |

12
Program-07

Create a class Student_Info to input (Scanner method) marks in English, Maths, Physics,
Chemistry, Biology, Computer Applications. Print the marks obtained in all the subjects, total
marks and percentage. (Assume that the maximum mark in each subject is 100)

import [Link].*;
public class Student_info
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
// Declare variables to store marks in each subject and overall totals
double English, Maths, Physics, Chemistry, Biology, Computerapp, total, percentage;
// Input marks for each subject
[Link]("Enter marks in English: ");
English=[Link]();
[Link]("Enter marks Maths: ");
Maths=[Link]();
[Link]("Enter marks in Physics: ");
Physics=[Link]();
[Link]("Enter marks in Chemistry: ");
Chemistry=[Link]();
[Link]("Enter marks in Biology: ");
Biology=[Link]();
[Link]("Enter marks in Computer applications: ");
Computerapp=[Link]();
// Calculate total marks and percentage
total=English+Maths+Physics+Chemistry+Biology+Computerapp;
percentage=total/600.0*100.0;
// Display the results
[Link]("The total marks scored are: "+total);
[Link]("The Percentage secured is: "+percentage);
}
}

13
Output

Variable Description Table


| Variable Name | Data Type | Variable Description |
| English | double | Stores the marks obtained in English. |
| Maths | double | Stores the marks obtained in Maths. |
| Physics | double | Stores the marks obtained in Physics. |
| Chemistry | double | Stores the marks obtained in Chemistry. |
| Biology | double | Stores the marks obtained in Biology. |
| Computerapp | double | Stores the marks obtained in Computer Applications. |
| total | double | Stores the total marks of all subjects. |
| percentage | double | Stores the overall percentage. |

14
Program-08

Write a program to input three sides of a triangle (Scanner method). Print the area of the
triangle using the given formula. The class name is Triangle. (Area= √s(s-a)(s-b)(s-c))

import [Link].*;
public class Triangle
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
// Declare variables for three sides of the triangle, semi-perimeter, and area
double a, b, c, s, area;
// Take input for the three sides of the triangle
[Link]("The 1st side is: ");
a=[Link]();
[Link]("The 2nd side is: ");
b=[Link]();
[Link]("The 3rd side is: ");
c=[Link]();
// Calculate semi-perimeter (s) and then area using Heron's formula
s=(a+b+c)/2.0;
area=[Link](s*(s-a)*(s-b)*(s-c));
// Check if the sides form triangle, print accordingly
if(a+b<=c||b+c<=a||c+a<=b)
[Link]("The sides entered can not form a triangle, please try again");
else
[Link]("The area of the triangle is: "+area);
}
}

15
Output

Variable Description Table


| Variable Name | Data Type | Variable Description |
| :--- | :--- | :--- |
| a | double | Stores the length of the first side of the triangle. |
| b | double | Stores the length of the second side of the triangle. |
| c | double | Stores the length of the third side of the triangle. |
| s | double | Stores the semi-perimeter of the triangle. |
| area | double | Stores the calculated area of the triangle. |

16
Program-09
Write a program to which inputs two integers num1, num2 and operator, that contains an
arithmetic operator ('+', '-', '/', '*') only. Perform and print the corresponding operation on n1
and n2 on the basis of the operator using the switch-case or user's choice statement.

import [Link].*;
public class pgm9
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
// Declare variables for two numbers, user choice, and results of operations
int n1, n2, choice, add, sub, divide, multiply;
// Take input of two integers
[Link]("Enter n1 and n2");
n1=[Link]();
n2=[Link]();
// display the menu for the user to choose
[Link]("MENU");
[Link]("1.+");
[Link]("2.-");
[Link]("3./");
[Link]("4.*");
choice=[Link]();
// Use switch-case to perform operations
switch(choice)
{
case 1:
add=n1+n2;
[Link]("The sum is: "+add);
break;
case 2:
if(n1>=n2)
{sub=n1-n2;}
else
{sub=n2-n1;}
[Link]("The difference is: "+sub);
break;
case 3:

17
if(n1>=n2)
{divide=n1/n2;}
else
{divide=n2/n1;}
[Link]("The quotient is: "+divide);
break;
case 4:
multiply=n1*n2;
[Link]("The product is: "+multiply);
break;
default:
[Link]("error, please try again");
}
}
}

18
Output

Variable Description Table


| Variable Name | Data Type | Variable Description |
| n1 | int | Stores the first integer. |
| n2 | int | Stores the second integer. |
| choice | int | Stores the user's choice of operation. |
| add | int | Stores the sum of n1 and n2. |
| sub | int | Stores the difference between n1 and n2. |
| divide | int | Stores the quotient of n1 and n2. |
| multiply | int | Stores the product of n1 and n2. |

19
Program-10

An XYZ mall has announced the festive discounts on the purchase of items based on the total
cost of items as per the given criteria. Write a program to input the name of the customer,
total cost of purchase, type of the purchase (H for Home Appliances and F for Furniture)
using Scanner class. Compute and display the amount to be paid by the customer after
availing the discount in the following format: Name, Cost of the Purchase, Discount (in Rs),
Net Amount(in Rs.)
import [Link].*;
public class pgm10
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
// Declare variables
String name;
double cost,disc, amount;
int choice;
//ask for name
[Link]("Name: ");
name=[Link]();
//display a menu
[Link]("MENU");
[Link]("1.H");
[Link]("2.F");
choice=[Link]();
//solve for each choice of user
switch(choice)
{
case 1:
[Link]("Cost of the purchase: ");
cost=[Link]();
if(cost<25000)
{
disc=5.0/100.0;
amount=cost-(cost*disc);
[Link]("Discount(in Rs): 5%\\tAmount(in Rs.): "+amount);
}
else if(cost>=25001&&cost<=30000)
{
disc=7.0/100.0;

20
amount=cost-(cost*disc);
[Link]("Discount(in Rs): 7%\\tAmount(in Rs.): "+amount);
}
else if(cost>=30001&&cost<=45000)
{
disc=10.0/100.0;
amount=cost-(cost*disc);
[Link]("Discount(in Rs): 10%\\tAmount(in Rs.): "+amount);
}
else if(cost>=45001)
{
disc=14.0/100.0;
amount=cost-(cost*disc);
[Link]("Discount(in Rs): 14%\\tAmount(in Rs.): "+amount);
}
break;
case 2:
[Link]("Cost of the purchase: ");
cost=[Link]();
if(cost<25000)
{
disc=7.0/100.0;
amount=cost-(cost*disc);
[Link]("Discount(in Rs): 7%\\tAmount(in Rs.): "+amount);
}
else if(cost>=25001&&cost<=30000)
{
disc=10.0/100.0;
amount=cost-(cost*disc);
[Link]("Discount(in Rs): 10%\\tAmount(in Rs.)"+amount);
}
else if(cost>=30001&&cost<=45000)
{
disc=13.0/100.0;
amount=cost-(cost*disc);
[Link]("Discount(in Rs): 13%\\tAmount(in Rs.)"+amount);
}
else if(cost>=45001)
{
disc=16.0/100.0;
amount=cost-(cost*disc);

21
[Link]("Discount(in Rs): 16%\\tAmount(in Rs.)"+amount);
}
break;
default:
[Link]("Invalid option, try again");
}
}
}

22
Output

Variable Description Table


| Variable Name | Data Type | Variable Description |
| name | String | Stores the name of the customer. |
| cost | double | Stores the total cost of the purchase. |
| disc | double | Stores the discount percentage. |
| amount | double | Stores the final amount to be paid after discount. |
| choice | int | Stores the user's choice of purchase type. |

23

You might also like