Question

In: Computer Science

create a java class with name ModernArt: For the first part of the assignment, you will...

create a java class with name ModernArt:

For the first part of the assignment, you will be extending the JApplet class and creating a work of modern using the Graphics class to draw various shapes to the applet window. As part of your masterpiece, you should incorporate the following elements:

  • At least 1 non-solid rectangle
  • At least 1 non-solid oval
  • At least 1 solid oval
  • At least 1 non-solid Polygon
  • At least 1 solid Polygon
  • At least 3 lines
  • At least 3 different colors
  • A caption (a text String) displayed somewhere on your work of art

You may use more elements than the minimal requirements above, but you must use at least that many. There are unit tests for this question that will determine if you have correctly included the required shapes and colors, but there are no tests to judge your work itself as it is not possible to write unit tests which measure the sheer lack of sophistication typically embodied by so much of modern art.

Solutions

Expert Solution

import java.applet.*;
import java.awt.*;
public class GApplet extends Applet
{
   public void paint(Graphics g)
   {
   //x coordinates for polygon
   int x[] = { 10, 30, 40, 50, 110, 140 };
      
       //y coordinates for polygon
int y[] = { 140, 110, 50, 40, 30, 10 };
      
// number of vertices
int numberofpoints = 6;
      
       //Colour is set to red
       g.setColor(Color.RED);
      
       //non-solid rectangle
       g.drawRect(20, 40, 200, 40);
       g.fillRect(300, 40, 200, 40);
      
       //non-solid oval
       g.drawOval(20, 160, 200, 100);
       g.fillOval(300, 160, 200, 100);
      
         
       // non-solid polygon
g.drawPolygon(x, y, numberofpoints);
      
       //line1(red)
       g.drawLine(30, 20, 80, 90);
      
       // set the color to blue
g.setColor(Color.blue);
      
       //solid oval
       draw3Oval(g,Color.blue,30,40,50,true);
      
       //solid polygon
       g.draw3DRect(100,100,50,50,true);
       g.fill3DRect(10,150,50,100,true);
      
       //line2(blue)
       g.drawLine(20, 20, 500, 20);
      
      
       // set the color to orange
       g.setColor(Color.orange);
       //line3 (orange)
       g.drawLine(40, 20, 80, 90);   
      
   }
  
   void draw3DOval(Graphics g, Color bg, int x, int y, int w, int h, boolean raised)
{
Color c = g.getColor();
Color shadow = bg.darker();
Color highlight = bg.brighter();

g.setColor(raised ? highlight : shadow);
g.drawArc(x, y, w, h, 45, 180);
g.setColor(raised ? shadow : highlight);
g.drawArc(x, y, w, h, 225, 180);
g.setColor(c);
}
}


Related Solutions

Create java class with name MyClass1 Instructions for MyClass1 For this portion of the assignment you...
Create java class with name MyClass1 Instructions for MyClass1 For this portion of the assignment you will need to create a java class of your own to model some objects in the real world or your own imagination. your classes should have at least three instances variables, accessor and mutator methods for each of those instance variables, one constructor method of any type, as well as an overridden toString method that will display every field value as part of a...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
java For this assignment, you will create a Time class that holds an hour value and...
java For this assignment, you will create a Time class that holds an hour value and a minute value to represent a time. We will be using "military time", so 12:01 AM is 0001 and 1 PM is 1300. For this assignment, you may assume valid military times range from 0000 to 2359. Valid standard times range from 12:00 AM to 11:59 PM. In previous assignments, we had a requirement that your class be named Main. In this assignment, the...
create a file in java where you can store the first name, last name and the...
create a file in java where you can store the first name, last name and the grade of the student. this will repeats until the answer of the question "are you done?" is.equals (y). then write another program that you can read from this file the student's information . I have dome most of it but my program stores only 1 student's information. WRITE IN FILE public static void main(String[] args) { System.out.println("Enter the file name"); Scanner keyboard=new Scanner(System.in); String...
Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a...
Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a method paycheck() which returns a double. For basic employees, paycheck is always 0 (they just get health insurance). Give the class a parameterized constructor that takes the name; Add a method reportDeposit. This method prints a report for the employee with the original amount of the paycheck, the amount taken out for taxes (we will do a flat 17%), and the final amount (for...
Java: Create a class and name it MyArray and implement following method. * NOTE: if you...
Java: Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items in the...
In Java, Here is a basic Name class. class Name { private String first; private String...
In Java, Here is a basic Name class. class Name { private String first; private String last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Name other) { return this.first.equals(other.first) && this.last.equals(other.last); } } Assume we have a program (in another file) that uses this class. As part of the program, we need to write a method with the following header: public static boolean exists(Name[] names, int numNames, Name name) The goal of...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after a Cat. You should have instance variables as follows: The Cat’s name The number of mice caught by the Cat. Whether or not the Cat is secretly plotting to kill you Note that you will need to choose both good types and meaningful identifiers for each of these instance variables. You may also assume that the Cat is not automatically always secretly plotting to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT