Question

Write a program which will Ask the user a series of questions using the Scanner object Based on the input, draw a grid of sta

Example User Input #1: ·Color: R = 70, G = 70, B = 70 10 stars across 2 stars tall Output: Drawing Panel File View Help x-152

Example User Input #2: ·Color: R = 0, G = 255, B = 100 8 stars across 8 stars tall Output: Drawing Panel File View Help x= 12

Example User Input #3: Color: R 0, G O, B 150 . 4 stars across . 5 stars tall Output: Lej Dra...- File View Help x=51, y=0),

Update, Replace or Add to This Code to get started *Before you can run the code below, you will have to save DrawingPanel.jav

Write a program which will Ask the user a series of questions using the Scanner object Based on the input, draw a grid of star figures on the DrawingPanel You program should ask your user: . What R, G & B values to create a color to draw the figure? How many stars across should the fgure be? How many stars tall should the figure be? Note that your program does not need to error check the users responses Your program can assume the user is inputting the correct data format Based on this input your program should: Set the color of the graphics object, g, with a new color created by the R G B values Draw a grid of star figures (explained in starter code) The DrawingPanel should be the exact size needed to draw the grid Each star figure is 50 pixels wide and 50 pixels tall For example, if the user specifies 3x3, the panel should be 150px by 150px . You may find that your panel has a minimum width of 100px - don't worry about this
Example User Input #1: ·Color: R = 70, G = 70, B = 70 10 stars across 2 stars tall Output: Drawing Panel File View Help x-152, y-1),r-255 g-255 b-255
Example User Input #2: ·Color: R = 0, G = 255, B = 100 8 stars across 8 stars tall Output: Drawing Panel File View Help x= 128, y= 12), r-255 g-255 b-255
Example User Input #3: Color: R 0, G O, B 150 . 4 stars across . 5 stars tall Output: Lej Dra...- File View Help x=51, y=0), r=255 g=255 b-255
Update, Replace or Add to This Code to get started *Before you can run the code below, you will have to save DrawingPanel.java in the same project folder: DrawingPanel.java import java.awt.Graphics; import java.awt.Color; import java.util.Scanner * Homework #2: * Update, replace, or add to this code * to form your solution public class HWO2_Starter_Code t public static DrawingPanel canvas; public static Graphics g; k A * This method creates a panel of size * 200x200. Your panel will have to vary * based on the user's input public static void main(Stringl] args) t canvas new DrawingPanel (200, 200); g canvas.getGraphics) star) * This method draws five lines to * create a star shape. The star is drawn * in the top left corner of the panel. public static void star) g. drawLine(0,15,50,15); g. drawLine(50,15,7, 50); g. drawLine(7, 50, 25, 0); g. drawLine(25, 0, 43, 50); g. drawLine(43, 50, 0, 15);
0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.awt.Graphics;
import java.awt.Color;
import java.util.*;




public class HW02_Starter_Code
{
    public static DrawingPanel canvas;
    public static Graphics g;

    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int R,G,B,s_across,s_tall;
        int x=0;int y=15;

        System.out.println("Enter RGB codes");
        R=sc.nextInt();
        G=sc.nextInt();
        B=sc.nextInt();
        System.out.println("How many stars across");
        s_across=sc.nextInt();
        System.out.println("How many stars tall");
        s_tall=sc.nextInt();

        canvas = new DrawingPanel(s_across*50,s_tall*50);
        g = canvas.getGraphics();
        g.setColor(new Color(R,G,B));
        for(int i=0;i<=s_across*50;i++)
        {

            for(int j=0;j<=s_tall*50;j++)
            {
                star(x,y);
                x=x+50;


            }
            y=y+50;
            x=0;

        }


    }
    public static void star(int x,int y)
    {
        g.drawLine(x,y,x+50,y);
        g.drawLine(x+50,y,x+7,y+35);
        g.drawLine(x+7,y+35,x+25,y-15);
        g.drawLine(x+25,y-15,x+43,y+35);
        g.drawLine(x+43,y+35,x,y);

    }

}

// compile and run and remember it needs DrawingPanel.java to run//

//run this file while having this and DrawingPanel.java is one folder//

//Compiled ,executed and tested //

Add a comment
Know the answer?
Add Answer to:
Write a program which will Ask the user a series of questions using the Scanner object Based on t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • User Profiles Write a program that reads in a series of customer information -- including name,...

    User Profiles Write a program that reads in a series of customer information -- including name, gender, phone, email and password -- from a file and stores the information in an ArrayList of User objects. Once the information has been stored, the program should welcome a user and prompt him or her for an email and password The program should then use a linearSearch method to determine whether the user whose name and password entered match those of any of...

  • With your partner, brainstorm a program that will ask the user for a number of digits...

    With your partner, brainstorm a program that will ask the user for a number of digits to be stored. The program should then create an array of that size and then prompt the user for numbers to fill each position in the array. When all of the positions are filled, display the contents of the array to the user. Create a new Project named FillArray and a new class in the default packaged named FillArray.java. You and your partner should...

  • Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles....

    Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles. You will need to define a Triangle class containing a single instance variable, representing the length of one of the triangle’s sides. Have the program create circles, rectangles, and triangles with equal probability. Circle and Rectangle is done, please comment on your methods so i can understand */ package NervousShapes; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class...

  • Write a JAVA program that prompts the user for student grades and displays the highest and...

    Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values. Starter code: import java.util.Scanner; public class MaxMinGrades{   public static void main(String[] args){     Scanner input = new Scanner(System.in);     System.out.println("Enter as many student grades as you like. Enter a character to stop.");     double grade = input.nextDouble();     double minGrade = Double.MAX_VALUE;     double maxGrade = Double.MIN_VALUE;     while (Character.isDigit(grade)) {       if (grade == 0)...

  • Write a program that will check a Java file for syntax errors. The program will ask...

    Write a program that will check a Java file for syntax errors. The program will ask for an input-file name and output-file name and will then copy all the code from the Java input file to the Java output file, but with the following changes: 1. Any syntax error found in the Java input file will be corrected: a. Missing semicolon b. Missing compound statements (curly braces) c. All comments have to start with // and end with a period....

  • So i need help with this program, This program is supposed to ask the user to...

    So i need help with this program, This program is supposed to ask the user to input their weight on earth so I would put "140" then it would ask "enter planet name, Min, Max or all" and if the user typed in all it would display all the planets and your weight on them. Right now Im suck on the part where im required to do a switch statement with a linear search. Below this im going to put...

  • Write an expression that executes the loop while the user enters a number greater than or...

    Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds,...

  • ***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*;...

    ***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class DrawingPanel implements ActionListener { public static final int DELAY = 50; // delay between repaints in millis private static final String DUMP_IMAGE_PROPERTY_NAME = "drawingpanel.save"; private static String TARGET_IMAGE_FILE_NAME = null; private static final boolean PRETTY = true; // true to anti-alias private static boolean DUMP_IMAGE = true; // true to write DrawingPanel to file private int width, height; // dimensions...

  • Question 4 (3 mark) : Write a Java program to ask the user to input an...

    Question 4 (3 mark) : Write a Java program to ask the user to input an integer number from the keyboard. The output should indicate whether it is positive, zero, or negative, an even number or an odd number. REQUIREMENTS • Your code should ask user to input an integer number, then decide its sign and parity based on this input. • Your code should use if-else statement. Your code must work exactly as the specification and the output should...

  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT