INFORMATICSPRACTICES
PRACTICAL
SUBMITTEDBY :
navet G
sin h
ROLL NO :
JAVA PROGRAMMING
[Link] a java program to print the table of the entered number?
Ans. Preview-
Source Code-
Code for Table
private void jButton1ActionPerformed([Link]) {
// TODO add your handling code here:
int x= [Link]([Link]());
inty,z=0;
for(y=1;y<=10;++y) {
z=y*x;
[Link](z+"\n"); }}
Code for Clear
private void clearActionPerformed([Link]) {
// TODO add your handling code here:
[Link](" ");
[Link](" "); }
[Link] a java program to print the Fibonacci series of the entered number?
Ans. Preview-
Source Code-
Code for Fibonacci
private void jButton2ActionPerformed([Link]) {
// TODO add your handling code here:
int s1=0,s2=1,sum,n;
n=[Link]([Link]());
if(n==0)
[Link](0+"\n");
else
if(n==1)
[Link](0+"\n"+1+"\n");
else {
[Link](0+"\n"+1+"\n");
[Link]("");
for(inti=2; i<=n; i++) {
sum=s1+s2;
[Link](sum+"\n");
[Link](" ");
s1=s2;
s2=sum; } } }
Code for Clear
private void clearActionPerformed ([Link]) {
// TODO add your handling code here:
[Link]("");
[Link]("");
}
[Link] a java program to display the scored goal details and match result?
Ans. Preview-
Source Code-
Code for Scored By A
private void GOAActionPerformed([Link]) {
// TODO add your handling code here:
intga= [Link]([Link]());
ga=ga+1;
[Link](""+ga); }
Code for Scored By B
private void GOBActionPerformed([Link]) {
// TODO add your handling code here:
intgb= [Link]([Link]());
gb=gb+1;
[Link](""+gb); }
Code for Declare Match
private void DCActionPerformed([Link]) {
// TODO add your handling code here:
intga=[Link]([Link]());
intgb=[Link]([Link]());
String res=(ga>gb?"Team A wins":(ga<gb)?"Team B wins":"Draw");
[Link](res); }
Code for Clear
private void CLEARActionPerformed([Link]) {
// TODO add your handling code here:
[Link](" ");
[Link]("0");
[Link]("0"); }
Q4. Design a java program to add the Digits in input area?
Ans. Preview-
Code of main method-
intaddDigits(int n){int s=0;
int dig;
while(n>0){
dig=n%10;
s=s+dig;
n=n/10;
}return s;
Code for Compt........... Button-
intnum=[Link]([Link]());
int sum=addDigits(num);
[Link]("Sum of its digits is "+sum);
Q5. Design a java program to change background colour of different input
controls ?
Ans. Preview-
Code for the jList (Event –ListSelection-valueChanged)-
private void ColValueChanged([Link]) {
// TODO add your handling code here:
inti;
Color x=[Link];
i=[Link]();
switch(i){
case 0: x=[Link];
break;
case 1: x=[Link];
break;
case 2: x=[Link];
break;
case 3: x=[Link];
break;
case 4: x=[Link];
break;
case 5: x=[Link];
break;
case 6: x=[Link];
break;
if([Link]())
[Link](x);
else
[Link]([Link]);
if([Link]())
[Link](x);
else
[Link]([Link]);
if([Link]())
[Link](x);
else
[Link]([Link]);
Q6. Design a java program to select the character from the list as given in
textfield?
Ans. Preview-
Code of Select in List Button-
private void oKActionPerformed([Link]) {
// TODO add your handling code here:
[Link]([Link](), true);
[Link] a java program to print the numbers in between the given input?
Ans.
Code of Count Button-
int a=[Link]([Link]());
int b=[Link]([Link]());
if(a>b){
for(;b<=a;b++)
{[Link](b+" ");}
else{
for(;a<=b;a++)
{ [Link](a+" ");}
}
Q8. Design a java program to check a string is palindrome or not?
Ans.
Code of Perform Palindrome Test Button-
String str=[Link]();
showPalindrome(str);
Main method Code-
public void showPalindrome(String s){
StringBuffer out=new StringBuffer(s);
if(isPalindrome(s))
s=s+": is a palindrome!";
else if(isPalindrome2(s))
s=s+ ": is a palindrome if you ignore case";
else
s=s+": is not a palinidrome! ";
[Link](s);
publicbooleanisPalindrome(String s)
{StringBuffer reversed=(new StringBuffer(s)).reverse();
[Link]([Link]());
publicboolean isPalindrome2(String s)
{StringBuffer reversed=(new StringBuffer(s)).reverse();
[Link]([Link]());
}
Q9. Design a java program to reverse a string?
Ans.
Code of Reverse Button-
String a=[Link]();
String b="";
for(inti=[Link]()-1;i>=0;i--){
b=b+[Link](i);
}[Link](b);
Q10. Design a java program to find the occurrence of a character?
Ans.
Code of Count Button-
String a=[Link]();
char b=[Link]().charAt(0);
int c=0;
for(int d=0;d<[Link]();d++){
if([Link](d)==b)
c++;
} [Link] (""+c);
Q11. Design a java program to find the position of a vowel in a string?
Ans.
Code of OK Button-
// TODO add your handling code here:
String a=[Link]();
for(int d=0;d<=[Link]();d++){
char c=[Link](d);
switch(c){
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
d=d+1;
[Link](" "+d+"\n");
break;
default: } }
Q12. Design a java program to display a menu of Ice-cream parlour ?
Ans.
Code of Calculate Button-
if([Link]()==true)
{ [Link]("35");}
else
{[Link]("0");
[Link]("0");}
if([Link]()==true)
{[Link]("50");}
else
{[Link]("0");
[Link]("0");}
if([Link]()==true)
{[Link]("30");}
else
{[Link]("0");
[Link]("0");}
int a1,a2,a3,a4,a5,a6,a7,a8,a9,a10;
a1=[Link]([Link]());
a2=[Link]([Link]());
a3=[Link]([Link]());
a4=[Link]([Link]());
a5=[Link]([Link]());
a6=[Link]([Link]());
a7=a1*a4;
a8=a2*a5;
a9=a3*a6;
[Link](""+a7);
[Link](""+a8);
[Link](""+a9);
a10=a7+a8+a9;
[Link](a10+"");
Code of Clear Button-
[Link](false);
[Link](false);
[Link](false);
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
Code of Exit Button-
[Link] (0);
Q13. Design a class program to display a detail of a book ?
Ans.
Class Method-
public class book {
String name,author;
int edition;
float price;
public book(){
[Link]="";
[Link]="";
edition=2000;
price=100.0f;
public book(String a,Stringb,intc,float d){
[Link]=a;
[Link]=b;
edition=c;
price=d;
void display(){
[Link]("Name of the book is "+name);
[Link]("Author of book is "+author);
[Link]("Edition:-"+edition);
[Link]("Price:-"+price);
}
Main Method-
book B1=new book ("The Canterville Ghost”, “Oscar Wilde",2012,55);
[Link] ();
Q14. Design program to display a student record table ?
Ans.
Class Method-
void process(){
int a=0;
String name="",hname="";
doubleperc=0.0,hperc=0.0;
do{name=[Link]("Enter Student's name:");
perc=[Link]([Link]("Enter Percentage Marks:"));
[Link](name+"\t"+perc+"\n");
if(hperc<perc){
hperc=perc;
hname=name;
a=[Link](null,"More Student info??");
while(a==JOptionPane.YES_OPTION);
if(a==JOptionPane.NO_OPTION){
[Link](null,"Highest scorer is "+hname+" with "+hperc+"marks. ");
Main Method-
JOPdialogs j1=new JOPdialogs();
[Link](true);
[Link]();
[Link](false);
Q15. Design a class program to print detail of a student?
Ans.
Class Method-
public class Student{
introllNumber = 0;
String name = "nil";
public Student(intrno,Stringsname){
rollNumber=rno;
name=sname;
void display(){
[Link]("RollNumber ="+rollNumber);
[Link]("Name ="+name);
Main Method-
StudentB1=new Student(23,"GOVIND");
[Link]();