In: Computer Science
To get full credit for this assignment you must:
(1) answer each question - make sure you answer every part of question
AND
(2) respond to at least 2 of your classmates posts
(NOTE: You should not just agree/ disagree with the post. You need to provide justified explanation
of your agreement/disagreement. Be respectful at all times.
Do NOT revise your post after reading other student posts.)
In your own words, answer all questions (4 points each):
P.S : I think there is a problem in the question number 4. as they have asked to assign 10 objects into the array whose length is 9 (given). I have assumed the array size as 10. Please go through the solutions minutely before giving a disilke. Thank you.
1. Write a method that displays the third letter of a string (p. 472 in textbook) that is given to the method (i.e. "Jacob" returns the letter 'c')
public class Main
{
public static char displayThird(String s)
{
char a[]=s.toCharArray();
return(a[2]);
}
public static void main(String[] args) {
System.out.println("The third
letter is: "+displayThird("Jacob"));
}
}
2. Write a method that modifies a string (p. 488 in textbook) using the stringVar.Remove(start) where the method removes the third letter of a string that is given to the method (i.e. "Jacob" returns "Jaob")
public class Main
{
public static String remove(String s)
{
return(s.substring(0,2)+s.substring(3));
}
public static void main(String[] args) {
System.out.println("The string is:
Jacob");
System.out.println("The string
after removing the third letter: "+ remove("Jacob"));
}
}
3.Write a statement that creates an instance of the Transcript class.
Transcript transcript = new Transcript( );
4.Suppose that an application declares an array of class objects with the following statement:
for ( i = 0 ; i<10 ; i++)
{
Employee emp = new Employee( );
employees [ i ] = emp;
}