==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
1. Write a program to define a class having one 3-digit number, num as data memb
er. Initialize and display reverse of that number.
================================================================================
==================================================*/
import java.lang.*;
class q1Reverse
{
int num,r=0,s=0;
q1Reverse(int n)
{
num = n;
}
void Reverse()
{
while(num>0)
{
r=num%10;
s=(s*10)+r;
num=num/10;
}
System.out.println("Reverse of number ="+s);
}
public static void main(String args[])
{
q1Reverse r1 = new q1Reverse(786);
r1.Reverse();
}
}
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
2.Write a program to define a class student with four data members such as name,
roll no.,sub1, and sub2. Define appropriate methods
to initialize and display the values of data members. Also calculate total Mark
s and percentage scored by student.
================================================================================
==================================================*/
import java.lang.*;
import java.io.*;
class student
{
String name;
int roll_no;
int sub1,sub2;
int total;
float per;
void getdata() throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(Sys
tem.in));
System.out.println ("Enter Name of Student");
name = br.readLine();
System.out.println ("Enter Roll No. of Student");
roll_no = Integer.parseInt(br.readLine());
/===============================================================================
=================================================
5. Write a program to accept a string from the console and count number of vowel
s, constants, digits, tabs and blank spaces in a string.
================================================================================
================================================*/
import java.io.*;
class q5vowels
{
public static void main(String args[]) throws IOException
{
String str;
int vowels = 0, digits = 0, blanks = 0;
char ch;
BufferedReader br = new BufferedReader(new InputStreamReader(Sys
tem.in));
System.out.print("Enter a String : ");
str = br.readLine();
for(int i = 0; i < str.length(); i ++)
{
ch = str.charAt(i);
if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || c
h == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U')
vowels ++;
else if(Character.isDigit(ch))
digits ++;
else if(Character.isWhitespace(ch))
blanks ++;
}
System.out.println("Vowels : " + vowels);
System.out.println("Digits : " + digits);
System.out.println("Blanks : " + blanks);
}
}
/*
Output:
Enter a String : ABC DE 123
Vowels : 2
Digits : 3
Blanks : 2
*/
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
6. Write a program to Implement a program to accomplish the following task using
string / string Buffer class :
i. Accept a password from user.
ii. Check if password is correct then display "Good"
Else display "Incorrect password"
iii. Append the password with the string "Welcome to java!!!"
iv. Display the password in reverse order.
sales[i-1] = Float.parseFloat(br.readLine());
sum=sum+sales[i-1];
}
System.out.println ("Sum = "+sum);
avg=sum/7;
System.out.println ("Average sale of week="+avg);
}
}
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
1. Write a program to define a class having one 3-digit number, num as data memb
er. Initialize and display reverse of that number.
================================================================================
==================================================*/
import java.lang.*;
class q1Reverse
{
int num,r=0,s=0;
q1Reverse(int n)
{
num = n;
}
void Reverse()
{
while(num>0)
{
r=num%10;
s=(s*10)+r;
num=num/10;
}
System.out.println("Reverse of number ="+s);
}
public static void main(String args[])
{
q1Reverse r1 = new q1Reverse(786);
r1.Reverse();
}
}
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
2.Write a program to define a class student with four data members such as name,
roll no.,sub1, and sub2. Define appropriate methods
to initialize and display the values of data members. Also calculate total Mark
s and percentage scored by student.
================================================================================
==================================================*/
import java.lang.*;
import java.io.*;
class student
{
String name;
int roll_no;
int sub1,sub2;
int total;
float per;
void getdata() throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(Sys
tem.in));
System.out.println ("Enter Name of Student");
name = br.readLine();
System.out.println ("Enter Roll No. of Student");
roll_no = Integer.parseInt(br.readLine());
System.out.println ("Enter marks out of 100 of 1st subject");
sub1 = Integer.parseInt(br.readLine());
System.out.println ("Enter marks out of 100 of 2nd subject");
sub2 = Integer.parseInt(br.readLine());
}
void show()
{
total=sub1+sub2;
per=(total*100)/200;
System.out.println ("Roll No. = "+roll_no);
System.out.println ("Name = "+name);
System.out.println ("Marks of 1st Subject = "+sub1);
System.out.println ("Marks of 2nd Subject = "+sub2);
System.out.println ("Total Marks = "+total);
System.out.println ("Percentage = "+per+"%");
}
}
class q2Student
{
public static void main(String args[]) throws IOException
{
student s=new student();
s.getdata();
s.show();
}
}
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
3.Write a program to define a class Fraction having data members numerator and d
enominator. Initialize three objects using different
constructors and display its fractional value.
================================================================================
==================================================*/
import java.lang.*;
import java.io.*;
class Fraction
{
double numerator,denominator,fraction;
Fraction (int a, double b)
{
numerator=a;
denominator=b;
fraction=numerator/denominator;
System.out.println ("Fraction1 = "+fraction);
}
Fraction (int x, int y)
{
numerator=x;
denominator=y;
fraction=numerator/denominator;
System.out.println ("Fraction2 = "+fraction);
}
Fraction(double m, double n)
{
numerator=m;
denominator=n;
fraction=numerator/denominator;
System.out.println ("Fraction3 = "+fraction);
}
}
class q3Fraction
{
public static void main(String args[])
{
Fraction f = new Fraction(12,12.3);
Fraction f2 = new Fraction(10,12);
Fraction f3 = new Fraction(10.5,13.5);
}
}
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
4.Write a program to define a class Employee to accept emp_id, emp _name, basic_
salary from the user and display the gross_salary.
================================================================================
==================================================*/
import java.lang.*;
import java.io.*;
class Employee
{
int emp_id;
String emp_name;
float basic_salary;
Employee(int id, String name, float sal)
{
emp_id=id;
emp_name=name;
basic_salary=sal;
}
void display()
{
float da=basic_salary*15/100;
float hra=basic_salary*10/100;
float gross_sal=basic_salary+da+hra;
System.out.println ("Employee Id= "+emp_id);
System.out.println ("Emplyee Name= "+emp_name);
System.out.println ("Gross Salary= "+gross_sal);
}
}
class q4Employee
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(Sys
tem.in));
System.out.println ("Enter Employee id");
int id = Integer.parseInt(br.readLine());
System.out.println ("Enter Employee Name");
String name = br.readLine();
System.out.println ("Enter Basic Salary");
Float sal = Float.parseFloat(br.readLine());
Employee e = new Employee(id, name, sal);
e.display();
}
}
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
6. Write a program to Implement a program to accomplish the following task using
string / string Buffer class :
i. Accept a password from user.
ii. Check if password is correct then display "Good"
Else display "Incorrect password"
iii. Append the password with the string "Welcome to java!!!"
iv. Display the password in reverse order.
v. Replace the character '!' in password with "*" character.
================================================================================
==================================================*/
import java.lang.*;
import java.io.*;
class q6String
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(Sys
tem.in));
String s1 = "!!sspp!!";
String s2;
System.out.println ("Enter Password");
s2 = br.readLine();
if(s1.compareTo(s2)==0)
{
System.out.println ("Good");
}
else
{
System.out.println ("Password is incorrect");
System.exit(0);
}
String s3 = "Welcome to Java!!!";
StringBuffer sb = new StringBuffer(s1);
sb.append(s3);
System.out.println ("Appended Password = "+sb);
StringBuffer s4 = new StringBuffer(s1);
s4=s4.reverse();
System.out.println ("String in Reverse Order = "+s4);
System.out.println ("Replaced '!' with '*' = "+s1.replace('!','*
'));
}
}
/*==============================================================================
==================================================
Roll No:- 12
}
}
//*Important Note- My .util package is not working so not sure whther this above
prgrm is crct or nt!!:-P
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
9.Write a program to implement the following Multi Level Inheritance:
Class: Account
Cust_name , acc_no
Class: Saving_Acc
Min_bal, saving_bal
Class:Acct_Details
Deposits, withdrawals
================================================================================
==================================================*/
import java.lang.*;
import java.io.*;
class Account
{
String cust_name;
int acc_no;
Account(String a, int b)
{
cust_name=a;
acc_no=b;
}
void display()
{
System.out.println ("Customer Name: "+cust_name);
System.out.println ("Account No: "+acc_no);
}
}
class Saving_Acc extends Account
{
int min_bal,saving_bal;
Saving_Acc(String a, int b, int c, int d)
{
super(a,b);
min_bal=c;
saving_bal=d;
}
void display()
{
super.display();
System.out.println ("Minimum Balance: "+min_bal);
System.out.println ("Saving Balance: "+saving_bal);
}
}
class Acct_Details extends Saving_Acc
{
int deposits, withdrawals;
Acct_Details(String a, int b, int c, int d, int e, int f)
{
super(a,b,c,d);
deposits=e;
withdrawals=f;
}
void display()
{
super.display();
System.out.println ("Deposit: "+deposits);
System.out.println ("Withdrawals: "+withdrawals);
}
}
class q9Multilevel
{
public static void main(String args[])
{
Acct_Details A = new Acct_Details("Pa.one",666,1000,5000,500,900
0);
A.display();
}
}
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
10.Write a program to implement the following Multiple Inheritance:
Class Student
Name, roll_no
Mark 1, Mark2
Interface: Exam
Percent_cal( )
Class: Result
Display( )
================================================================================
==================================================*/
import java.lang.*;
import java.io.*;
interface Exam
{
void percent_cal();
}
class Student
{
String name;
int roll_no,mark1,mark2;
Student(String n, int r, int m1, int m2)
{
name=n;
roll_no=r;
mark1=m1;
mark2=m2;
}
void display()
{
System.out.println ("Name of Student: "+name);
System.out.println ("Roll No. of Student: "+roll_no);
System.out.println ("Marks of Subject 1: "+mark1);
System.out.println ("Marks of Subject 2: "+mark2);
}
}
int n;
try
{
System.out.println ("Enter a no.");
n=Integer.parseInt(br.readLine());
if(n%2==0)
{
System.out.println ("No. is even");
}
else
{
throw new myException("No. is not even");
}
}
catch(myException me)
{
System.out.println (me);
}
catch(IOException ie)
{
System.out.println (ie);
}
}
}
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
13.Write a program to implement two threads such that one thread prints prime nu
mbers from 1 to 10 and other thread prints
non-prime numbers from 1 to 10 (use Thread class ).
Note :- Each thread has a delay of 500 millsecond after printing one number
================================================================================
==================================================*/
import java.lang.*;
import java.io.*;
import java.util.*;
class Prime extends Thread
{
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
if(i==2||i==3||i==5||i==7)
{
System.out.println ("Prime No.= "+i);
}
Thread.sleep(500);
}
}
catch (Exception e){}
}
}
class notPrime extends Thread
{
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
if(i==4||i==6||i==8||i==9||i==10)
{
System.out.println ("Non-Prime No.= "+i)
;
}
Thread.sleep(500);
}
}
catch (Exception e){}
}
}
class q13Thread
{
public static void main(String args[])
{
new Prime().start();
new notPrime().start();
}
}
//*Important Note- My Thread programs are not working so not sure whther this pr
grm is crct or nt!!:-P
/*==============================================================================
==================================================
Roll No:- 12
Class:- TYCO - Ist Shift
14.Write a program to accomplish following task.
i) Create a user-defined package box which has a class definition. For box havin
g data member and disp( )method . (Assume suitable data )
ii) Source file imports above package and calculates the volume of box .
================================================================================
==================================================*/
import java.lang.*;
import java.io.*;
Pacakage BoxPackage
{
public class Box
{
int length, breadth, height;
Box(int I,int b,int h)
{
length=l;
breadth=b;
height=h;
}
public void display()
{
int volume=length*breadth*height;
System.out.println("Volume of Box is"+volume);
}
}
}
import.BoxPackage.*;
class Boxdemo
{
/*==============================================================================
=============================================
16.Write a program to draw a bar chart for the table given below which shows ann
ual result analysis of a school from period 2001-2005.these values may be placed
in a HTML file as <param> attributes and then used in Applet for dislaying barchart.
Year
2001
2002
2003
2004
2005
Result %
80
90
100
100
98
Bar Chart
================================================================================
===========================================*/
import java.applet.*;
import java.awt.*;
/*
<applet code = "BarChart.class" width=400 height=400>
<param
<param
<param
<param
<param
name="year0"
name="year1"
name="year2"
name="year3"
name="year4"
value="2001">
value="2002">
value="2003">
value="2004">
value="2005">
<param
<param
<param
<param
<param
name="result0"
name="result1"
name="result2"
name="result3"
name="result4"
value="80">
value="90">
value="100">
value="100">
value="98">
</applet>
*/
public class BarChart extends Applet
{
int n;
String year[];
int value[];
public void init()
{
n = 5;
year = new String[n];
value = new int[n];
year[0]
year[1]
year[2]
year[3]
year[4]
value[0]
value[1]
value[2]
value[3]
value[4]
=
=
=
=
=
getParameter("year0");
getParameter("year1");
getParameter("year2");
getParameter("year3");
getParameter("year4");
=
=
=
=
=
Integer.parseInt(getParameter("result0"));
Integer.parseInt(getParameter("result1"));
Integer.parseInt(getParameter("result2"));
Integer.parseInt(getParameter("result3"));
Integer.parseInt(getParameter("result4"));
}
public void paint(Graphics g)
{
Font font = new Font("Arial",Font.BOLD,15);
g.setFont(font);
for(int i = 0; i < n; i ++)
{
g.setColor(Color.BLUE);
g.drawString(year[i], 20, i * 50 + 30);
g.setColor(Color.RED);
g.fillRect(70, i * 50 + 10, value[i], 40);
g.drawString(String.valueOf(value[i]) + "%", 180, i * 50
+ 35);
}
String msg = "Bar Chart from Year 2001 - 2005";
g.setColor(Color.darkGray);
font = new Font("Arial",Font.BOLD,20);
g.setFont(font);
g.drawString(msg, 50, 300);
}
}