[go: up one dir, main page]

0% found this document useful (0 votes)
10 views29 pages

Comp Project 11

The document is a computer science project by Reeti Kumari, focusing on Java programming. It includes an introduction to Java, key features, and practical programming assignments covering various topics such as calculating greatest numbers, leap years, HCF and LCM, and temperature conversions. The document serves as a comprehensive guide for beginners to understand Java and its applications through practical examples.
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)
10 views29 pages

Comp Project 11

The document is a computer science project by Reeti Kumari, focusing on Java programming. It includes an introduction to Java, key features, and practical programming assignments covering various topics such as calculating greatest numbers, leap years, HCF and LCM, and temperature conversions. The document serves as a comprehensive guide for beginners to understand Java and its applications through practical examples.
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/ 29

glish Medium

En
p Sc
lo

ho
n
Du

ol
Computer Science Project &
Practical

Name : Reeti Kumari.


Class : XI(Commerce).
Roll No. :
Index

Sl. No. Topic Page No.

1. Introduction To JAVA Programming 1-5


WAP to display the greatest of three numbers using
2. input
6-7
WAP to check whether a given year is a Leap Year
3. or not
8-9

WAP to input two numbers and display their HCF


4. 10-11
and LCM
WAP to find the sum of 'n' terms: S = 2 + 5 + 10 + ...
5. 12-13
to n terms

6. LG Product Discount Calculation (Microwave, 14-16


AC, Television)

7. WAP to calculate and display the difference between 17-18


Compound & Simple Interest

8. WAP to enter three unequal numbers and display the 19-20


second greatest number

9. WAP to convert temperature between Celsius, Fahrenheit, 21-24


and Kelvin

10. WAP to find the sum of the series: a - a²/2! + a³/3! - a⁴/4! + 25-27
... + aⁿ/n!
Introduction To Java Programming

Java is one of the most widely used


programming languages in the world today.
It was developed by James Gosling and his
team at Sun Microsystems in 1995 and is
now maintained by Oracle Corporation.
Java was designed with the philosophy of
"Write Once, Run Anywhere" (WORA) —
meaning that Java programs can run on
any system that has a Java Virtual
Machine (JVM), regardless of the
underlying hardware and operating system.

Java is a general-purpose, object-oriented,


class-based, and high-level language that
has built-in tools for memory management,
security, and error handling. Its structure
and syntax are influenced by C and C++,
but Java removes many of the complexities
of those languages, making it more
beginner-friendly and less error-prone.
Why Learn Java?
Java is not only a language but a complete
platform. It’s used in a wide variety of
applications:
Desktop applications
Web-based applications
Android apps
Enterprise-level software
Embedded systems
Scientific and research applications
Its stability, reliability, and community
support have made it a preferred language
for millions of developers and companies
worldwide.

Key Features of Java:


Platform Independent: Java programs
are compiled into bytecode that can be
executed on any device with a JVM.
Object-Oriented: Java follows the
object-oriented programming paradigm,
which makes the code reusable,
scalable, and easier to manage.
Simple and Familiar: Java’s syntax is
similar to C++, but it eliminates
complex features like pointers and
operator overloading.
Secure: Java provides a secure
environment by eliminating common
programming errors and managing
memory automatically.
Robust: Java has strong memory
management and built-in exception
handling.
Multithreaded: Java supports
multithreading, allowing multiple
threads to run concurrently, making
programs faster and more efficient.
Distributed: Java allows developers to
create applications that can be run on
multiple computers connected to a
network.
Portable: Java programs can run on
any platform without needing to be
rewritten or recompiled.
Understanding Java Development Process:
The development process in Java involves
three key steps:
Writing the Code: A developer writes
Java code in a .java file using an editor
or IDE.
Compiling the Code: The Java compiler
(javac) converts the source code into
bytecode (.class files).
Executing the Program: The JVM
interprets or compiles this bytecode and
runs the program.
Structure of a Basic Java Application:
A Java program typically consists of
classes and methods. The main() method is
the entry point from where execution
begins. Java uses packages, classes,
methods, variables, and control structures
to build logic and functionality.
Applications of Java in the Real World:
Android app development (using Java
or Kotlin)
Enterprise software like banking and
insurance systems
Server-side technologies (Servlets, JSP)
Big Data technologies like Apache
Hadoop
Embedded systems in smartcards,
sensors, etc.
Conclusion:
Learning Java is an essential step for any
aspiring programmer or computer science
student. Its simplicity, vast library of built-
in classes, and strong community support
make it an ideal choice for both beginners
and advanced developers. Understanding
Java’s core concepts is crucial for
developing efficient, scalable, and secure
applications. This introduction sets the
foundation for exploring Java programming
in more depth through practical examples
and projects.
Q2. WAP in JAVA to display the greatest of
three numbers using input statement.
Program:
import java.util.Scanner;
public class GreatestOfThree
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Three Numbers : ");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int max=0;
if(a>b)
{
if(a>c)
{
max=max+a;
}
}
else if(b>a)
{
if(b>c)
{
max=max+b;
}
}
else
{
max=max+c;
}
System.out.println("Greatest Number Is: " + max);
}
}

Output:

Variable Description Table:

Variable Data Type Description

a int First number input by user

b int Second number input by user

c int Third number input by user

Stores the greatest among a,


max int
b, and c
Q3. WAP in JAVA to check whether a given
year is a Leap Year or not.
Program:
import java.util.Scanner;
public class LeapYear
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter A Year : ");
int year = sc.nextInt();
if ((year%4==0 && year%100!=0) || year%400==0)
{
System.out.println(year + " Is A Leap Year");
}
else
{
System.out.println(year + " Is Not A Leap Year");
}
}
}

Output:
Variable Description Table:

Variable Data Type Description

year int Year entered by the user

Stores whether the year is


isLeap boolean
leap or not
Q4. WAP in JAVA to input two numbers and
display their HCF and LCM.
Program:
import java.util.Scanner;
public class HCF_LCM
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Two Numbers : ");
int a = sc.nextInt();
int b = sc.nextInt();
int hcf = 1;
int min = Math.min(a,b);
for (int i=1;i<=min;i++)
{
if (a%i==0 && b%i==0)
{
hcf = i;
}
}
int lcm = (a * b)/hcf;
System.out.println("HCF = " + hcf);
System.out.println("LCM = " + lcm);
}
}
Output:

Variable Description Table:


Variable Data Type Description

x int First input number

y int Second input number

Highest Common Factor of x


hcf int
and y

Least Common Multiple of x


lcm int
and y

i int Loop control variable


Q5. WAP in JAVA to find the sum of 'n'
terms from the console.
S = 2 + 5 + 10 + ........... to n terms.
Program:
import java.util.Scanner;
public class SeriesSum
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number Of Terms (n) : ");
int n = sc.nextInt();
int sum = 0;
for (int i=1;i<=n;i++)
{
sum+=i*i+1;
}
System.out.println("Sum = " + sum);
}
}

Output:
Variable Description Table:
Variable Data Type Description

Number of terms entered by


n int
user

Stores the cumulative sum of


sum int
the series

i int Loop control variable

Individual term value of the


term int
series
Q6. LG product discount to be displayed on
total:
Microwave Oven - 10%
Air Conditioner - 12%
Television - 15%
(Amount of the product will be entered by
user - then display the total after discount)
Program:
import java.util.Scanner;
public class LGDiscount
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Product Name (Microwave / AC
/ Television) : ");
String product = sc.nextLine();
System.out.println("Enter Price : ");
double price = sc.nextDouble();
double discount = 0;
product=product.toLowerCase();
switch (product)
{
case "microwave":
discount = 0.10;
break;
case "ac":
discount = 0.12;
break;
case "television":
discount = 0.15;
break;
default:
System.out.println("Invalid Product");
return;
}
double discountedPrice = price - (price * discount);
System.out.println("Price After Discount = ₹" +
discountedPrice);
}
}

Output:
Variable Description Table:
Variable Data Type Description

Name of the product entered


product String
by the user

amt double Marked price of the product

Discount rate based on


discount double
product

total double Price after applying discount


Q7. WAP in JAVA to calculate and display the
difference between compound interest and
simple interest.
(Principal amount, rate of interest, time
period will be entered by user)
Program:
import java.util.Scanner;
public class InterestDifference
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Principal : ");
double p = sc.nextDouble();
System.out.println("Enter Rate(%) : ");
double r = sc.nextDouble();
System.out.println("Enter Time(Years) : ");
double t = sc.nextDouble();
double si = (p*r*t)/100;
double ci = p*Math.pow((1+r/100),t)-p;
double diff = ci-si;
System.out.println("Simple Interest = " + si);
System.out.println("Compound Interest = " + ci);
System.out.println("Difference = " + diff);
}
}
Output:

Variable Description Table:


Variable Data Type Description

Principal amount entered by


p double
the user

Rate of interest entered by


r double
user

t double Time period in years

Simple Interest calculated


si double
using formula

Compound Interest
ci double
calculated using formula

diff double Difference between CI and SI


Q8. WAP in JAVA to enter three unequal
numbers and display the second greatest
number.
Program:
import java.util.Scanner;
public class SecondGreatest
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Three Unequal Numbers : ");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int second;
if ((a>b&&a<c) || (a<b&&a>c))
{
second = a;
}
else if ((b>a&&b<c) || (b<a&&b>c))
{
second = b;
}
else
{
second = c;
}
System.out.println("Second Greatest = " + second);
}
}
Output:

Variable Description Table:


Variable Data Type Description

a int First number

b int Second number

c int Third number

Stores the second greatest


second int
number among the three
Q9. WAP in JAVA to convert and display
temperature from °C to °F and K or °F to °C
and K or K to °C and °F
(based on user’s choice)
°C to °F: F = 9C/5 + 32
°F to °C: C = (F - 32) * 5/9
K = C + 273
Program:
import java.util.Scanner;
public class TempConverter
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Convert From : \n1. Celsius \n2.
Fahrenheit \n3. Kelvin");
int choice = sc.nextInt();
System.out.println("Enter Temperature : ");
double temp = sc.nextDouble();
double C, F, K;
switch (choice)
{
case 1:
C = temp;
F = (9*C/5)+32;
K = C+273;
break;
case 2:
F = temp;
C = (F-32)*5/9;
K = C+273;
break;
case 3:
K = temp;
C = K-273;
F = (9*C/5)+32;
break;
default:
System.out.println("Invalid Choice");
return;
}
System.out.println("Celsius : " + C);
System.out.println("Fahrenheit : " + F);
System.out.println("Kelvin : " + K);
}
}

Output:
Variable Description Table:

Variable Data Type Description

User's menu selection (1: °C, 2:


choice int
°F, 3: K)

Input temperature entered by


temp double
user

C double Temperature in Celsius

F double Temperature in Fahrenheit

K double Temperature in Kelvin


Q10. WAP in JAVA to find the sum of the
given series after accepting a and n from the
console.

Program:
import java.util.Scanner;
public class SeriesAdvanced
{
static int factorial(int n)
{
int f = 1;
for (int i = 2; i <= n; i++)
{
f *= i;
}
return f;
}
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Value Of a And n: ");
double a = sc.nextDouble();
int n = sc.nextInt();
double sum = 0;
for (int i=1;i<=n;i++)
{
double term = Math.pow(a, i) / factorial(i);
if(i%2==0)
{
sum+=(-term);
}
else
{
sum+=term;
}
}
sum+=a;
System.out.println("Sum Of The Series = " + sum);
}
}

Output:
Variable Description Table:
Variable Data Type Description

a double Base value entered by user

Number of terms entered by


n int
user

sum double Accumulates the series result

i int Loop variable for term index

term double Stores each individual term

Calculates factorial of a
factorial() method
number

You might also like