Create a program called ColorComparer that asks the user for two sets of RGB val
ID: 3742967 • Letter: C
Question
Create a program called ColorComparer that asks the user for two sets of RGB values (integer values between 0 and 255) for a total of six integers, then creates two different Color objects with the gathered RGB values. Then, compare the two colors to one another using equals(), and return whether the two colors being the same is true or false. For this problem, the program is not expected to know when any of the RGB values are outside of the range of 0 to 255.(Java Coding Style) Create a program called ColorComparer that asks the user for two sets of RGB values (integer values between 0 and 255) for a total of six integers, then creates two different Color objects with the gathered RGB values. Then, compare the two colors to one another using equals(), and return whether the two colors being the same is true or false. For this problem, the program is not expected to know when any of the RGB values are outside of the range of 0 to 255.
(Java Coding Style)
(Java Coding Style)
Explanation / Answer
import java.awt.*; import java.util.Scanner; public class ColorComparer { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter r g and b for first color: "); int r1 = in.nextInt(), g1 = in.nextInt(), b1 = in.nextInt(); System.out.print("Enter r g and b for second color: "); int r2 = in.nextInt(), g2 = in.nextInt(), b2 = in.nextInt(); Color color1 = new Color(r1, g1, b1); Color color2 = new Color(r2, g2, b2); if(color1.equals(color2)) { System.out.println("Both colors are same"); } else { System.out.println("Both colors are not same"); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.