Computer - Project 1 (1) Isc
Computer - Project 1 (1) Isc
A) Algorithm:
import java.util.Scanner;
D) Terminal Window:
A) Algorithm:
import java.util.Scanner;
if (number % 2 == 0) {
System.out.println("Sum of square and square root: " +
(number * number + Math.sqrt(number)));
} else {
System.out.println("Square: " + number * number);
System.out.println("Cube: " + number * number * number);
}
}
}
C) Variable Description:
D) Terminal window:
A) Algorithm:
import java.util.Scanner;
A) Algorithm:
import java.util.Scanner;
A) Algorithm:
import java.util.Scanner;
scanner.close();
}
}
C) Variable Description:
A) Algorithm:
1. Accept three numbers. Check if all numbers are single digit numbers or
not. If yes, then continue, else end the program stating invalid number.
2. Generate combinations using nested loops:
- Loop through each digit (d1, d2, d3) for the hundreds place.
- Loop through remaining digits for the tens place.
- Loop through remaining digit for the ones place.
3. Print each generated combination.
B) Program:
import java.util.Scanner;
public class DigitPermutations {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
A) Algorithm:
1. Accept a number.
2. Initialize count = 0 and num = 2.
3. While count < n:
a. Check if num is prime using IsPrime() function.
b. If num is prime:
i. Print num.
ii. Increment count.
c. Increment num.
4. End.
C) Program:
import java.util.Scanner;
public class PrimeNumbers {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of prime numbers:");
int n = scanner.nextInt();
int count = 0;
int num = 2;
System.out.println("Prime numbers:");
while (count < n) {
if (isPrime(num)) {
System.out.println(num); count+
+;
}
num++;
}
scanner.close();
}
public static boolean isPrime(int num) {
if (num <= 1) return false;
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) return false;
}
return true;
}
}
C) Variable Description:
D) Terminal Window:
A) Algorithm:
1. Accept a number n.
2. Initialize i = 1.
3. While i ≤ n:
a. Initialize sum = 0 and j = 1.
b. While j ≤ i:
i. Print j.
ii. If j < i, print "+".
iii. sum += j.
iv. j++.
c. Print " = " and sum.
d. i++.
B) Program:
import java.util.Scanner;
// Validate
input if (n <=
0) {
System.out.println("Invalid input. Please enter a positive integer.");
return;
}
System.out.println("Sum Series:");
printSeries(n);
printSeries(n, true);
scanner.close();
}
C) Variable Description:
Variable Datatype Description
n int To store value of n
i int Loop variable
j int Loop variable
D) Terminal window:
Enter a number:
2
1
1+2
Sum=3
9) Write a program in Java to input two numbers m and n. Find
and print: s=𝑚 !(𝑛𝑛−! 𝑚)!. Use a method that accepts
numbers and return its factorial.
A) Algorithm:
B) Program:
import java.util.Scanner;
public class FactorialExpression {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the value of m:");
int m = scanner.nextInt();
System.out.println("Enter the value of n:");
int n = scanner.nextInt();
// Validate input
if (m < 0 || n < 0) {
System.out.println("Invalid input. Please enter non-negative
integers.");
return;
}
long result = calculateExpression(m, n);
System.out.println("s = " + result);
scanner.close();
}
// Method to calculate the expression
public static long calculateExpression(int m, int n) {
return factorial(m) / (factorial(n - 1) * factorial(m));
}
// Method to calculate factorial
public static long factorial(int num) {
long fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
return fact;
}
}
C) Variable Description:
A) Algorithm:
C) Variable Description:
Variable Data Type Description
a float Coefficient of x^2
term
b float Coefficient of x term
c float Constant term
d float Discriminant
(b^2 - 4ac)
x1 double Root 1 of the quadratic
equation
x2 double Root 2 of the
quadratic equation
D) Terminal Window:
Quadratic Equation:
1.0x^2 + -5.0x + 6.0 = 0
Real and distinct roots:
2.0, 3.0
11) Class name: Discount
Data Members:
Int cost – to store the list price of the article
String name – to store name
Double dc – to store discount
Double amt – to store amount to be paid
Member Functions:
Void input()- to accept name of the customer and cost of the article
purchased
Void cal()- to calculate the discount and the amount
Void display()- to display the name of the customer, cost, discount
and amount to be paid .
Write a program to compute the discount according to given conditions
and displays the output as per given format:
List price Rate of
Discount
Upto ₨ 5000 no discount
From ₨ 5001 to ₨ 10000 10% on list
price
From ₨ 10001 to ₨15000 15% on list
price
Above ₨15000 20% on list
price
Output:
Name of Customer Discount Amount to be paid
……………….. ……… ..………….
A) Algorithm:
1. Input customer name and list price.
2. Calculate discount based on list price:
- ≤ 5000: 0%
- 5001-10000: 10%
- 10001-15000: 15%
- ≥ 15001: 20%
3. Calculate amount to be paid.
4. Display customer name, list price, discount rate, and amount to be paid.
B) Program:
import java.util.*;
public class Discount {
int cost;
String name;
double dc;
double amt;
void input() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter customer name: ");
name = scanner.nextLine();
System.out.print("Enter list price: ");
cost = scanner.nextInt();
scanner.close();
}
void cal() {
if (cost <= 5000) {
dc = 0;
} else if (cost >= 5001 && cost <= 10000) {
dc = 10;
} else if (cost >= 10001 && cost <= 15000) {
dc = 15;
} else {
dc = 20;
}
amt = cost - (cost * dc / 100);
}
void display() {
System.out.println(“Name of Customer ” + “\t” + “ Discount”+ “\ t”
+ “Amount to be paid”);
System.out.println(“……………”+ “\t” + “…......” + “\t” +
“…………….”);
}
public static void main(String[] args) {
Discount discount = new Discount();
discount.input();
discount.cal();
discount.display();
}
}
C) Variable Description:
Variable Datatype Description
Cost int To store the MRP cost
of an article.
Name String To store the name of
customer.
Dc double To store the discount
on the article.
Amt double To store the final price
of the article.
12) A bank charges interest for the vehicle loan as per the following
tariff:
Number of Rate of Interest
Up to 5 years 15%
More than 5 years and up to 10 years 12%
Above 10 years 10%
Data Members:
int time- time for which loan is sanctioned
double principal- amount sanctioned
double rate- rate of interest
double interest- to store interest
Interest=(principal*rate*time)/100
double amt- amount to be paid after given time
Member Functions:
Void getdata()- to accept principal and time
Void calculate()- to find interest and amount
Void display()- to display interest and amount
B) Program:
import java.util.Scanner;
class Loan {
int time; // time for which loan is sanctioned
double principal; // amount sanctioned
double rate; // rate of interest
double interest; // to store interest
double amt; // amount to be paid after given time
if (time <= 5) {
rate = 15.0;
} else if (time <= 10) {
rate = 12.0;
} else {
rate = 10.0;
}
}
Data Members:
String name- to store name of the student
Int mm- to store marks in maths
Int scm- to store marks in science
Int comp- to store marks in computer
Member Methods:
Student()- parameterized constructor to initialize data members by
accepting details check()- to check the eligiblity for the course with
the following conditions:
Marks Course
90% or more in all subjects Science with Computer
Average marks 90% or more Bio- science
Average marks 80% or more and less than 90%
Commerce display()- to display eligibility
Write a main() method to create an object of the class and call all the
above member methods.
A) Algorithm:
1. Initialize the Student Object:
Accept the student’s name and marks in Maths, Science, and Computer.
Check Eligibility:
If marks in all subjects are 90% or more, the student is eligible for
Science with Computer.
If the average marks are 90% or more, the student is eligible for Bio-
Science.
If the average marks are between 80% and 89.99%, the student is
eligible for Commerce.
Display Eligibility:
Print the student’s name and the eligible course based on the conditions
checked.
B) Program:
class Student {
// Data members
private String name;
private int mm; // Marks in Maths
private int scm; // Marks in Science
private int comp; // Marks in Computer
// Parameterized constructor
public Student(String n, int m, int sc, int c) {
name = na;
mm = m;
scm = sc;
comp = c;
}
C) Variable Descrition:
1. name:
Type: String
1. mm:
Type: int
2. scm:
Type: int
3. comp:
Type: int
Data Members:
Name, address, phone, subject, specialization, monthly salary,
incometax
Member Methods:
(i) To accept details of the teacher including monthly salary
(ii) To display details of the teacher
(iii) To compute annual income tax at 5% of annual salary above
Rs. 175000
Write a main method to call the above member methods.
A) Algorithm:
1. Initialize the Salary Object:
If the annual salary exceeds Rs. 175,000, compute the income tax as 5% of
the amount exceeding Rs. 175,000.
4. Main Method:
B) Program:
class Salary {
// Data members
private String name;
private String address;
private String phone;
private String subject;
private String specialization;
private double monthlySalary;
private double incomeTax;
address = add ;
phone = ph;
subject = sub;
specialization = spec;
monthlySalary = sal;
}
// Method to display details of the teacher
public void displayDetails() {
System.out.println("Name: " + name);
System.out.println("Address: " + address);
System.out.println("Phone: " + phone);
System.out.println("Subject: " + subject);
System.out.println("Specialization: " + specialization);
System.out.println("Monthly Salary: " + monthlySalary);
System.out.println("Annual Income Tax: " + incomeTax);
}
Data Members:
String name, address , city
Float salary
Member Functions:
Pay(String n, String add, String cy, float s)
Void outputdata()- to display all
initialized values Void
calculate()- to find and print the
salary da=15% of salary
hra=10% of salary
Pf=12% of salary
gross= salary+da+hra
net=gross-pf
void display()-to display all details of the employee
A) Algorithm:
B) Program:
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
name = n;
address = add;
city = cy;
salary = s;
}
// Function to calculate and print the salary details
outputData();
calculate();
employee.display();
C) Variable Description:
1. name
Datatype: String
2. address
Datatype: String
3. city
Datatype: String
4. salary
Datatype: float
Name:
Aizen
Address:
City:
Ahmedabad
Salary:
20000000 Inr
3000000 Inr
1500000 Inr
1800000 Inr
Gross Salary:
24500000 Inr
Net Salary:
18200000 Inr