Question

In: Computer Science

The Language is Java. Sample Output: There is no given sample Output IsEqualToTest (30) Write a...

The Language is Java.

Sample Output:

There is no given sample Output

IsEqualToTest (30)

Write a simple generic version of method isEqualTo that compares its two arguments with the equals method and returns true if they’re equal and false otherwise. Use this generic method in a program that calls isEqualToTest with the built-in types Integer, String, Double and Object. The main reads in two Integer, and two Double values with autoboxing, as well as two String and calls the method. For Object just create two Object objects with no parameters. The method doesn’t need to include any correctness tests.

Solutions

Expert Solution

Please find the code below.

class isEqualToTest<T1, T2>
{
T1 obj1; // An object of type T1
T2 obj2; // An object of type T2
  

isEqualToTest(T1 obj1, T2 obj2) // Constructor of the class 'isEqualToTest'
{
this.obj1 = obj1;
this.obj2 = obj2;
}
  
// It will return the boolean value after comparison
public boolean isEqualTo()
{
if (obj1.equals(obj2)){
return true;
}
else
return false;
  
}
}
  
class Main
{
public static void main (String[] args)
{
Object ob1 = new Object();
Object ob2 = new Object();
isEqualToTest <Integer, Integer> int_test =
new isEqualToTest<Integer, Integer>(15, 15);
isEqualToTest <Double, Double> double_test =
new isEqualToTest<Double, Double>(15.8, 15.7);
isEqualToTest <String, String> str_test =
new isEqualToTest<String, String>("ABC", "ABC");
isEqualToTest <Object, Object> obj_test =
new isEqualToTest<Object, Object>(ob1, ob2);
// Printing all outputs here
System.out.println("*** OUTPUT ***");
System.out.println(int_test.isEqualTo());
System.out.println(double_test.isEqualTo());
System.out.println(str_test.isEqualTo());
System.out.println(obj_test.isEqualTo());

}
}

OUTPUT:


Related Solutions

Write a program to perform the following actions: the language is Java – Open an output...
Write a program to perform the following actions: the language is Java – Open an output file named “Assign14Numbers.txt” – Using a do-while loop, prompt the user for and input a count of the number of random integers to produce, make sure the value is between 35 and 150, inclusive. – After obtaining a good count, use a for-loop to generate the random integers in the range 0 ... 99, inclusive, and output each to the file as it is...
Language for this question is Java write the code for the given assignment Given an n...
Language for this question is Java write the code for the given assignment Given an n x n matrix, where every row and column is sorted in non-decreasing order. Print all elements of matrix in sorted order.Input: The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the size of the matrix. Then the next line contains the n x n elements...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
In JAVA answer has to be able to do exact Sample Output shown Write a do-while...
In JAVA answer has to be able to do exact Sample Output shown Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again. If so, the loop should repeat; otherwise it should terminate. Name your class as NumberSum and add to it your header and sample output as a block comments. Upload the...
PROGRAM SIMULATION. Understand the given JAVA program and write the output. 1.     public class Places        {...
PROGRAM SIMULATION. Understand the given JAVA program and write the output. 1.     public class Places        {            public static void main(String args[])            {                   String place[]=new String[4];           place[0]="Salmaniya"; place[1]="Salmabad"; place[2]="Isa Town"; place[3] = “Manama”         System.out.println(place[3]);         System.out.println(place[1].toLowerCase());         System.out.println(place[2].substring(4,6);         System.out.println(place[3].charAt(4));         System.out.println(place[1].equals(place[2]));            } }    b. public class ChangeIt { public void doIt( int[] z ) { z[0] = 0; } } public class TestIt { public static void main ( String[] args ) {...
**Please write in Java, in a very simple/beginner coding style/language - thank you!** Directions: Given a...
**Please write in Java, in a very simple/beginner coding style/language - thank you!** Directions: Given a factorial n!. Find the sum of its digits, and the number of trailing zeros (ie: the number of zeros at the end of the factorial). Input: integer nn, a non-negative integer where n≤20n≤20 Output: integer xyxy, the concatenation of x and y, where x is the sum of the digits in n! and y is the number of the zeros in n!) Note, 0≤x,y0≤x,y....
Write a machine language program to output your name on the output device. The name you...
Write a machine language program to output your name on the output device. The name you output must be longer than two characters. Write it in a format suitable for the loader and execute it on the Pep/9 simulator. my name is Kevin
Language is Java Design and write a Java console program to estimate the number of syllables...
Language is Java Design and write a Java console program to estimate the number of syllables in an English word. Assume that the number of syllables is determined by vowels as follows. Each sequence of adjacent vowels (a, e, i, o, u, or y), except for a terminal e, is a syllable. However, the minimum number of syllables in an English word is one. The program should prompt for a word and respond with the estimated number of syllables in...
Java programming language Write a Java application that simulates a test. The test contains at least...
Java programming language Write a Java application that simulates a test. The test contains at least five questions. Each question should be a multiple-choice question with 4 options. Design a QuestionBank class. Use programmer-defined methods to implement your solution. For example: - create a method to simulate the questions – simulateQuestion - create a method to check the answer – checkAnswer - create a method to display a random message for the user – generateMessage - create a method to...
Write Java statements that will Create an UnorderedLinkedList Given List: 75 48 78 45 30 18...
Write Java statements that will Create an UnorderedLinkedList Given List: 75 48 78 45 30 18 4 32 36 19.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT