question archive In many languages (including Java), you can form a color by specifying certain amounts of red, green, and blue, with each color's amount ranging from 0% to 100%

In many languages (including Java), you can form a color by specifying certain amounts of red, green, and blue, with each color's amount ranging from 0% to 100%

Subject:Computer SciencePrice:5.87 Bought7

In many languages (including Java), you can form a color by specifying certain amounts of red, green, and blue, with each color's amount ranging from 0% to 100%. For example, to specify purple, you could use this code

rgb(100%, 60%, 100%)

The rgb stands for red, green, and blue. With 100% for red and blue, the resulting color is purple. In the following Rgb and RgbDriver class skeletons, replace the <insert...> lines with appropriate code such that the program operates properly. More specifically:

  1. In the Rgb class, provide a method definition for the setRed method such that setRed can be called as part of a method-call chain.
  2. In the RgbDriver class, provide a single statement that chains calls to the setRed, setGreen, setBlue, and display For your method-call arguments, pass 100 to setRed, 60 to setGreen, and 100 to setBlue. With those argument values, your method-call-chaining statement should print this:

rgb(100%, 60%, 100%)

public class Rgb
{
  private int red; 
  private int green;
  private int blue;

  <insert setRed method definition here>

  public Rgb setGreen(int green) 
  {
    this.green = green; 
    return this; 
  } // end setGreen

  public Rgb setBlue(int blue) 
  {
    this.blue = blue; 
    return this; 
  } // end setBlue

  public void display()
  {
    System.out.printf("rgb(%d%%, %d%%, %d%%)n",
      this.red, this.green, this.blue); 
  } // end display
} // end Rgb class
public class RgbDriver
{
  public static void main(String[] args) 
  {
    Rgb rgb = new Rgb();
    <insert chained method calls here>
  }
} // end RgbDriver class

 

Option 1

Low Cost Option
Download this past answer in few clicks

5.87 USD

PURCHASE SOLUTION

Option 2

Custom new solution created by our subject matter experts

GET A QUOTE

rated 5 stars

Purchased 7 times

Completion Status 100%