0% found this document useful (0 votes)
39 views41 pages

Final Computer Assignment Class IX

The document outlines a Class IX Computer Assignment consisting of multiple programming tasks, each with a description, source code, and variable listings. Assignments include calculating the product of digits in a 3-digit number, discount calculations for a travel company, electricity bill calculations, summing middle digits of 4-digit numbers, and validating date formats. Each assignment specifies completion and submission dates, along with detailed programming logic and examples.

Uploaded by

shuvamaysarkar11
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)
39 views41 pages

Final Computer Assignment Class IX

The document outlines a Class IX Computer Assignment consisting of multiple programming tasks, each with a description, source code, and variable listings. Assignments include calculating the product of digits in a 3-digit number, discount calculations for a travel company, electricity bill calculations, summing middle digits of 4-digit numbers, and validating date formats. Each assignment specifies completion and submission dates, along with detailed programming logic and examples.

Uploaded by

shuvamaysarkar11
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/ 41

Class IX Computer Assignment (Part 1)

Index Page
Assignment
Description Page No. Date Signature
No.
Product of
smallest and
1 largest digit in 2-5 29.7.2025
a 3-digit
number
ABC Travels
2 Discount 6-9 29.7.2025
Calculation
Electricity Bill
3 10 - 13 29.7.2025
Calculation
Sum of middle
digits of two
4 14 – 17 29.7.2025
4-digit
numbers
Date Validity
5 18 – 21 29.7.2025
Checker
Employee
6 Wage + 22 - 25 29.7.2025
Commission
Cookies Box
7 and Container 26 - 29 29.7.2025
Calculation
Special Two-
8 Digit Number 30 – 33 29.7.2025
Checker
Triangle
9 Validity and 34 – 37 29.7.2025
Type
Second
Smallest of
10 Three 38 - 41 29.7.2025
Unequal
Numbers

1 Class IX Computer Assignment (Part 1)


Assignment 1 :
Date of Completion : 05.06.2025
Submission Date : 29.7.2025
Program Description :
This program accepts a 3-digit number from the user and extracts each
digit using division and modulus operations. It then uses basic
arithmetic logic to identify the largest and smallest digits,
respectively. The final output is the product of these two digits. The
program includes input validation to ensure that the number entered is
exactly 3 digits long.
Source Code :

import java.util.* ;// importing Utility package ( Scanner Class included


inside )
class Assignment1
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in); // Create Scanner object for
input
System.out.print("Enter a 3-digit number: ");
int num = sc.nextInt();// Create Scanner object for input
if ( num < 100 || num > 999 )
System.out.println ( “ “ +num “ is not a 3 – digit number “);
else
{
// Extract digits
int a = num / 100;
int b = (num / 10) % 10;
int c = num % 10;

int max =0 , min =0 , prod = 1 ;


// Calculating Maximum digit of the number
if ( a > b && a > c )
max = a ;

2 Class IX Computer Assignment (Part 1)


else if ( b > a && b > c )
max = b ;
else
max = c ;

// Calculating Minimum digit of the number


if ( a < b && a < c )
min = a ;
else if ( b < a && b < c )
min = b ;
else
min = c ;

// Output product
prod = max * min ;
System.out.println("Product of largest and smallest digit: " + prod);
}
}
}

3 Class IX Computer Assignment (Part 1)


Output Screenshots :
➤Output Example 1:

➤Output Example 2:

4 Class IX Computer Assignment (Part 1)


Variable Listing :

Variable Name Data Type Scope Purpose


Accepts input
sc Scanner main method
from the user
Stores the 3-
digit number
num int main method
entered by the
user
Stores the
a int main method hundreds digit
of the number
Stores the tens
b int main method digit of the
number
Stores the units
c int main method digit of the
number
Stores the
largest digit
max int main method
among a, b, and
c
Stores the
smallest digit
min int main method
among a, b, and
c
Stores the
product of the
prod int main method
largest and
smallest digits

5 Class IX Computer Assignment (Part 1)


Assignment 2 :
Date of Completion : 05.06.2025
Submission Date : 29.7.2025
Program Description :

This program is used by ABC Travels Pvt. Ltd. to compute the discount
and net payable amount on a customer's ticket based on pre-defined
price slabs. It takes the name and ticket amount customers as input,
determines the applicable discount percentage, calculates the
discounted amount, and then displays the net amount to be paid by
them.
Source Code :

import java.util.Scanner; // importing Utility package ( Scanner Class


included inside )

class ABCTravelsPvtLtd
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

System.out.print("Enter Customer Name : ");


String ch = sc.next() ; // Entering the customer's name
System.out.print("Enter ticket amount: ");
double tAmt = sc.nextDouble();// Entering the customer's ticket
amount

double dis = 0.0 , netAmt = 0.0 ;


// Determine the appropriate discount rate based on the amount
if (tAmt > 70000)
dis =18.0/100;
else if (tAmt > 55000 && tAmt <= 70000)
dis = 16.0/100;
else if (tAmt > 35000 && tAmt <= 55000 )
dis = 12.0/100;
else if (tAmt > 25000&& tAmt <= 35000)
dis = 10.0/100;

6 Class IX Computer Assignment (Part 1)


else if (tAmt < 25000 && tAmt > 0)
dis = 2.0/100;
else
{
System.out.println(+tAmt + "is an invalid Ticket Amount" );
}

netAmt = tAmt - ( tAmt * dis );// Calculating Total amount to be


paid
// Display the result in tabular format
System.out.println("Name\tTicket Charges\tDiscount\tNet
Amount");
System.out.println(ch + "\t" + tAmt + "\t\t" + dis+ "\t\t" + netAmt);
}
}

7 Class IX Computer Assignment (Part 1)


Output Screenshots:

➤Output Example 1:

➤Output Example
e 2:

8 Class IX Computer Assignment (Part 1)


Variable Listing:

Variable Name Data Type Scope Purpose


Accepts input
sc Scanner main method
from the user
Stores the name
ch String main method
of customer
Stores the ticket
amount entered
tAmt double main method
for the
customer
Stores the
discount rate
dis double main method applicable
based on the
ticket amount
Stores the final
amount after
netAmt double main method
applying the
discount

9 Class IX Computer Assignment (Part 1)


Assignment 3 :
Date of Completion : 05.06.2025
Submission Date : 29.7.2025
Program Description :
This program is designed to solve the problem: Electricity Bill
Calculation. It takes user input using the Scanner class and calculates
the electricity bill according to the slab system and then adds 20%
Surcharge and 15.5% Govt.Tax to give the final amount to be paid by the
consumer for N number of consumers.
Source Code :

import java.util.*;

class ElectricityBill
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

System.out.print("Enter customer's name: ");


String ch = sc.next();
System.out.print("Enter number of units consumed: ");
double u = sc.nextDouble();
// Validate number of units
if (u < 0)
{
System.out.println("Invalid units consumed.Must be non-
negative.");
}
else
{
double amt = 0.0 , netAmt;

// Calculate base bill using slabs


if (u <= 50)
{
amt = 0.50 * u;
10 Class IX Computer Assignment (Part 1)
} else if (u > 50 && u <= 170)
{
amt = (0.50 * 50) + ((u - 50) * 0.85);
} else if (u > 170 && u <= 300)
{
amt = (0.50 * 50) + (0.85 * 120) + ((u - 170) * 1.20);
} else
{
amt = (0.50 * 50) + (0.85 * 120) + (1.20 * 130) + ((u - 300) *
1.75);
}
// Apply surcharge and government tax
netAmt = amt + (0.20 * amt) + (0.155 * amt);
// Display bill
System.out.println("\nName\tTotal Units\tTotal Amount");
System.out.println(ch + "\t" + u + "\t\t" + netAmt);
}
}
}

11 Class IX Computer Assignment (Part 1)


Output Screenshots:

➤Output Example 1:

➤Output Example 2:

12 Class IX Computer Assignment (Part 1)


Variable Listing :

Variable Name Data Type Scope Purpose


sc Scanner main method Accepts input
from the user
u int loop body Units consumed
by customer
ch String loop body Customer name
amt double loop body Amount before
tax
netAmt double loop body Final bill
amount after
surcharge and
tax

13 Class IX Computer Assignment (Part 1)


Assignment 4 :
Date of Completion : 05.06.2025
Submission Date : 29.7.2025
Program Description :
This program is designed to solve the problem: Sum of middle digits of
two 4-digit positive numbers. It takes user input using the Scanner class
and processes the data to give the sum of middle digits of the two 4-
digit positive number.
Source Code :

import java.util.*;

class Num
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

// Prompt the user


System.out.println("Enter 2 positive 4-digit numbers:");

// Input two integers


int a = sc.nextInt();
int b = sc.nextInt();

// Validate that both are 4-digit numbers


if (a < 1000 || a > 9999 || b < 1000 || b > 9999)
{
System.out.println("Invalid input! Please enter 4-digit numbers
only.");
}
else
{
// Extract middle digits of first number (hundreds and tens)
int k = (a / 10) % 10; // tens digit
int l = ((a / 10) / 10) % 10; // hundreds digit

14 Class IX Computer Assignment (Part 1)


// Extract middle digits of second number (hundreds and tens)
int m = (b / 10) % 10;
int n = ((b / 10) / 10) % 10;

// Form 2-digit numbers using middle digits


int num1 = (l * 10) + k;
int num2 = (n * 10) + m;

// Calculate sum of two 2-digit numbers


int sum = num1 + num2;

// Print result
System.out.println("Answer = " + sum);
}
}
}

15 Class IX Computer Assignment (Part 1)


Output Screenshots:
➤Output Example 1:

➤Output Example 2:

16 Class IX Computer Assignment (Part 1)


Variable Listing:

Variable Data
Scope Purpose
Name Type
main
sc Scanner To accept input from the user
method
main Stores the first 4-digit number
a int
method entered by the user
main Stores the second 4-digit number
b int
method entered by the user
main Extracts the tens digit of the first
k int
method number (a)
main Extracts the hundreds digit of the
l int
method first number (a)
main Extracts the tens digit of the
m int
method second number (b)
main Extracts the hundreds digit of the
n int
method second number (b)
main Forms a 2-digit number using l and
num1 int
method k (from a)
main Forms a 2-digit number using n
num2 int
method and m (from b)
Stores the final sum of num1 and
main
sum int num2, and displays it as the
method
answer

17 Class IX Computer Assignment (Part 1)


Assignment 5 :
Date of Completion : 05.06.2025
Submission Date : 29.7.2025
Program Description :
This program is designed to solve the problem: Date Validity Checker. It
takes user input using the Scanner class and processes the data to make
sure the date entered is valid according to (dd.mm.yyyy) format . It also
checks for the number of days in February in a leap year and makes
sure that the entered data is correct with respect to the above
informations for the given set of dates .
Source Code :

import java.util.Scanner;
class DateChecker
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

// Input the date


System.out.print("Enter day (dd): ");
int day = sc.nextInt();
System.out.print("Enter month (mm): ");
int month = sc.nextInt();
System.out.print("Enter year (yyyy): ");
int year = sc.nextInt();
boolean leap;
boolean valid = true;

// Separate logic to check leap year


if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
leap = true;
// Validate using leap year logic
if (month == 2)
{
if (day < 1 || day > 29)
valid = false;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (day < 1 || day > 30)

18 Class IX Computer Assignment (Part 1)


valid = false;
}
else if (month >= 1 && month <= 12)
{
if (day < 1 || day > 31)
valid = false;
}
else
{
valid = false;
}
}
else
{
leap = false;

// Validate using non-leap year logic


if (month == 2)
{
if (day < 1 || day > 28)
valid = false;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (day < 1 || day > 30)
valid = false;
}
else if (month >= 1 && month <= 12)
{
if (day < 1 || day > 31)
valid = false;
}
else
{
valid = false;
}
}

// Final output
if (valid == true )
System.out.println("Output: Valid date");
else
System.out.println("Output: Invalid date");
}
}

19 Class IX Computer Assignment (Part 1)


Output Screenshots:
➤Output Example 1:

➤Output Example 2:

20 Class IX Computer Assignment (Part 1)


Variable Listing :

Variable Data
Scope Purpose
Name Type
main Used to read user inputs (day,
sc Scanner
method month, year)
main
day int Stores the day entered by the user
method
main Stores the month entered by the
month int
method user
main Stores the year entered by the
year int
method user
main Holds true if year is a leap year,
leap boolean
method else false
main Flag used to track whether the
valid boolean
method input date is valid or invalid

21 Class IX Computer Assignment (Part 1)


Assignment 6 :
Date of Completion : 05.06.2025
Submission Date : 29.7.2025
Program Description :
This program is designed to solve the problem: Employee Wage +
Commission for SEM Consulting firm employees. It takes user input
using the Scanner class and in addition to the Basic Hourly Wage of
Rs 500 it also generates a commission according to the number of sales
and adds them to give the total wage of the employee.
Source Code :

import java.util.Scanner;

class WageCalculator
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

// Input employee name


System.out.print("Enter employee name: ");
String name = sc.nextLine();

// Input number of hours worked


System.out.print("Enter number of hours worked: ");
int h = sc.nextInt();

// Input total s
System.out.print("Enter total sales amount: ");
double s = sc.nextDouble();

double RPH = 500.0;


double comRate;

// Determine commission rate


if (s >= 100 && s < 1000)
{
comRate = 0.01; // 1%
22 Class IX Computer Assignment (Part 1)
}
else if (s >= 1000 && s < 10000)
{
comRate= 0.02; // 2%
}
else if (s >= 10000 && s < 25000)
{
comRate = 0.03; // 3%
}
else if (s >= 25000)
{
comRate = 0.035; // 3.5%
}
else
{
comRate = 0.0; // No commission
}

// Calculate basic wage and commission


double basicWage = h * RPH;
double commission = s * comRate;

// Calculate total wage


double totalWage = basicWage + commission;

// Output the final wage


System.out.println("\n--- Wage Summary ---");
System.out.println("Employee Name: " + name);
System.out.println("Basic Wage: ₹" + basicWage);
System.out.println("Commission Earned: ₹" + commission);
System.out.println("Total Wage: ₹" + totalWage);
}
}

23 Class IX Computer Assignment (Part 1)


Output Screenshots:
➤Output Example 1:

➤Output Example 2:

24 Class IX Computer Assignment (Part 1)


Variable Listing:

Variable Data
Scope Purpose
Name Type
main
sc Scanner Accepts input from the user
method
main
name String Stores the name of the employee
method
main Stores number of hours worked by
h int
method the employee
main Stores total sales amount made by
s double
method the employee
main Stores fixed wage rate (₹500 per
RPH double
method hour)
main Stores the commission percentage
comRate double
method based on sales slab
main Stores calculated basic wage
basicWage double
method (hours * ratePerHour)
main Stores commission earned (sales *
commission double
method commissionRate)
main Stores total wage (basicWage +
totalWage double
method commission)

25 Class IX Computer Assignment (Part 1)


Assignment 7 :
Date of Completion : 05.06.2025
Submission Date : 29.7.2025
Program Description
This program is designed to solve the problem: Cookies Box and
Container Calculation. It takes user input using the Scanner class and
then calculates the number of cookies in a box , the number of boxes
that can be kept in a container.
Source Code :

import java.util.Scanner;

class CookiesCalculation
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

// Input section
System.out.print("Enter total number of cookies: ");
int cookies = sc.nextInt();

System.out.print("Enter number of cookies per box: ");


int cookiesPerBox = sc.nextInt();

System.out.print("Enter number of boxes per container: ");


int boxesPerContainer = sc.nextInt();

// Validation
if (cookies <= 0 || cookiesPerBox <= 0 || boxesPerContainer <= 0)
{
System.out.println("Invalid input.");
}
else
{
// Calculate total number of boxes
int boxes = cookies / cookiesPerBox;

26 Class IX Computer Assignment (Part 1)


if (cookies % cookiesPerBox != 0)
{
boxes += 1; // one more for leftover cookies
}

// Calculate total number of containers


int containers = boxes / boxesPerContainer;
if (boxes % boxesPerContainer != 0)
{
containers += 1; // one more for leftover boxes
}

// Output
System.out.println("Number of boxes: " + boxes);
System.out.println("Number of containers: " + containers);
}
}
}

27 Class IX Computer Assignment (Part 1)


Output Screenshots:
➤Output Example 1:

➤Output Example 2:

28 Class IX Computer Assignment (Part 1)


Variable Listing:

Data
Variable Name Scope Purpose
Type
main Used to read input from the
sc Scanner
method user
main Stores the total number of
cookies int
method cookies entered by the user
Stores the number of cookies
main
cookiesPerBox int that can be packed into one
method
box
Stores the number of boxes
main
boxesPerContainer int that can be packed into one
method
container
main Stores the total number of
boxes int
method boxes required
main Stores the total number of
containers int
method containers required

29 Class IX Computer Assignment (Part 1)


Assignment 8 :
Date of Completion : 05.06.2025
Submission Date : 29.7.2025
Program Description :

This program is designed to solve the problem: Special Two-Digit


Number Checker. It takes user input using the Scanner class and
whether a given two-digit number is a special number. A number is
considered special if Sum of digits + Product of digits = Original number.
The program extracts digits, calculates sum and product, and then
verifies if the number is special.

Source Code :

import java.util.*; // Importing Scanner class from utility package

class SpecialNumber {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in); // Create Scanner object for


input

System.out.println("Enter a two-digit number:");

int n = sc.nextInt();

if (n > 99 || n < 10) {

System.out.println("Invalid input"); // Input must be two-digit

} else {

// Extract digits

int a = n % 10; // unit digit

int b = n / 10; // tens digit

int sum = a + b; // sum of digits

30 Class IX Computer Assignment (Part 1)


int prod = a * b; // product of digits

int result = sum + prod; // total

if (result == n) {

System.out.println(n + " is a special two-digit number");

} else {

System.out.println(n + " is not a special two-digit number");

31 Class IX Computer Assignment (Part 1)


Output Screenshots:

➤Output Example 1:

➤Output Example 2:

32 Class IX Computer Assignment (Part 1)


Variable Listing:

Variable Name Data Type Scope Purpose


Accepts input
sc Scanner main method
from the user
Stores the two-
n int main method
digit number
a int main method Unit digit
b int main method Tens digit
Sum of the
sum int main method
digits
Product of the
prod int main method
digits
Sum of sum and
product to
result int main method
compare with
input

33 Class IX Computer Assignment (Part 1)


Assignment 9 :
Date of Completion : 05.06.2025
Submission Date : 29.7.2025
Program Description :

This program takes three side lengths as input and first checks if they
can form a valid triangle using the triangle inequality theorem:The sum
of any two sides must be greater than the third.
If a triangle can be formed, it then classifies the triangle as:

 Equilateral: all sides equal


 Isosceles: any two sides equal
 Scalene: all sides different

Source Code :

import java.util.Scanner; // Import Scanner class

public class TriangleSideChecker


{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in); // Create Scanner object for
input

// Input the three sides of the triangle


System.out.print("Enter first side: ");
int a = sc.nextInt();

System.out.print("Enter second side: ");


int b = sc.nextInt();

System.out.print("Enter third side: ");


int c = sc.nextInt();

34 Class IX Computer Assignment (Part 1)


// Step 1: Check if a triangle can be formed using Triangle
Inequality Theorem
if (a <= 0 || b <= 0 || c <= 0)
{
System.out.println("Sides must be positive.");
} else if ((a + b > c) && (a + c > b) && (b + c > a)) {
System.out.println("Triangle can be formed.");

// Step 2: Check the type of triangle


if (a == b && b == c && c == a)
{
System.out.println("It is an Equilateral triangle.");
}
else if (a == b || b == c || a == c)
{
System.out.println("It is an Isosceles triangle.");
}
else
{
System.out.println("It is a Scalene triangle.");
}
}
else
{
System.out.println("Triangle cannot be formed with the given
sides.");
}
}
}

35 Class IX Computer Assignment (Part 1)


Output Screenshots:

➤Output Example 1:

➤Output Example 2:

➤Output Example 3 :

36 Class IX Computer Assignment (Part 1)


Variable Listing:

Variable Name Data Type Scope Purpose


Used to read
sc Scanner main method input from the
user
Stores the first
a int main method side of the
triangle
Stores the
b int main method second side of
the triangle
Stores the third
c int main method side of the
triangle

37 Class IX Computer Assignment (Part 1)


Assignment 10 :
Date of Completion : 05.06.2025
Submission Date : 29.7.2025
Program Description :

This program takes three unequal positive numbers as input and


determines the second smallest number. It uses basic arithmetic logic
to efficiently identify the second smallest value among the three
numbers. Input validation ensures all three numbers are positive and
not equal to each other.
Source Code :

import java.util.Scanner;

public class SecondSmallestNumberChecker


{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

// Input three numbers


System.out.print("Enter first number: ");
int a = sc.nextInt();

System.out.print("Enter second number: ");


int b = sc.nextInt();

System.out.print("Enter third number: ");


int c = sc.nextInt();

// Check if all numbers are positive and unequal


if (a <= 0 || b <= 0 || c <= 0)
{
System.out.println("All numbers must be positive.");
}
else if (a == b || b == c || a == c)
{

38 Class IX Computer Assignment (Part 1)


System.out.println("All numbers must be different.");
}
else
{
int secondSmallest;

// Compare to find second smallest


if ((a > b && a < c) || (a > c && a < b))
{
secondSmallest = a;
}
else if ((b > a && b < c) || (b > c && b < a))
{
secondSmallest = b;
}
else
{
secondSmallest = c;
}

// Output the second smallest number


System.out.println("The second smallest number is: " +
secondSmallest);
}
}
}

39 Class IX Computer Assignment (Part 1)


Output Screenshots:
➤Output Example 1:

➤Output Example 2:

➤Output Example 3::

40 Class IX Computer Assignment (Part 1)


Variable Listing:

Variable Name Data Type Scope Purpose


Accepts input
sc Scanner main method
from the user
a int main method First number
b int main method Second number
c int main method Third number
Stores the
secondSmallest int main method second smallest
value

41 Class IX Computer Assignment (Part 1)

You might also like