e Secure httpscourseseasasuedulcse110dicurrenthwshw3html App

e Secure https://courseseas.asuedulcse110dicurrenthws/hw3.html Apps graduate school D asu-estwdfiles.co o arregentsasuedul. a windows 84thRH B windows 8p D Mttps:Neossasued 47 lssc uploads e universey Housing- iu other Spring 2017 ue: Thursday, February 16th, 6pm aximum points: 200 What This Assignment ls About Using Classes and objects (The String class) Using conditional (if, if-else) statements Use the following Coding Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators all other identifiers (variables, methods, objects) Use tabs or spaces to indent code within blocks code surrounded by braces). This includes classes, methods, and code associated with is, suitches and loops. Be consistent with the number of spaces ortabs dat use to indent. Use white space to make your program more readable. Note: The answers to the following questions should be typed in the block of comment ts in the Assignemnt3Java file. Please make sure theyre commented out. rype them neatly and make them easy to nead for the Exercisel what output is produced by the following code fragment? pto String Java Programming\" nl toLowerCase system out... printin (m3 repli and assigns the result to aum3.2 pts) Exercise2: write an assignment statement that computes the square root of the sum.f sereises: What output is produced by the following code fragment? 35 system out printin orange-y syaten out.println MacBook Air

Solution

Part1:

1. Jovo Progromming JAVA PROGRAMMING

   String n1,n2,n3;
   n1=\"Java Programming\";
   n2=n1.toUpperCase(); //JAVA PROGRAMMING
   n3=n1 + \" \" + n2; // Java Programming JAVA PROGRAMMING
   System.out.println(n3.replace(\'a\',\'o\')); // Jovo Progromming JAVA PROGRAMMING
  

2.   num3=Math.sqrt(num1+num2);

3. lemon
apple
          
int num=57, max=35;
if(num>=max*2) //condition evaluates to false. So \'if\' block won\'t be entered.
   System.out.println(\"orange\");
System.out.println(\"lemon\");
System.out.println(\"apple\");

Part 2:

Assignment3.java:

import java.util.Scanner;

public class Assignment3 {

   public static void main(String args[]){

   Scanner sc=new Scanner(System.in);
   System.out.println(\"Please enter a string\");
   String string1=sc.nextLine();
   //First string is read in string1 variable
  
   System.out.println(\"Please enter another string\");
   String string2=sc.nextLine();
   //Second string is read in string2 variable

   if(string1.length()%2==0)
       //If number of characters in first String is divisible by 2, it\'s even
       System.out.println(\"The first string\'s length is even\");
   else
       //If number of characters in first String is not divisible by 2, it\'s odd
       System.out.println(\"The first string\'s length is odd\");

  
   if(string2.length()%2==0)
       //If number of characters in second String is divisible by 2, it\'s even
       System.out.println(\"The second string\'s length is even\");
   else
       //If number of characters in second String is not divisible by 2, it\'s odd      
       System.out.println(\"The second string\'s length is odd\");

  
  
   if(string1.equals(string2)) //It checks if 2 strings are equal
       System.out.println(\"The two strings are same\");
   else
       System.out.println(\"The two strings are different\");
      

   if(string1.compareTo(string2)>0) //if string1>string2, positive value is returned
       System.out.println(\"The first string is lexically larger\");
   else if(string1.compareTo(string2)<0) //if string1<string2, negative value is returned
       System.out.println(\"The second string is lexically larger\");
   else   //if strings are equal, 0 is returned
       System.out.println(\"The strings are lexically equal\");

   //charAt function gives the first character of the String
   System.out.println(\"The first character of the first string is \"+ string1.charAt(0));
   System.out.println(\"The first character of the second string is \"+ string2.charAt(0));
  
   // \'+\' concatenates value of 2 strings
   System.out.println(\"The concatenation of the two strings is \"+ string1+string2);
  
   // toUpperCase() function returns the String in Upper case.
   System.out.println(\"The first string using uppercase letters: \"+ string1.toUpperCase());
   System.out.println(\"The second string using uppercase letters: \"+ string2.toUpperCase());

   }
}


Test Case 1:
Please enter a string
carrots
Please enter another string
Potatoes
The first string\'s length is odd
The second string\'s length is even
The two strings are different
The first string is lexically larger
The first character of the first string is c
The first character of the second string is P
The concatenation of the two strings is carrotsPotatoes
The first string using uppercase letters: CARROTS
The second string using uppercase letters: POTATOES


Test Case 2:
Please enter a string
cabbage
Please enter another string
cabbage
The first string\'s length is odd
The second string\'s length is odd
The two strings are same
The strings are lexically equal
The first character of the first string is c
The first character of the second string is c
The concatenation of the two strings is cabbagecabbage
The first string using uppercase letters: CABBAGE
The second string using uppercase letters: CABBAGE

Note: Please write the header information(assignment number, lab letter, name, etc) in comments.

 e Secure https://courseseas.asuedulcse110dicurrenthws/hw3.html Apps graduate school D asu-estwdfiles.co o arregentsasuedul. a windows 84thRH B windows 8p D Mtt
 e Secure https://courseseas.asuedulcse110dicurrenthws/hw3.html Apps graduate school D asu-estwdfiles.co o arregentsasuedul. a windows 84thRH B windows 8p D Mtt
 e Secure https://courseseas.asuedulcse110dicurrenthws/hw3.html Apps graduate school D asu-estwdfiles.co o arregentsasuedul. a windows 84thRH B windows 8p D Mtt

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site