Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package two;
- import java.util.Scanner;
- public class zadacha_02 {
- public static void main(String[] args) {
- Scanner input=new Scanner(System.in);
- ColorRectangle rect=new ColorRectangle();
- ColorRectangle rect1=new ColorRectangle();
- System.out.println(rect.toString());
- System.out.println(rect1.toString());
- System.out.println("Enter number to translate X and Y: ");
- rect.translateXY(input.nextInt());
- System.out.println(rect.toString());
- System.out.println(rect.equals(rect1));
- System.out.println(rect.intersectionRect(rect1));
- System.out.println(rect.intersectionRect(rect1).Area());
- System.out.println(rect.unionRect(rect1));
- System.out.println(rect.unionRect(rect1).Area());
- System.out.println("Insert two values for X and Y: ");
- System.out.println(rect.isInside(input.nextInt(), input.nextInt()));
- Color color=new Color();
- System.out.println("Value of R is: "+color.getRValue());
- System.out.println("Value of G is: "+color.getGValue());
- System.out.println("Value of B is: "+color.getBValue());
- }
- }
- class Console
- {
- static String a, b;
- public static Long readLine()
- {
- Scanner input=new Scanner(System.in);
- a=input.next();
- long a1=Long.parseLong(a);
- return a1;
- }
- public static int readLineInt()
- {
- Scanner input=new Scanner(System.in);
- b=input.next();
- int b1=Integer.parseInt(b);
- return b1;
- }
- }
- class Color implements Comparable<Color>
- {
- private long RValue, GValue, BValue, RGBValue;
- Color()
- {
- System.out.println("Insert Value of R:");
- RValue=Console.readLine();
- System.out.println("Insert Value of G:");
- GValue=Console.readLine();
- System.out.println("Insert Value of B:");
- BValue=Console.readLine();
- }
- public void setRValue(long RValue)
- {
- this.RValue=RValue;
- }
- public long getRValue()
- {
- return RValue;
- }
- public void setGValue(long GValue)
- {
- this.GValue=GValue;
- }
- public long getGValue()
- {
- return GValue;
- }
- public void setBValue(long BValue)
- {
- this.BValue=BValue;
- }
- public long getBValue()
- {
- return BValue;
- }
- public long getRGBValue()
- {
- return this.RGBValue=256*256*getRValue()+256*getGValue()+1*getBValue();
- }
- public String toString()
- {
- return ("Value of Red is: "+this.RValue+" "+"Value of Green is: "+this.GValue+" "+"Value of Blue is: "+this.BValue+" "+"Value of Total is: "+getRGBValue());
- }
- public boolean equals(long r)
- {
- if (this.RGBValue==r)
- return true;
- else
- return false;
- }
- @Override
- public int compareTo(Color arg0) {
- if (this.RGBValue<arg0.RGBValue) {
- return -1;
- }
- if (this.RGBValue==arg0.RGBValue) {
- return 0;
- }
- return 1;
- }
- }
- class ColorRectangle
- {
- private int iX1, iY1, iX2, iY2;
- ColorRectangle()
- {
- System.out.println("Insert Value of iX1:");
- iX1=Console.readLineInt();
- System.out.println("Insert Value of iX2:");
- iX2=Console.readLineInt();
- System.out.println("Insert Value of iY1:");
- iY1=Console.readLineInt();
- System.out.println("Insert Value of iY2:");
- iY2=Console.readLineInt();
- }
- public ColorRectangle(int x1, int y1, int x2, int y2)
- {
- this.iX1=x1;
- this.iY1=y1;
- this.iX2=x2;
- this.iY2=y2;
- }
- public int getIX1()
- {
- return iX1;
- }
- public int getIY1()
- {
- return iY1;
- }
- public int getIX2()
- {
- return iX2;
- }
- public int getIY2()
- {
- return iY2;
- }
- public void setIX1(int x1)
- {
- this.iX1=x1;
- }
- public void setIX2(int x2)
- {
- this.iX2=x2;
- }
- public void setIY1(int y1)
- {
- this.iY1=y1;
- }
- public void setIY2(int y2)
- {
- this.iY2=y2;
- }
- public String toString()
- {
- return ("X1:"+this.iX1+" X2:"+this.iX2+" Y1:"+this.iY1+" Y2:"+this.iY2);
- }
- public int Area()
- {
- return (iX2-iX1)*(iY2-iY1);
- }
- public boolean equals(ColorRectangle r)
- {
- if(this.iX1==r.iX1 && this.iX2==r.iX2 && this.iY1==r.iY1 && this.iY2==r.iY2)
- return true;
- else
- return false;
- }
- public void translateX(int iPoints)
- {
- this.iX1+=iPoints;
- this.iX2+=iPoints;
- }
- public void translateY(int iPoints)
- {
- this.iY1+=iPoints;
- this.iY2+=iPoints;
- }
- public void translateXY(int iPoints)
- {
- this.iX1+=iPoints;
- this.iX2+=iPoints;
- this.iY1+=iPoints;
- this.iY2+=iPoints;
- }
- public boolean isInside(int ptX, int ptY )
- {
- if((ptX>=this.iX1 && ptX<=this.iX2) && (ptY>=this.iY1 && ptY<=this.iY2))
- return true;
- else
- return false;
- }
- public int compareTo(ColorRectangle r)
- {
- if(this.Area()-r.Area()<0)
- return -1;
- if(this.Area()-r.Area()==0)
- return 0;
- return 1;
- }
- public ColorRectangle unionRect(ColorRectangle r)
- {
- return new ColorRectangle((this.iX1<r.iX1) ? this.iX1:r.iX1, (this.iY1<r.iY1) ? this.iY1:r.iY1, (this.iX2>r.iX2) ? this.iX2:r.iX2, (this.iY2>r.iY2) ? this.iY2:r.iY2);
- }
- public ColorRectangle intersectionRect(ColorRectangle r)
- {
- ColorRectangle result = new ColorRectangle((this.iX1>r.iX1) ? this.iX1:r.iX1, (this.iY1>r.iY1) ? this.iY1:r.iY1, (this.iX2<r.iX2) ? this.iX2:r.iX2, (this.iY2<r.iY2) ? this.iY2:r.iY2);
- if (result.iX1>result.iX2) { result.iX1 = result.iX2 = 0; }
- if (result.iY1>result.iY2) { result.iY1 = result.iY2 = 0; }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement