Questions
Java 2D Drawing Application. The application will contain the following elements: a) an Undo button to...

Java 2D Drawing Application.

The application will contain the following elements:

a) an Undo button to undo the last shape drawn.
b) a Clear button to clear all shapes from the drawing.
c) a combo box for selecting the shape to draw, a line, oval, or rectangle.
d) a checkbox which specifies if the shape should be filled or unfilled.
e) a checkbox to specify whether to paint using a gradient.
f) two JButtons that each show a JColorChooser dialog to allow the user to choose the first and second color in the gradient.
g) a text field for entering the Stroke width.
h) a text field for entering the Stroke dash length.
I) a checkbox for specifying whether to draw a dashed or solid line.
j) a JPanel on which the shapes are drawn.
k) a status bar JLabel at the bottom of the frame that displays the current location of the mouse on the draw panel.

If the user selects to draw with a gradient, set the Paint on the shape to be a gradient of the two colors chosen by the user. If the user does not chose to draw with a gradient, then Paint with a solid color of the 1st Color. The following code can create a gradient paint object:
Paint paint = new GradientPaint(0, 0, color1, 50, 50, color2, true);

To set the stroke for a line to be drawn, you can use the following code:

            if (dashCheckBox.isSelected())
            {
                stroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10, dashLength, 0);
            } else
            {
                stroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
            }

Where the first stroke line creates a dashed line and dashLength is a one element float array with the dash length in the first element. The second stroke line creates an undashed line with the line width specified from the GUI.

Note: When dragging the mouse to create a new shape, the shape should be drawn as the mouse is dragged.

A template project has been provided for you in Canvas in Java2DDrawingApplicationTemplate.zip. This project contains a MyShapes hierarchy that is a complete shape hierarchy for drawing a line, rectangle or oval. You must use this MyShapes hierarchy. A template for the Drawing Application Frame is also provided along with a template for the DrawPanel inner class. You do not need to use these templates if you so choose.

In the paintComponent(Graphics g) method of the DrawPanel, to loop through and draw each shape created by the user, you will loop through an ArrayList of MyShapes, that you built, and call the draw(Graphics2D g2d) method for each shape. The draw method is already implemented in the MyShapes hierarchy.

Note: You do not need to create an event handler for each component in the top two lines of the frame. You only need to create event handlers for the buttons. You can get the values out of all the other components in the top two lines, when the user presses the mouse button on the DrawPanel. At that time, you have all the information you need to create a new Myshapes object.

Note: Do not use the NetBeans GUI generator for this assignment.

-------------------------------------------------------------------- PLEASE USE THE FOLLOWING FILES!!! -----------------------------------------------------------------------

https://drive.google.com/file/d/1wiRjRNrunGPYMeWD2qM7Zgj6H0jg_SAa/view?usp=sharing

Thank you!

In: Computer Science

The verticies of ABC are A(2,4), B (7,6) and C(5,2) give the correct composition of the...

The verticies of ABC are A(2,4), B (7,6) and C(5,2) give the correct composition of the matricies for the image of ABC after the given composition of the transformations in the order listed(show what it would be for each vertex)

First Translation: (x, y) -> (x-2,y-3)

Second Rotation: 75 degrees about the pivot popoint (1,3)

In: Computer Science

C++ Programming The following program reads the sentences in "fdata.txt" and stores each word in a...

C++ Programming
The following program reads the sentences in "fdata.txt" and stores each word in a word vector starting with the first letter.
Fill in the blanks.

#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>


using namespace std;

class SVector
{
public:
int size;
int idx;
char x;
string *sptr;
// (a)
void insert(string s);
void print();
};

SVector::SVector(char c, int size)
{
x = c;
idx = 0;
this->size = size;
//(b)
}
void SVector::insert(string s)
{
//(c)
}
void SVector::print()
{
if(idx != 0){
cout << "starting with " << x << endl;
for(int i = 0; i < idx; i++){
cout << sptr[i] << endl;
}
}
}

int main()
{
SVector *sv[26];
string word;
ifstream fin;
fin.open(".\\data\\fdata.txt");
//cout << fin << endl;
if(!fin){
cout << "file not opened" << endl;
return 0;
}

for(int i = 0; i < 26; i++){
char c = 'a' + i;
sv[i] = //(d);
}

while(true){
fin >> word;
if(fin.eof()) break;
int fc = //(e);
sv[fc]->insert(word);
}

for(int i = 0; i < 26; i++){
sv[i]->print();
}
  
return 0;
}

In: Computer Science

i need to find complexity and cost and runtime for each line of the following c++...

i need to find complexity and cost and runtime for each line of the following c++ code :

// A C++ program for Dijkstra's single source shortest path algorithm.
// The program is for adjacency matrix representation of the graph

#include <limits.h>
#include <stdio.h>

// Number of vertices in the graph
#define V 9

// A utility function to find the vertex with minimum distance value, from
// the set of vertices not yet included in shortest path tree
int minDistance(int dist[], bool sptSet[])
{
   // Initialize min value
   int min = INT_MAX, min_index;

   for (int v = 0; v < V; v++)
       if (sptSet[v] == false && dist[v] <= min)
           min = dist[v], min_index = v;

   return min_index;
}

// A utility function to print the constructed distance array
void printSolution(int dist[])
{
   printf("Vertex \t\t Distance from Source\n");
   for (int i = 0; i < V; i++)
       printf("%d \t\t %d\n", i, dist[i]);
}

// Function that implements Dijkstra's single source shortest path algorithm
// for a graph represented using adjacency matrix representation
void dijkstra(int graph[V][V], int src)
{
   int dist[V]; // The output array. dist[i] will hold the shortest
   // distance from src to i

   bool sptSet[V]; // sptSet[i] will be true if vertex i is included in shortest
   // path tree or shortest distance from src to i is finalized

   // Initialize all distances as INFINITE and stpSet[] as false
   for (int i = 0; i < V; i++)
       dist[i] = INT_MAX, sptSet[i] = false;

   // Distance of source vertex from itself is always 0
   dist[src] = 0;

   // Find shortest path for all vertices
   for (int count = 0; count < V - 1; count++) {
       // Pick the minimum distance vertex from the set of vertices not
       // yet processed. u is always equal to src in the first iteration.
       int u = minDistance(dist, sptSet);

       // Mark the picked vertex as processed
       sptSet[u] = true;

       // Update dist value of the adjacent vertices of the picked vertex.
       for (int v = 0; v < V; v++)

           // Update dist[v] only if is not in sptSet, there is an edge from
           // u to v, and total weight of path from src to v through u is
           // smaller than current value of dist[v]
           if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX
               && dist[u] + graph[u][v] < dist[v])
               dist[v] = dist[u] + graph[u][v];
   }

   // print the constructed distance array
   printSolution(dist);
}



In: Computer Science

URGENT JAVA Develop a Java computer program to simulate access control to a system network. The...

URGENT JAVA

Develop a Java computer program to simulate access control to a system network. The username and password authentication mechanism is used as an access control mechanism in this project. The program needs to authenticate the user with their username and hashed password stored in Access Manager User (AMU) file. To create an Access Manager User file, you need to develop a java program that takes username and password as input and then generates a file containing the username, hashed password, and plaintext password. In real world, the plaintext are not saved in the AMU file. However, you need the username and corresponding plaintext password for testing of your main program. The structure of the AMU file is shown in the appendix. Note that this should be done as a separate program. The main program operates in the following manner. It first prompts the user to enter username and password. After the user enters both username and password, it hashes the password and search the AMU file to verify both the user name and password. If the program verifies the username and password, it returns the message “Access Granted.” If the programcould not verify the username, it returns the message “Access Denied. You are not a registered user.” If the program verifies the username but not the password, it prompts the user to enter the password again. If the user enter the password three times incorrectly, the system locks the user account and gives this message. “You exceeded entering the allowablenumber of incorrect password. Your account is locked. Contact system administrator to unlock your account”

In: Computer Science

What are the key activities performed in the implementation phase and how are they connected in...

What are the key activities performed in the implementation phase and how are they connected in project management?

In: Computer Science

IN JAVA Step 1 Develop the following interface: Interface Name: ImprovedStackInterface Access Modifier: public Methods Name:...

IN JAVA

Step 1 Develop the following interface: Interface Name: ImprovedStackInterface Access Modifier: public Methods Name: push Access modifier: public Parameters: item (data type T, parameterized type) Return type: void Throws: StackFullException Name: push Access modifier: public Parameters: item1 (data type T, parameterized type), item2 (data type T, parameterized type) Return type: void Throws: StackFullException Name: pop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Name: doublePop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Name: top Access modifier: public Parameters: none Return type: T (parameterized type) Throws: StackEmptyException Step 2 Develop the following class: Class Name: StackFullException Access Modifier: public Extends: Exception Constructors Name: StackFullException Access modifier: public Parameters: none (default constructor) Task: makes a call to the default constructor of its superclass Name: StackFullException Access modifier: public Parameters: message (datatype String) Task: makes a call to the constructor of its superclass by passing the parameter message to it Step 3 Develop the following class: Class Name: StackEmptyException Access Modifier: public Extends: Exception Constructors Name: StackEmptyException Access modifier: public Parameters: none (default constructor) Task: makes a call to the default constructor of its superclass Name: StackEmptyException Access modifier: public Parameters: message (datatype String) Task: makes a call to the constructor of its superclass by passing the parameter message to it Step 4 Develop the following class: Class Name: ImprovedArrayBasedStack Access Modifier: public Implements: ImprovedStackInterface Instance variables Name: top Access modifier: private Data type: int Name: stack Access modifier: private Data type: T[] (an array of parameterized type) Constructors Name: ImprovedArrayBasedStack Access modifier: public Parameters: none (default constructor) Task: sets the value of top to -1 sets the stack to refer to an array of Objects with 100 elements which are type cast to T[] Name: ImprovedArrayBasedStack Access modifier: public Parameters: size (data type int) Task: sets the value of top to -1 sets the stack to refer to an array of Objects with the number of elements equal to the size parameter which are type cast to T[] Methods Name: push Access modifier: public Parameters: item (data type T, parameterized type) Return type: void Throws: StackFullException Task: if the value of top is less than the length of the stack minus 1 then increase the value of top by 1 and place the item at the top of the stack, otherwise throw a StackFullException with the message "Not enough room for one item" Name: push Access modifier: public Parameters: item1 (data type T, parameterized type), item2 (data type T, parameterized type) Return type: void Throws: StackFullException Task: if the value of top is less than the length of the stack minus 2, then increase the value of top by 1 and place item1 at the top of the stack, then increase the value of top by 1 and place item2 at the top of the stack, otherwise throw a StackFullException with the message "Not enough room for two items" Name: pop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Task: if the value of top is greater than -1 then remove the item at the top of the stack by replacing it with null and decrease the value of top by 1, otherwise throw a StackEmptyException with the message "No item to remove" Name: doublePop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Task: if the value of top is greater than 0, then remove the item at the top of the stack by replacing it with null and decrease the value of top by 1, then remove the item at the top of the stack by replacing it with null and decrease the value of top by 1, otherwise throw a StackEmptyException with the message "There are less than two items in the stack" Name: top Access modifier: public Parameters: none Return type: T (parameterized type) Throws: StackEmptyException Task: if the value of top is greater than -1 then return the item at the top of the stack, otherwise throw a StackEmptyException with the message "Top attempted on an empty stack" Step 5 Develop a class with only a main method in it: import java.util.Scanner; public class ImprovedStackDemo { public static void main(String[] args) { /* Inside of this main method do the following: Create an object of the Scanner class that takes input from System.in and refer to this object as keyboard Create a reference to a ImprovedStackInterface called myImprovedStack and have it refer to a new object of the ImprovedArrayBasedStack type passing the value of 6 as an argument to the constructor Open a do/while loop Prompt the user to pick one of the following options: Press 1 to push one item onto the stack Press 2 to push two items onto the stack Press 3 to pop the top of stack Press 4 to pop the top of the stack twice Press 5 to look at the top of the stack Press 6 to end the program Save the user’s input into the option variable if the user picks option 1, prompt the user for what they would like to push onto the stack then save that in a variable called item Open a try block and inside that block call the push method by passing item as a parameter and then close the try block Open a catch block catching StackFullException e and inside this catch block print out the value of message stored in the exception else if the user picks option 2, prompt the user for what they would like to push onto the stack then save that in a variable called item1 Prompt the user for the second item that they would like to push onto the stack and save that in a variable called item2 Open a try block and inside that block call the push method by passing item1 and item 2 as parameters and then close the try block Open a catch block catching StackFullException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 3, Open a try block and call the pop method and close the try block Open a catch block catching StackEmptyException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 4, Open a try block and call the doublePop method and close the try block Open a catch block catching StackEmptyException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 5, Open a try block and print the value returned by the top method and close the try block Open a catch block catching StackEmptyException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 6, display Goodbye. else if the user picks any other option, display Error! close the do/while loop and make it so that it continues to run as long as the user does not pick option 6 */ } }

In: Computer Science

Describe a project, or process, where quality assurance may be one of the most costly activities?...

Describe a project, or process, where quality assurance may be one of the most costly activities? please explain

In: Computer Science

Write a program that takes a string from the user, identifies and counts all unique characters...

Write a program that takes a string from the user, identifies and counts all unique characters in that given string. You are bound to use only built-in string functions where necessary. For identification of unique characters and for counting of the characters make separate functions.

For character identification

Develop a program that takes a string argument, and returns an array containing all unique characters.

For character counting

Develop a program that takes an array returned from above function as an argument along with the given string and return an array containing the total count of each uniquely identified character present in the argument array.

In: Computer Science

1. Write a program that does the following. Write in Assembly Language program Loads your student...

1. Write a program that does the following. Write in Assembly Language program

Loads your student ID number into memory starting at location 0x2000 0100 a. DO NOT do any conversion on your ID number. If my ID number is 123456789, I should be able to read your ID in memory as 123456789 2. Loads the first six characters of your name, in ASSIC, in to memory right after your student ID. Total of 6 bytes. a. This means that you should NOT over write anything that you have already entered. 3. Load from memory location 0x0000 0000 into the registers a. R0 and R1 hold the 64 bits starting at 0x0000 0000 (Total of 2 Words, each of 32 bits) b. R2 holds the next byte (8 bits) data c. R3 holds the next half word (16 bits) d. R4 holds the next word (32 bits) 4. Use the debugger to test your program to make sure that it does what you think it does. Use Lab 1 to help you get started with this

In: Computer Science

1. Competitors The results of a running competition are shown in the table below. Index Name...

1. Competitors

The results of a running competition are shown in the table below.

Index Name Birthdate Rank
0 Am, Erica 1984. 05. 06. 1
1 Abnorm, Al 1982. 09. 30. 3
2 Pri, Mary 1988. 08. 25. 2
3 Duck, Ling 1979. 06. 10. 5
4 Mac, Donald 1992. 04. 05. 4

Find an unfinished program below that contains the appropriate types and the above data in an array. Complete the program, step-by-step, according to the comments.

#include <stdio.h>
 
typedef struct Date {
    int year, month, day;
} Date;
 
typedef struct Competitor {
    char name[31];
    Date birth;
    int rank;
} Competitor;
 
void Date_print(Date d);
 
void Competitor_print(Competitor c);
 
int main() {
    Competitor competitors[5] = {
        { "Am, Erica", {1984, 5, 6}, 1 },
        { "Abnorm, Al", {1982, 9, 30}, 3 },
        { "Pri, Mary", {1988, 8, 25}, 2 },
        { "Duck, Ling", {1979, 6, 10}, 5 },
        { "Mac, Donald", {1992, 4, 5}, 4 },
    };
 
    /* name of competitor 0 - printf %s */
    /* rank of competitor 2 */
    /* birth date of competitor 4, use the given function */
    /* the first letter of the name of competitor 1 (a string is an array of characters) */
    /* is competitor 1 among the best three? yes/no, may use ?: operator */
    /* is competitor 4 faster than competitor 3? */
    /* was competitor 1 born in the same year as competitor 2? */
    /* complete the Competitor_print() function,
     * then print all data of competitor 1 */
    /* at last print all data of all competitors. */
 
    return 0;
}
 
void Date_print(Date d) {
    /* print year, month and day */
}
 
void Competitor_print(Competitor c) {
    /* print all data of the competitor */
}

In: Computer Science

For a Car Rental System, do the following: 1. Decompose the system into 3 components 2....

For a Car Rental System, do the following:

1. Decompose the system into 3 components

2. For each component, write 1-2 lines of Requirement

3. Draw Context Diagram based on the Requirements from #2 above.

4. Draw Level-0 diagram based on the Requirements from #2 above.

In: Computer Science

Compare and contrast Client/Server to Peer-to-Peer networks and which one you would consider to be best...

Compare and contrast Client/Server to Peer-to-Peer networks and which one you would consider to be best for a specific circumstance or context within a metropolitan area and why. Provide at least 3 examples.

In: Computer Science

Explain and provide examples for 5 ways RFIDs can be utilized in a Smart City. How...

Explain and provide examples for 5 ways RFIDs can be utilized in a Smart City. How does this differ from NFC technology? What are at least 3 advantages and disadvantages of NFC; explain reasoning with examples.

In: Computer Science

C++ Pie bakery our bakery makes 8 kinds of pie, and receives orders for these pies...

C++ Pie bakery

our bakery makes 8 kinds of pie, and receives orders for these pies from on-line buyers. The program you’ll write for this lab knows the price of each pie, so as each new order is received, it’s possible to know how much money the bakery should be receiving.

The program must read in lines of input which have two fields: a pie type and a quantity. With this, the program needs to update the quantity of that type of pie, adding the new order to those already received. You already have code that you’ve written for previous labs that uses getline() and splits the line read in into two separate parts: you get to re-use that here, since you have the same work to do – breaking an input string into two substrings, the first is the name of a kind of pie string and the second is the quantity int.

The program you are writing would be part of a larger system used by the bakery to track and schedule its baking. That’s good for you because it means that the input your program reads is guaranteed not to have bogus order numbers or pie types. A sample input line looks like:

raspberry 10

When the program reaches the end of input it prints out, for each type of pie, the quantity ordered and the total price of that number of those pies. After that it prints out the grand total of all orders (total number of pies, total price).

One problem you face is mapping pie types as strings (how you read them in) to the int index of the array element holding the struct for that pie type. For example, you might read in ”apple” and need to figure out that it’s in array element 3. You must use a function to handle this.

To make life a bit easier, you should initialize an array of struct with these pie types and prices:

peach lemon pumpkin blueberry apple raspberry strawberry cherry

$3.75 $4.50 $5.75 $4.25 $3.70 $6.35 $5.65 $5.20

Of course, you’ll need more than just these two fields in your struct.
A sample run with 100 individual pie orders might produce output like this.

Orders for peach:
Orders for lemon:
Orders for pumpkin:
Orders for blueberry:
Orders for apple:
Orders for raspberry:
Orders for strawberry:
Orders for cherry:

115 value is $ 431.25 128 value is $ 576.00 75 value is $ 431.25 75 value is $ 318.75 71 value is $ 262.70 89 value is $ 565.15 122 value is $ 689.30 53 value is $ 275.60

Grand total: 728 pies for $3550.00

You can test your program with data you type in, or on a test data file you create.

In: Computer Science