Notes
Notes - notes.io |
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package clientlight;
import java.util.HashMap;
import java.awt.Color;
interface IShapeInterface{
public void draw(String graphicType, int x, int y, int width, int height, String color, boolean fill);
}
class rectangle implements IShapeInterface{
public void draw(String graphicType, int x, int y, int width, int height, String color, boolean fill){
System.out.println("Shape drawn with following parameters: X:" + x + "Y: " + y + "Width: " + width + "Height: " + height + "Color: " + color + "Fill: " + fill + "Type: " + "R" );
}
}
class square implements IShapeInterface{
public void draw(String graphicType, int x, int y, int width, int height, String color, boolean fill){
System.out.println("Shape drawn with following parameters: X:" + x + "Y: " + y + "Width: " + width + "Height: " + height + "Color: " + color + "Fill: " + fill + "Type: " + "S" );
}
}
class triangle implements IShapeInterface{
public void draw(String graphicType, int x, int y, int width, int height, String color, boolean fill){
System.out.println("Shape drawn with following parameters: X:" + x + "Y: " + y + "Width: " + width + "Height: " + height + "Color: " + color + "Fill: " + fill + "Type: " + "T" );
}
}
class circle implements IShapeInterface{
public void draw(String graphicType, int x, int y, int width, int height, String color, boolean fill){
System.out.println("Shape drawn with following parameters: X:" + x + "Y: " + y + "Width: " + width + "Height: " + height + "Color: " + color + "Fill: " + fill + "Type: " + "C" );
}
}
class oval implements IShapeInterface{
public void draw(String graphicType, int x, int y, int width, int height, String color, boolean fill){
System.out.println("Shape drawn with following parameters: X:" + x + "Y: " + y + "Width: " + width + "Height: " + height + "Color: " + color + "Fill: " + fill + "Type: " + "O" );
}
}
class parallelogram implements IShapeInterface{
public void draw(String graphicType, int x, int y, int width, int height, String color, boolean fill){
System.out.println("Shape drawn with following parameters: X:" + x + "Y: " + y + "Width: " + width + "Height: " + height + "Color: " + color + "Fill: " + fill + "Type: " + "P" );
}
}
class hexagon implements IShapeInterface{
public void draw(String graphicType, int x, int y, int width, int height, String color, boolean fill){
System.out.println("Shape drawn with following parameters: X:" + x + "Y: " + y + "Width: " + width + "Height: " + height + "Color: " + color + "Fill: " + fill + "Type: " + "H" );
}
}
class sphere implements IShapeInterface{
public void draw(String graphicType, int x, int y, int width, int height, String color, boolean fill){
System.out.println("Shape drawn with following parameters: X:" + x + "Y: " + y + "Width: " + width + "Height: " + height + "Color: " + color + "Fill: " + fill + "Type: " + "SP" );
}
}
class ShapeFactory{
public static HashMap<String, IShapeInterface> m = new HashMap<String, IShapeInterface>();
public static IShapeInterface getShape(String label){
IShapeInterface i = null;
if(m.get(label) != null){
i = m.get(label);
}
else{
switch(label){
case "rc":
i = new rectangle();
break;
case "sq":
i = new square();
break;
case "pa":
i = new parallelogram();
break;
case "sp":
i = new sphere();
break;
case "he":
i = new hexagon();
break;
case "tr":
i = new triangle();
break;
case "ci":
i = new circle();
break;
case "ov":
i = new oval();
break;
}
m.put(label, i);
}
return i;
}
}
class ClientLight {
private static final int WIDTH = 1800, HEIGHT = 1600;
//rc=rectangle, tr=triangle, sq=square, ci=circle, ov=oval, pa=parallelogram, he=hexagon, sp=sphere
private static final String shapes[] = { "rc", "tr", "sq", "ci", "ov", "pa", "he", "sp"};
private static final Color colors[] = { Color.red, Color.green, Color.blue, Color.darkGray };
private static final String COLORS[] = { "red","green","blue","darkGray"};
private static final boolean fill[] = { true, false };
private ShapeFactory sf;
public ClientLight() {
int i;
for(i = 0; i < 1000; ++i) {
//Your code for ShapeFactory and generating random values for different variables
sf = new ShapeFactory();
IShapeInterface ish = sf.getShape(getRandomShape());
ish.draw("2-D", getRandomX(), getRandomY(), getRandomWidth(), getRandomHeight(), getRandomColor(), getRandomFill());
}
}
private String getRandomShape() {return shapes[(int) (Math.random() * shapes.length)];}
private int getRandomX() {return (int) (Math.random() * WIDTH*0.9);}
private int getRandomY() {return (int) (Math.random() * HEIGHT*0.8);}
private int getRandomWidth(){return (int) (Math.random() * (WIDTH / 7));}
private int getRandomHeight() {return (int) (Math.random() * (HEIGHT / 7));}
private String getRandomColor() {return COLORS[(int) (Math.random() * COLORS.length)];}
private boolean getRandomFill() {return fill[(int) (Math.random() * fill.length)];}
public static void main(String[] args) {
ClientLight client = new ClientLight();
System.out.println("Size of Hashmap" + client.sf.m.size());
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team