Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with these! Tried it again and again, but I keep getting errors. This needs to be coded in Java through NetBeans. This

I need help with these! Tried it again and again, but I keep getting errors. This needs to be coded in Java through NetBeans.

This is what I have for my code so far, please tell me where I went wrong

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

package Isho_Hwk2;

import static javafx.application.Application.launch; import javafx.scene.Group; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.shape.Rectangle; import javafx.scene.paint.Color; import javafx.scene.text.Text;

/** * * @author donovanisho */ public class Isho_Hwk2 { public void start(Stage primaryStage) throws Exception{ GetRandomValues object1 = new GetRandomValues(50,100,120,140,"ORANGE"); Text textObject1 = new Text();

textObject1.setX(50); textObject1.setY(50);

textObject1.setText(object1.toString());

Rectangle rectangle1 = new Rectangle(object1.getWidth(),object1.getHeight(),object1.getNewColor()); rectangle1.setX(textObject1.getX()); rectangle1.setY(textObject1.getY()+50);

GetRandomValues object2 = new GetRandomValues(50,100,120,140,"BLUE"); Text textObject2 = new Text();

textObject2.setX(object1.getWidth()+150); textObject2.setY(50);

textObject2.setText(object2.toString());

Rectangle rectangle2 = new Rectangle(object2.getWidth(),object2.getHeight(),object2.getNewColor()); rectangle2.setX(textObject2.getX()); rectangle2.setY(textObject2.getY()+50);

GetRandomValues object3 = new GetRandomValues(50,100,120,140,""); Text textObject3 = new Text();

textObject3.setX(object1.getWidth() + object2.getWidth() + 250); // we used width of 1st and 2nd rectangles to maintain the proper position. textObject3.setY(50);

textObject3.setText(object3.toString());

Rectangle rectangle3 = new Rectangle(object3.getWidth(),object3.getHeight(),object3.getNewColor()); rectangle3.setX(textObject3.getX()); rectangle3.setY(textObject3.getY()+50);

Group group = new Group();

group.getChildren().add(textObject1); group.getChildren().add(rectangle1); group.getChildren().add(textObject2); group.getChildren().add(rectangle2); group.getChildren().add(textObject3); group.getChildren().add(rectangle3);

Scene scene = new Scene(group, 1000, 1000);

primaryStage.setTitle("Isho D : Homework2");

primaryStage.setScene(scene);

primaryStage.show(); }

public static void main(String[] args) { launch(args); }

public static class GetRandomValues{ private final Color newColor; private final String colorName; private final int width; private final int height;

public GetRandomValues(int minWid, int maxWid, int minHt, int maxHt, String clr){ this.width = (int) ((Math.random() * (maxWid - minWid)) + minWid); this.height = (int) ((Math.random() * (maxHt - minHt)) + minHt); switch (clr) { case "ORANGE": colorName = clr; newColor = Color.ORANGE; break; case "BLUE": colorName = clr; newColor = Color.BLUE; break; default: colorName = "GREEN"; newColor = Color.GREEN; break; } }

public Color getNewColor() { return newColor; }

public String getColorName() { return colorName; }

public int getWidth() { return width; }

public int getHeight() { return height; }

@Override public String toString() { return "Width : " + this.width + " Height : " + this.height + " Color : " + this.colorName; } } }

image text in transcribedimage text in transcribedimage text in transcribed

Instructions Use this UML to create your object GetRandom Values newColor: Color - colorName: String - width: int - height: int + public GetRandom Values(int min Wid, int max Wid, int minllt, int max Ht, String clr) +getNewColor() Color + getColorName( String +get Width() int + getHeight (int I toString0 String 1) Create a GetRandomValues Class a) Create private data members using the UML above b) Write a Constructor for your class i) The Arguments mean (1) int min Wid, minimum width of a rectangle (2) int max Wid, maximum width of a rectangle (3) int minHt, minimum height of a rectangle (4) int max Ht, maximum height of a rectangle (5) String clr, This is a string representing the rectangle color. You should pick two valid color names you will accept for your program, like ORANGE and BLUE ii) Generate a random int in range [min Wid,max Wid) and update width data member Generate a random int in range (minHt,max Ht] and update height data member iv) Update the colorName dala member with clr v) Use an if/else structure to assign a value to newColor. vi) Example (Use colors different than mine) (1) if clr is "ORANGE" then (a) new Color - Color. ORANGE (2) else if clr is BLUE then (a) newColor = Color.BLUE (3) else if the user didn't enter one of your two color name then (a) assign colorName a color you pick (b) sel new Color to the actual color you pick c) Write get methods for newColor, colorName, width and height d) Write a toString() method. Only add the colorName to the output string, and not the new Color value as shown in example output 2) the start() method of a JavaFX application should a) Create 3 GetRandomValues objects by repeating the following 3 lines 3 times with different variable names, and adjust the X and Y values for the text objects and rectangle objects so they line up in a row. Don't worry about centering, just made them far enough apart so they don't overlap i) Create a GetRandomValues object, passing it values as described above. For the color string pass one of the valid colors you identified in your class. (Use the two valid colors strings and an invalid color for each object.) Make sure your min values are less than your max values. ii) Example GetRandomValues x = new GetRandomValues (50, 100, 120, 140, "ORANGE"); Create a Text object with values for x, y, and for the string argument pass the results of the toString() method you wrote for your GetRandomValues Class iv) Create a Rectangle object, with values for x, y, value returned from getWidth() method, return value returned from getHeight() method. Set the color with the value returned from the getNewColor() method. b) Add your Text and Rectangle objects to a Group, add Group object to a Scene object, and add Scene object to the primaryStage object. c) Set primaryStage title to include your full name and Homework 2 d) Show the stage. Example Output Width: 125 width: 265 wigot 113 Height:72 width: 104 Height:20 Color: AQUA Colon HOTPINK Colon GREEN

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

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago

Question

1. Who will you assemble on the team?

Answered: 1 week ago

Question

4. Who would lead the group?

Answered: 1 week ago