public class TrafficLightViewer 2 { 1 3. public static void main(String[] args) 4 Rectangle rl = new Rectangle(50,20,20,60); Ellipse cl Ellipse cl.setColor(Color.RED); Ellipse cl.fil); = new Ellipse(30,40,20,20); 8 9 Ellipse c2 Ellipse c2.setColor(Color.YELLOW); Ellipse c2.fil1(); 10 = new Ellipse(30,70,20,20); 11 12 13 = new Ellipse(30,100,20,20); Ellipse c3 Ellipse c3.setColor(Color.GREEN; Ellipse c3.fill(); 16 17 18 } 19 LO O 4 56 709

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Help me fix this code I tried to make the traffic light like the traffic light on the picture.
1 public class TrafficLightViewer
2 {
3.
public static void main(String[] args)
4
Rectangle rl = new Rectangle(50,20,20,60);
Ellipse cl
Ellipse cl.setColor(Color.RED);
Ellipse cl.fil);
= new Ellipse(30,40,20,20);
7
8
9
= new Ellipse(30,70,20,20);
Ellipse c2
Ellipse c2.setColor(Color.YELLOW);
Ellipse c2.fil1();
10
11
12
13
= new Ellipse(30,100,20,20);
Ellipse c3
Ellipse c3.setColor(Color.GREEN;
Ellipse c3.fill();
}
16
17
18
}
19
456 7 0 9
Transcribed Image Text:1 public class TrafficLightViewer 2 { 3. public static void main(String[] args) 4 Rectangle rl = new Rectangle(50,20,20,60); Ellipse cl Ellipse cl.setColor(Color.RED); Ellipse cl.fil); = new Ellipse(30,40,20,20); 7 8 9 = new Ellipse(30,70,20,20); Ellipse c2 Ellipse c2.setColor(Color.YELLOW); Ellipse c2.fil1(); 10 11 12 13 = new Ellipse(30,100,20,20); Ellipse c3 Ellipse c3.setColor(Color.GREEN; Ellipse c3.fill(); } 16 17 18 } 19 456 7 0 9
Create a class TrafficLightViewer, then write the main() method to draw a traffic light
as shown below:
The rectangle has the default color, Color.BLACK, its upper-left conner is at (50, 20), its width is
20 and height is 60. The three circles has different colors, Color.RED, Color.YELLOW and
Color.GREEN, from the top. The circles have the same radius and will touch the sides of the
rectangle and each other.
Create Ellipse objects with the same width and height to get the circles, then call method
setColor() to get the required color before calling method fill). For the rectangle, you don't need
to call method setColor(), since it has the default color, but you need to call method draw()
instead of method fill().
You should figure out the locations and radius of circles before writing the code.
You can use magic numbers for the locations and sizes for the rectangle and the circles, but must
use the pre-defined color constants Color.RED, Color. YELLOW and Color.GREEN.
Transcribed Image Text:Create a class TrafficLightViewer, then write the main() method to draw a traffic light as shown below: The rectangle has the default color, Color.BLACK, its upper-left conner is at (50, 20), its width is 20 and height is 60. The three circles has different colors, Color.RED, Color.YELLOW and Color.GREEN, from the top. The circles have the same radius and will touch the sides of the rectangle and each other. Create Ellipse objects with the same width and height to get the circles, then call method setColor() to get the required color before calling method fill). For the rectangle, you don't need to call method setColor(), since it has the default color, but you need to call method draw() instead of method fill(). You should figure out the locations and radius of circles before writing the code. You can use magic numbers for the locations and sizes for the rectangle and the circles, but must use the pre-defined color constants Color.RED, Color. YELLOW and Color.GREEN.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education