If you do not already have the Java development kit JDK inst

If you do not already have the Java development kit (JDK) installed, download and install it (Oracle Corporation, 2013b). You may use an integrated development environment (IDE) of your choice if you wish.

Solve the following programming problems in Java. Submit your source files including several test cases to show your solutions work as expected.


Write a program that reverses the order of characters in a string without using API functions.

Examples:
Enter a string: Northcentral University
The reverse of “Northcentral University” is “ytisrevinU lartnechtroN.”


Enter a string: racecar
The reverse of “racecar” is “racecar.”

Write a program that reads a list of integers (separated by whitespace and terminated by EOF) and outputs a report showing how many of each number was in the list. The sequencing of the numbers in the output is not important.

Example:
Enter a list of numbers: 1 2       3 2 3   2 3 4      1 89 1024
You entered 11 numbers. Here is a report on the duplicates:
1: typed 2 times
2: typed 3 times
3: typed 3 times
4: typed 1 time
89: typed 1 time
1024: typed 1 time

Write a program that prompts for the X, Y integer coordinates of two rectangles in the 2D plane and determines if the rectangles overlap.

Examples:
Enter the X, Y coordinates for one corner of rectangle 1: 0, 0
Enter the X, Y coordinates for another corner of rectangle 1: 5, 15
Enter the X, Y coordinates for one corner of rectangle 2: 1, 1
Enter the X, Y coordinates for another corner of rectangle 2: 6, 12
The rectangles overlap in the 2D plane.


Enter the X, Y coordinates for one corner of rectangle 1: 0, 0
Enter the X, Y coordinates for another corner of rectangle 1: 5, 15
Enter the X, Y coordinates for one corner of rectangle 2: 65, 30
Enter the X, Y coordinates for another corner of rectangle 2: 100, 56
The rectangles do not overlap in the 2D plane.

Solution

a)

import java.util.Scanner;

public class abc
{

public static void main(String[] args)
{
   String s ;
Scanner scanner = new Scanner(System.in);
System.out.println(\"Enter a String: \");
s = scanner.nextLine();   
System.out.print(\"The reverse of \" + s + \" is \" );
for (int i= s.length() - 1; i>=0; i--)
{
   System.out.print(s.charAt(i));        
}  
   System.out.print(\"\ \");        
}

}

b)

import java.util.Scanner;
import java.util.*;

public class abc
{

public static void main(String[] args)
{
   String s;    
       Map<Integer,Integer> map =new HashMap<Integer,Integer>();
System.out.println(\"Enter a list of numbers: \");    
   Scanner scanner = new Scanner(System.in);
   s = scanner.nextLine();   
       String[] strings = s.split(\"\\\\s+\");
       int[] numbers = new int[strings.length];
       for (int i = 0; i < numbers.length; i++)
       {
       numbers[i] = Integer.parseInt(strings[i]);

       if(map.containsKey(numbers[i]))
       {
          map.put(numbers[i], + (map.get(numbers[i]) + 1));
       }
       else
       {
          map.put(numbers[i] , 1);         
       }
       }

   for(Map.Entry m:map.entrySet())
   {
   System.out.println( m.getKey()+\" : typed \" + m.getValue() + \" times \");
   }

}

}

sample Output:

Enter a list of numbers:
1 2 2 3 3 3 4 4 4 4
1 : typed 1 times
2 : typed 2 times
3 : typed 3 times
4 : typed 4 times

c)

import java.util.Scanner;
import java.util.*;

public class abc
{

public static void main(String[] args)
{

   String s;    

System.out.println(\"Enter the X, Y coordinates for one corner of rectangle: \");    
   Scanner scanner = new Scanner(System.in);
   s = scanner.nextLine();   
       String[] strings = s.split(\",\");
       int[] numbers = new int[strings.length];
       for (int i = 0; i < numbers.length; i++)
       {
       numbers[i] = Integer.parseInt(strings[i]);
       }
       int x11 = numbers[0];        int y11 = numbers[1];

System.out.println(\"Enter the X, Y coordinates for another corner of rectangle: \");    
   // Scanner scanner = new Scanner(System.in);
   s = scanner.nextLine();   
       strings = s.split(\",\");
       for (int i = 0; i < numbers.length; i++)
       {
       numbers[i] = Integer.parseInt(strings[i]);
       }
       int x12 = numbers[0];        int y12 = numbers[1];

System.out.println(\"Enter the X, Y coordinates for one corner of rectangle: \");    
   // Scanner scanner = new Scanner(System.in);
   s = scanner.nextLine();   
       strings = s.split(\",\");
       for (int i = 0; i < numbers.length; i++)
       {
       numbers[i] = Integer.parseInt(strings[i]);
       }
       int x21 = numbers[0];        int y21 = numbers[1];

System.out.println(\"Enter the X, Y coordinates for another corner of rectangle: \");    
   // Scanner scanner = new Scanner(System.in);
   s = scanner.nextLine();   
       strings = s.split(\",\");
       for (int i = 0; i < numbers.length; i++)
       {
       numbers[i] = Integer.parseInt(strings[i]);
       }
       int x22 = numbers[0];        int y22 = numbers[1];

if (x12 < x21 || x22 < x11)
{
       System.out.println(\"The rectangles do not overlap in the 2D plane.\");
}       
else if (y11 > y22 || y21 > y12)
{
       System.out.println(\"The rectangles do not overlap in the 2D plane.\");
}
else
{
   System.out.println(\"The rectangles overlap in the 2D plane.\");
}

}

}

sample Output:

Enter the X, Y coordinates for one corner of rectangle:
0,0
Enter the X, Y coordinates for another corner of rectangle:
5,15
Enter the X, Y coordinates for one corner of rectangle:
1,1
Enter the X, Y coordinates for another corner of rectangle:
6,12
The rectangles overlap in the 2D plane.
akash@akash-SVE15116ENB:~/Desktop/chegg/Java$ java abc
Enter the X, Y coordinates for one corner of rectangle:
0,0
Enter the X, Y coordinates for another corner of rectangle:
5,15
Enter the X, Y coordinates for one corner of rectangle:
65,30
Enter the X, Y coordinates for another corner of rectangle:
100,56
The rectangles do not overlap in the 2D plane.

If you do not already have the Java development kit (JDK) installed, download and install it (Oracle Corporation, 2013b). You may use an integrated development
If you do not already have the Java development kit (JDK) installed, download and install it (Oracle Corporation, 2013b). You may use an integrated development
If you do not already have the Java development kit (JDK) installed, download and install it (Oracle Corporation, 2013b). You may use an integrated development
If you do not already have the Java development kit (JDK) installed, download and install it (Oracle Corporation, 2013b). You may use an integrated development

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site