Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
CODE 01:
package termwork_java;
import [Link];
public class Count_character_in_string {
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
[Link]("Enter Strings");
String s = [Link]();
char[] arr = [Link]();
int l = [Link]();
int[] dup = new int[l];
int i , j,count=0 ;
for(i=0 ; i<l ; i++)
{
if(dup[i]==0 && arr[i]!=' ')
{
count=0;
for(j=0 ; j<l ; j++)
{
if(arr[i]==arr[j])
{
count++;
dup[j]=-1 ;
}
}
if(count!=0)
{
dup[i]= count ;
}
}
}
for(i=0 ; i<l ; i++)
{
if(dup[i]!=0 && dup[i]!=-1)
{
[Link](arr[i]+" = "+dup[i]);
}
}
}}
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
OUTPUT :
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
CODE 02:
package termwork_java;
public class Q2_print_char_place_of_num
{ public static void main(String[]
args)
{
int i;
for(i=1 ; i<50 ; i++)
{
if(i % 3 == 0)
{
if(i%5 == 0)
[Link]("TF");
else
[Link]("T");
}
else if(i % 5 == 0)
{
if(i%3 == 0)
[Link]("TF");
else
[Link]("F");
}
else
[Link](i);
}
}
}
OUTPUT :
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
CODE 03:
package termwork_java;
import [Link];
class String_Operations
{
Scanner sc = new Scanner([Link]);
void string_to_integer()
{
[Link]("Enter string to convert in integer");
String s = [Link]();
int s1 = [Link](s);
[Link]("Integer : "+s1);
String s2 = [Link](s1);
[Link]("String Again :
"+s2);
}
void string_change_case()
{
[Link]("Enter String for case conversion");
String s = [Link]();
[Link]("UpperCase : "+[Link]());
[Link]("LowerCase : "+[Link]());
}
void extract_no_of_characters()
{
[Link]("Enter String for getting no of characters");
String s = [Link]();
int l = [Link]();
int c=0 ;
for(int i=0 ; i<l ; i++)
{
if([Link](i)!=' ')
c++;
}
[Link]("No of characters : "+c);
}
void compare_strings()
{
[Link]("Enter two Strings for comparing");
String s1 = [Link]();
String s2 = [Link]();
[Link]("using equal method -- "+[Link](s2));
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
[Link]("using equalsIgnoreCase-- "+[Link](s2));
[Link]("using compareTo-- "+[Link](s2));
}
void substring_search_and_replace()
{
[Link]("Enter Main String for searching");
String s1 = [Link]();
[Link]("Enter substring to replace");
String s2 = [Link]();
[Link]("Enter string by which substring replaced");
String s3 = [Link]();
String s4 = [Link](s2, s3);
[Link]("new string "+ s4);
}
void count_various_characters()
{
int vowels=0 , digits=0 , sp_char=0 ,lower=0 , upper=0 , words=1 ;
[Link]("enter a string for counting");
String s = [Link]();
String Vowel = "AEIOUaeiou" ;
int l1 = [Link]();
int l = [Link]();
for(int i=0 ; i<l ; i++)
{
for(int j=0 ; j<l1 ; j++)
{
if([Link](i)==[Link](j))
vowels++;
}
if([Link]([Link](i)))
digits++;
else if([Link]([Link](i)))
upper++;
else if([Link]([Link](i)))
lower++;
else if([Link]([Link](i)))
words++;
else
sp_char++;
}
[Link]("Number of vowels : " + vowels);
[Link]("Number of digits : " + digits);
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
[Link]("Number of special characters: " + sp_char);
[Link]("Number of lowercase letters : " + lower);
[Link]("Number of uppercase letters : " + upper);
[Link]("Number of words : " + words);
}
}
public class Q3_String_Operations {
public static void main(String[] args)
{
String_Operations a = new String_Operations();
a.string_to_integer();
a.string_change_case();
a.extract_no_of_characters();
a.compare_strings();
a.substring_search_and_replace();
a.count_various_characters();
}
}
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
OUTPUT :
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
CODE 04:
package termwork_java;
import [Link];
class Employee
{
Scanner sc = new Scanner([Link]);
String name ,pan;
long taxIncome;
double tax=0 ;
void inputinfo()
{
[Link]("Enter name of employee");
name = [Link]();
[Link]("Enter Pan_Number of employee");
pan = [Link]();
[Link]("Enter Income of employee");
taxIncome = [Link]();
}
void taxcalc()
{
if(taxIncome >=250000 && taxIncome <=300000 )
{
tax = (10.0/100)*(taxIncome-250000);
}
else if(taxIncome >300000 && taxIncome <= 400000 )
{
tax = (10.0/100)*50000 + ((20.0/100)*(taxIncome-300000)+5000) ;
}
else if(taxIncome >400000 )
{
tax = (10.0/100)*50000 + (20.0/100)*100000+5000 +
((30.0/100)*(taxIncome-400000)+25000);
}
}
void displayinfo()
{
[Link]("*****Employeee Details*********");
[Link]("Name :"+name);
[Link]("Pan_Number :"+pan);
[Link]("Annual_Income:"+taxIncome);
[Link]("Tax_to_pay :"+tax);
}
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
}
public class Q4_Tax_Calculation {
public static void main(String[] args)
{
Employee e = new Employee();
[Link]();
[Link]();
[Link]();
}
}
OUTPUT :
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
CODE 05:
package termwork_java;
import [Link];
class shape
{
Scanner sc = new Scanner([Link]);
void getPeri()
{
}
void getArea()
{
}
}
class circle extends shape
{
int r ;
circle()
{
[Link]("Enter radius ");
r = [Link]();
}
void getPeri()
{
double p = 2 * 3.14 * r ;
[Link]("perimeter of circle = "+p);
}
void getArea()
{
double a = 3.14 * r * r ;
[Link]("area of circle = "+a);
}
}
public class Q5_inheritance {
public static void main(String[] args)
{
circle c = new circle();
[Link]();
[Link]();
}}
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
OUTPUT :
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
CODE 06:
package termwork_java;
import [Link] ;
class bank
{
long amount;
Scanner sc = new Scanner([Link]);
bank(int balance)
{
[Link] = balance ;
}
void deposit()
{
[Link]("Enter amount to deposit ");
[Link] += [Link]();
[Link]("Amount deposited successfully");
[Link]("Total Bank Balance "+amount+" rupees");
}
void withdraw()
{
}
}
class custAccount extends bank
{
custAccount(int balance)
{
super(balance);
}
void withdraw()
{
[Link]("Do u want to withdraw type -- 1 for yes and 0 for no");
int ch = [Link]();
if(ch == 1) {
[Link]("Enter amount for withdrawl--- ");
long withdraw = [Link]();
amount = amount - withdraw;
if(amount <= 250 || amount < withdraw)
{
[Link]("cannot Withdraw");
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
}
else
{
[Link](withdraw +" rupees deducted from your account ");
[Link](amount+" rupees left in your account");
}}
}
}
public class Q6_Bank_mangaement {
public static void main(String[] args)
{
custAccount c = new custAccount(5000);
[Link]();
[Link]();
}
}
OUTPUT :
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
CODE 07:
package termwork_java;
abstract class Animal
{
abstract void sound();
}
class tiger extends Animal
{
void sound()
{
[Link]("Roarrrrrrrrrrrrrrr");
}
}
class dog extends Animal
{
void sound()
{
[Link]("barkkkkkkkkkkkkkkkk");
}
}
public class Q7_abstract_Ex {
public static void main(String[] args)
{
tiger t = new tiger();
dog d = new dog();
[Link]();
[Link]();
}
}
OUTPUT :
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
CODE 08:
package termwork_java;
import [Link] ;
interface Sortable
{
void sort(int[] arr);
}
class Bubble implements Sortable
{
public void sort(int[] a)
{
int i,j,tmp=0 ;
int n = [Link];
for(i=0 ; i<n-1 ; i++)
{
for(j=0 ; j<n-i-1 ; j++)
{
if(a[j]>a[j+1])
{
tmp = a[j];
a[j]=a[j+1];
a[j+1]=tmp ;
}
}
}
[Link]("Sorted Array using Bubble
Sort"); for(i=0 ; i<n ; i++)
{
[Link](a[i]+" ");
}
[Link]();
}
}
class Selection implements Sortable
{
public void sort(int[] a)
{
int i,j,tmp=0,min ;
int n = [Link];
for(i=0 ;i<n-1 ; i++)
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
{
min = i;
for(j=i+1 ; j<n-i-1 ; j++)
{
if(a[j]<a[min])
{
min = j ;
}
}
if(i!=min)
{
tmp = a[i];
a[i] = a[min];
a[min] = tmp;
}
}
[Link]("Sorted Array using Selection Sort");
for(i=0 ; i<n ; i++)
{
[Link](a[i]+" ");
}
[Link]();
}
}
public class Q8_Sorting_using_interface
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
[Link]("Enter range for array");
int length = [Link]();
int[] arr = new int[length];
[Link]("Enter elements of array");
for(int i=0 ; i<length ; i++)
{
arr[i] = [Link]();
}
Bubble b = new Bubble();
[Link](arr);
Selection s = new Selection();
[Link](arr);
}}
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
OUTPUT :
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
CODE 09:
package termwork_java;
import [Link];
public class Q9_Exception {
public static void main(String[] args) throws Exception
{
Scanner sc = new Scanner([Link]);
int maxMarks = 0;
float obtainedMarks = 0;
try {
if([Link] == 0)
throw new Exception("one command line argument must needed ");
maxMarks = [Link](args[0]);
if(maxMarks <= 0)
{
throw new Exception("Max marks must be greater than 0");
}
[Link]("Enter obtained marks");
obtainedMarks = [Link]();
if(obtainedMarks<0)
throw new Exception("marks must be positive");
else if(obtainedMarks > maxMarks)
throw new Exception("Obtained marks should be less than
maximum marks");
double p = (obtainedMarks*100)/maxMarks;
[Link]("Percentage = "+p+"%");
}catch(NumberFormatException e)
{
[Link]("Enter valid integral Number");
}
}
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
OUTPUT :
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
CODE 10:
package termwork_java;
import [Link];
class InvalidNameException extends Exception
{
public InvalidNameException(String msg)
{
super(msg);
}
}
class InvalidDesignationException extends Exception
{
public InvalidDesignationException(String msg)
{
super(msg);
}
}
class InvalidIdException extends Exception
{
public InvalidIdException(String msg)
{
super(msg);
}
}
public class Q10_Exception {
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
try {
[Link]("Enter Name of Employee");
String name = [Link]();
if()
{
throw new InvalidNameException("Name must be in UPPERCASE as
well as ALPHABETS only");
}
[Link]("Enter designation of employee");
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
String desg = [Link]();
if( && 
&& )
{
throw new InvalidDesignationException("Designation must be MANAGER
or CLERK or PEON only");
}
[Link]("Enter department ID");
int dept_id = [Link]();
if(dept_id<1 || dept_id > 5)
{
throw new InvalidIdException("Department id should be between 1
and 5");
}
[Link]("REQUIRED
DATA*******************************************");
[Link]("Name : "+name);
[Link]("Designation : "+desg);
[Link]("Deparment_Id : "+dept_id);
}catch(InvalidNameException e)
{
[Link]("Exception : "+[Link]());
}
catch(InvalidDesignationException e)
{
[Link]("Exception : "+[Link]());
}
catch(InvalidIdException e)
{
[Link]("Exception : "+[Link]());
}
}
}
Name: Anurag Singh Rangad MCA Sec ‘A’ Roll no: 41
OUTPUT :