Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete Java program in a source file to be named Assignment3.java. The

ID: 3628867 • Letter: W

Question

Write a complete Java program in a source file to be named Assignment3.java.
The program should asks a user to enter two strings.
First, the program prompts:

Please enter a string.

The program should read in the string a user enters, and prompts:

Please enter another string.

The program reads in the string and performs the following:
checks if each string's length is odd or even.
checks if two strings are same or different.
checks which string is lexically larger, or they are same.
prints out the first character (index 0) of each string
prints out a new string consisting of the first string concatenated (appended) with the second string.
prints out two strings using upper case letters.

Here is the output your program should produce when the user enters the string shown in bold:

Sample Output: (the user enters the string shown in bold)

Please enter a string.
Apple
Please enter another string.
Orange

The first string's length is odd.
The second string's length is even.

The two strings are different.

The second string is lexically larger.

The first character of the first string is A
The first character of the second string is O

The concatenation of two strings is "AppleOrange"

The first string using upper case letters: APPLE
The second string using upper case letters: ORANGE

******************************************************************************
Try your program with the following input test cases:

Input test case 1:

carrots
Potatoes (with upper case 'P')

Input test case 2:

cabbage
cabbage


For this and all subsequent assignments, provide a heading (in comments) which includes:

The assignment number.
Its author (your name).
Your Lab Letter.
A description of what this program is doing.


Grading Criteria for the part 2:

2 pts : it contains header information, code is nicely commented
2 pts : it compiles
1 pt : it runs/executes
2 pts: it checks and prints if each string's length is odd or even
1 pt: it checks and prints if two strings are same or different.
1 pt: it checks and prints which string is lexically larger, or they are same.
2 pts: it prints out the first character (index 0) of each string
1 pt: it prints out a new string consisting of the first string concatenated (appended) with the second string.
2 pts: it prints out two strings using upper case letters.


Deduction: if code has poor style (indentation, spacing, etc.) then -2 points will be deducted.

Explanation / Answer

please rate - thanks

import java.util.*;
public class Assignment3
{public static void main(String[] args)
{String s1,s2,s3;
int n;
Scanner in=new Scanner(System.in);
System.out.println("Please enter a string: ");
s1=in.nextLine();
System.out.println("Please enter another string: ");
s2=in.nextLine();
System.out.println();
if(s1.length()%2==0)
      System.out.println("The first string's length is even.");
else
      System.out.println("The first string's length is odd.");
if(s2.length()%2==0)
      System.out.println("The second string's length is even.");
else
      System.out.println("The second string's length is odd.");
System.out.println();
n=s1.compareTo(s2);       
if(n==0)
     System.out.println("The two strings are the same.");
else
     System.out.println("The two strings are different.");
System.out.println();
if(n<0)
     System.out.println("The second string is lexically larger.");
else if(n>0)
     System.out.println("The first string is lexically larger.");
System.out.println();
System.out.println("The first character of the first string is "+s1.charAt(0));
System.out.println("The first character of the second string is "+s2.charAt(0));
s3=s1+s2;
System.out.println();
System.out.println("The concatenation of two strings is ""+s3+""");
System.out.println();
System.out.println("The first string using upper case letters:"+s1.toUpperCase());
System.out.println("The second string using upper case letters:"+s2.toUpperCase());

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote