Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Start with program DNAGenerator . Using RandomColorsSwitch, modify the code by replacing the IF statement with a SWITCH statement. I am sending you the DNA

Start with program DNAGenerator.

Using RandomColorsSwitch, modify the code by replacing the IF statement with a SWITCH statement.

I am sending you the DNA generator and random color codes.modify it according to question above please send me.

DNA Generator code

import objectdraw.*; import java.awt.*; public class DNAGenerator extends WindowController { // Coordinates of Text objects private static final int LEFT_MARGIN = 15; private static final int MESSAGE_Y = 15; private static final int STRAND_Y = 60; // Maximum number of bases in strand private static final int LIMIT = 20; // Displays DNA strand private Text strandDisp; // The DNA strand private String strand; // Random number generated by gen private int randNum; private RandomIntGenerator gen = new RandomIntGenerator( 1, 4 ); // Create Text displays public void begin() { strand = ""; new Text( "Click to generate DNA!", LEFT_MARGIN, MESSAGE_Y, canvas ); strandDisp = new Text( strand, LEFT_MARGIN, STRAND_Y, canvas ); } // Add random part to DNA strand as long as it is not too long public void onMouseClick( Location point ) { if ( strand.length() < 2*LIMIT ) { randNum = gen.nextValue(); if (randNum == 1) { strand = strand + " G"; } else if (randNum == 2) { strand = strand + " A"; } else if (randNum == 3) { strand = strand + " T"; } else { strand = strand + " C"; } strandDisp.setText( strand ); } } } 

Random Color code

import objectdraw.*; import java.awt.*; // This program allows the user to draw lines of randomly chosen colors on the screen // using the mouse as if it were a pencil public class RandomColors extends WindowController{ private Location lastPoint; // location where mouse was last pressed private Color currentColor; // current color for scribbling private int colorNumber; // random int generated for color selection // a random number generator that generates random numbers // between 1 and 4 (inclusive) RandomIntGenerator pickAColor = new RandomIntGenerator(1,4); // remember point of press // generate a random color with which lines will be drawn public void onMousePress(Location point) { lastPoint = point; colorNumber = pickAColor.nextValue(); if (colorNumber == 1) { currentColor = Color.RED; } else if ( colorNumber == 2) { currentColor = Color.BLUE; } else if ( colorNumber == 3 ) { currentColor = Color.MAGENTA; } else { currentColor = Color.GREEN; } } // draws a line with the random color selected at the time of mouse press public void onMouseDrag(Location point) { new Line( lastPoint, point, canvas).setColor( currentColor); lastPoint = point; } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

Describe the signs of poor listening.

Answered: 1 week ago