UNIVERSITY SYLLABUS:
EX NO:2
1.Design a Date class similar to the one provided in the java.util package.
(First you should finish that progam,then only you can go to next program):
(Search the Date class methods in Internet and try.First define get method and set the method value into setmethod.Dvelope a code to check whether the given date is actual date or before or after the date.Here the algorithm for DATE class program.)
ALGORITHIM:
step 1:Define the class MyDate with members date,month,year,hour,min,sec.
step 2:USing a default constructor,set the values using the predefined Dateclass.
step 3:use parameterised constructors to set the values for the members.
step 4:Define the methods getYear(),getMonth(),getDate(),getHours(),getMinutes(),getSeconds to return the year,month,date,hours,minutes and seconds.
step 5:Define the methods setYear(),setMonth(),setDate(),setHours(),setMinutes(),setSeconds() to set the values for year,month,date,hours,minutes and seconds.and also get the date,year,month,time,sec using Scanner.
step 6:Define the method after() with the return type boolean to check whether the given date is after the current date.
step 7:Define the method before() with the return type boolean to check whether the given date is before the current date.
step 8:Define the method compareTo() with the return type integer to compare two dates.it will return 0 if both are same,will return 1 if date is after currrent date else it returns -1.
step 9:terminate the class.
step 10:Define the datetest and define the main() in it.
step 11:Create many objects for the class MyDate and access the methods of the class using different objects.and compare the date to display the result.
step 12:Display the result.
step 13:terminate the main() and class.
OTHER LAB PROGRAMS:
1.Sting s1=”Hello”; Sring s2=”Hello”;Sring s3=”Good-Bye”;String s4=”HELLO”;
Apply all String comparision methods to the value of s.
2.String s=”Now is the time for all good men”+”to come to the aid of country.”;
Apply all String searching method to the value of s.
3.String s=”APPLY ALL STRING MODIFICATION METHOD:”;
Apply all String modification methods to the value of s.
4.Write a java program to check whether the String is palindrome or not.
5.Display the following output :
S1=hello
S2=Java world
S3=world
S4=hello
Input:
Char carry[]={‘J’,’a’,’v’,’a’,’w’,’o’,’r’,’l’,’d’};
Apply any string operations.
6.Display the following output using arraycopy method.
0:2001
1:2002
2:2003
3:5
4:7
5:11
6:13
Input:
Int[] first={2,3,5,7,11,13};
Int[] second={2001,2002,2003,2004,2005,2006,2007};
7.Develop a program to sorting the following array elements:
a){45,65,12,32,1,23,39,4,8,3}
b){46,78,34,43,23,22,11,55,23,111}
8.Write a java program to convert the value “Programmer” in the string variable convert to “Programming”.
9.Write a java program to search for a number in the given array using binary search.
10.Diaplay the output for the following program:
public class StringsDemo3 {
public static void main(String[] args) {
String str1 = "My name is bob";
char str2[] = new char[str1.length()];
String str3 = "bob";
String str4 = "cob";
String str5 = "BoB";
String str6 = "bob";
System.out.println("Length of the String str1 : " + str1.length());
System.out.println("Character at position 3 is : "
+ str1.charAt(3));
str1.getChars(0, str1.length(), str2, 0);
System.out.print("The String str2 is : ");
for (int i = 0; i < str2.length; i++) {
System.out.print(str2[i]);
}
System.out.println();
System.out.print("Comparision Test : ");
if (str3.compareTo(str4) < 0) {
System.out.print(str3 + " < " + str4);
} else if (str3.compareTo(str4) > 0) {
System.out.print(str3 + " > " + str4);
} else {
System.out.print(str3 + " equals " + str4);
}
System.out.println();
System.out.print("Equals Test");
System.out.println("str3.equalsIgnoreCase(5) : "
+ str3.equalsIgnoreCase(str5));
System.out.println("str3.equals(6) : " + str3.equals(str6));
System.out.println("str1.equals(3) : " + str1.equals(str3));
str5.toUpperCase(); //Strings are immutable
System.out.println("str5 : " + str5);
String temp = str5.toUpperCase();
System.out.println("str5 Uppercase: " + temp);
temp = str1.toLowerCase();
System.out.println("str1 Lowercase: " + str1);
System.out.println("str1.concat(str4): " + str1.concat(str4));
String str7temp = " \t\n Now for some Search and Replace Examples ";
String str7 = str7temp.trim();
System.out.println("str7 : " + str7);
String newStr = str7.replace('s', 'T');
System.out.println("newStr : " + newStr);
System.out.println("indexof Operations on Strings");
System.out.println("Index of p in " + str7 + " : "
+ str7.indexOf('p'));
System.out.println("Index of for in " + str7 + " : "
+ str7.indexOf("for"));
System.out.println("str7.indexOf(for, 30) : "
+ str7.indexOf("for", 30));
System.out.println("str7.indexOf('p', 30) : "
+ str7.indexOf('p', 30));
System.out.println("str7.lastIndexOf('p') : "
+ str7.lastIndexOf('p'));
System.out.println("str7.lastIndexOf('p', 4) : "
+ str7.lastIndexOf('p', 4));
System.out.print("SubString Operations on Strings");
String str8 = "SubString Example";
String sub5 = str8.substring(5); // "ring Example"
String sub3_6 = str8.substring(3, 6); // "Str"
System.out.println("str8 : " + str8);
System.out.println("str8.substring(5) : " + sub5);
System.out.println("str8.substring(3,6) : " + sub3_6);
}
}
11.Try the programs for all array methods.(Try Example Program for every methods)
12.Try the programs for StrinBuilder class methods. _________________________________________________________________________________
Note:
1.Finish all bending lab programs.
2.Finish all class work examples.
3.Study for VIVA.
No comments:
Post a Comment