Computer Project
Computer Project
class ElectricBill {
String n;
int units;
void acceptData() {
void computeData() {
rate = ((2 * 100) + (units - 100) * 3); // Rate for next 200 units
else
rate = ((2 * 100) + (200 * 3) + (units - 300) * 5); // Rate for units above 300
else
bill = rate;
void displayData() {
2
System.out.println("Name\tUnits\tRate\tAmount");
a.acceptData();
a.displayData();
OUTPUT:
import java.util.*;
class Numbers
int n, s = 0;
void display()
System.out.println("Enter Number");
n = sc.nextInt();
if(s < n)
else if(s == n)
}
4
s.display();
OUTPUT:
import java.util.*;
class Menu {
int n;
void display() {
System.out.println("Enter Option");
n = sc.nextInt();
switch (n) {
case 1:
int p = 0;
System.out.println("Enter number");
p = sc.nextInt();
int s = 0;
int sum1 = 0;
sum1 += s;
s *= 10;
break;
case 2:
int g = sc.nextInt();
6
int a = 0, b = 1, c = 2;
a = b;
b = c;
c = d;
System.out.println();
break;
case 3:
int x = 0;
int l = 0;
System.out.println("Enter n");
l = sc.nextInt();
x = sc.nextInt();
double sum2 = 0;
if (i % 2 == 0) {
} else {
}
7
break;
default:
System.out.println("Invalid option");
a.display();
OUTPUT:
8
2 p int Stores the number entered by the user for the first case
3 s int Stores the intermediate sum value for the series in the first case
4 sum1 int Stores the total sum of the series in the first case
5 g int Stores the number of terms entered by the user for the second
case
7 x int Stores the value of x entered by the user for the third case
8 l int Stores the value of n entered by the user for the third case
4.Method Overloading
PROGRAM:
class Overload
void show()
char ch = 'A';
if(i % 2 == 0)
else
if(ch == 'A')
ch++;
System.out.println();
}
10
int sum;
if(ch == 's')
else
double z = 0;
a.show();
a.show(4, 's');
11
a.show(4, 'c');
a.show(3, 4);
OUTPUT:
import java.util.*;
class ShowRoom {
String name;
long mobno;
void input() {
System.out.println("Enter Name:");
name = sc.nextLine();
mobno = sc.nextLong();
System.out.println("Enter Cost:");
cost = sc.nextDouble();
void calculate() {
dis = (10.0 / 100) * cost; // Discount for cost between 10001 and 20000
dis = (15.0 / 100) * cost; // Discount for cost between 20001 and 35000
} else {
}
13
void display() {
a.input();
a.calculate();
a.display();
OUTPUT:
14
5 amt double Stores the final amount after applying the discount
15
double volume(double R)
double vol = 0;
return vol;
double vol = 0;
return vol;
double vol = 0;
return vol;
System.out.println(a.volume(21.0));
System.out.println(a.volume(17.0, 14.0));
16
OUTPUT:
import java.util.*;
class Number
int sum = 0;
while(n > 0)
int r = 0;
r = n % 10;
sum += r;
n /= 10;
return sum;
int n1 = 0, n2 = 0;
int sum2 = 0;
int sum1 = 0;
if(i % 2 == 0)
n2 = sc.nextInt();
else
n1 = sc.nextInt();
while(n1 > 0)
int r = 0;
r = n1 % 10;
sum1 += r;
n1 /= 10;
while(n2 > 0)
int r = 0;
r = n2 % 10;
sum2 += r;
n2 /= 10;
int sum = 0;
OUTPUT:
5 sum1, sum2 int Stores the sum of digits for n1 and n2 respectively
20
import java.util.*;
import java.util.Map;
class Num
int n;
void display()
n = sc.nextInt();
int[] A;
A = new int[n];
A[i] = sc.nextInt();
if (A[i] % 2 == 0)
else
a.display();
OUTPUT:
import java.util.*;
class BinSearch
int n;
void display()
n = sc.nextInt();
int L, U, M = 0, flag = 0;
L = 0;
U = A.length - 1;
while(L <= U)
M = (L + U) / 2;
else
break;
}
23
if(flag == 1)
System.out.println("Search successful");
else
System.out.println("Search Unsuccessful");
a.display();
OUTPUT:
6 flag int Indicator to show if the element is found (1) or not (0)
24
import java.util.*;
class chr
char ch;
int n;
void display()
n = sc.nextInt();
A[i] = sc.next().charAt(0);
int pos;
small = A[i];
pos = i;
{
25
temp = A[i];
A[i] = A[pos];
a.display();
OUTPUT:
26
6 pos int Stores the position of the smallest character during sorting
27
import java.util.*;
class Matrix
void display()
A[i][j] = sc.nextInt();
sumElements += A[i][j];
if (A[i][j] % 2 == 0) {
rowSum[i] += A[i][j];
colSum[j] += A[i][j];
28
if (i == j) {
if (i + j == 2) {
a.display();
}
29
OUTPUT:
import java.util.*;
class BSort {
void sort() {
char temp;
A[i] = sc.next().charAt(0);
temp = A[j];
}
31
a.sort();
OUTPUT:
import java.util.*;
class Piglatin
void display()
System.out.println("Enter String:");
s = sc.nextLine();
if ("AEIOU".indexOf(A[0]) != -1)
} else {
w += A[i];
w += A[0] + "AY"; // Move first consonant to the end and append "AY"
{
33
a.display();
OUTPUT:
import java.util.*;
class Wonders7
String s;
void display()
System.out.println("Country name");
s = sc.next();
if(s.equalsIgnoreCase("Mexico"))
else if(s.equalsIgnoreCase("Brazil"))
else if(s.equalsIgnoreCase("India"))
else if(s.equalsIgnoreCase("China"))
else if(s.equalsIgnoreCase("Peru"))
else if (s.equalsIgnoreCase("Jordan"))
System.out.println("JORDAN-PETRA");
else if(s.equalsIgnoreCase("Italy"))
System.out.println("ITALY-COLLOSEUM");
else
35
a.display();
OUTPUT:
import java.util.Scanner;
class LetterFrequency {
String sentence;
int[] freq = new int[26]; // Array to hold the frequency of each letter
void getInput() {
System.out.println("Enter a sentence:");
void calculateFrequency() {
char ch = sentence.charAt(i);
if (ch >= 'a' && ch <= 'z') { // Check if the character is a letter
void displayFrequency() {
System.out.println("Letter frequencies:");
}
37
lf.getInput();
lf.calculateFrequency();
lf.displayFrequency();
OUTPUT:
16.Palindromic String
PROGRAM:
import java.util.*;
class Palindrome
String s;
String w="";
void display()
System.out.println("Enter word");
s=sc.next();
for(int i=0;i<s.length();i++)
char ch=s.charAt(i);
if(ch!=' ')
if(w.equals(s))
else
a.display();
39
OUTPUT:
import java.util.*;
class Frequency
String s;
void display()
System.out.println("Enter String");
s = sc.nextLine();
char ch = s.charAt(i);
if(Character.isLetter(ch))
c1 += 1; // Count letters
if(Character.isDigit(ch))
c2 += 1; // Count digits
if(Character.isUpperCase(ch))
if(Character.isLowerCase(ch))
if(Character.isWhitespace(ch))
a.display();
OUTPUT:
import java.util.*;
class Applicant
System.out.println("Enter Adm.No");
System.out.println("Enter Name");
name=sc.next();
if(Agg>=80)
else if(Agg<80&&Agg>=65)
else if(Agg<65&&Agg>=50)
43
else
void RESULT()
System.out.println("AdmissionNumber:"+ANO+"\nName:"+name+"\nAggregate
Marks:"+Agg+"\nGrade:"+Grade);
a.ENTER();
a.GradeMe();
a.RESULT();
OUTPUT:
44
19.Manipulating String
PROGRAM:
import java.util.*;
class Convert {
String s;
String w = "";
void display() {
System.out.println("Enter String");
s = sc.nextLine();
char ch = s.charAt(i);
if (Character.isUpperCase(ch)) {
} else if (Character.isLowerCase(ch)) {
} else {
converter.display();
}
46
OUTPUT:
import java.util.*;
class Student
int n;
String[] name;
int[] mark;
void getInput()
n = sc.nextInt();
sc.nextLine();
System.out.println("Enter Name:");
name[i] = sc.nextLine();
System.out.println("Enter Mark:");
mark[i] = sc.nextInt();
sc.nextLine();
void calculateAndDisplay()
48
int sum = 0;
int sumDeviation = 0;
a.getInput();
a.calculateAndDisplay();
}
49
OUTPUT: