[Java Jobs] Fan, seeking straight intersection, TRIANGLE2D, elective course

Source: Internet
Author: User
Tags abs mul

public class Fan {public static void main (string[] args) {fan fan1 = new Fan (), fan2 = new fan                   ();                   Fan1.modifyspeed (FAST);                   Fan1.modifyradius (10);                   Fan1.modifycolor ("yellow");                   Fan1.modifyon (TRUE);                   System.out.println (Fan1.tostring ());                   Fan2.modifyspeed (MEDIUM);                   Fan2.modifyradius (5);                   Fan2.modifycolor ("Blue");                   Fan2.modifyon (FALSE);         System.out.println (Fan2.tostring ());                   Public Fan () {speed = SLOW;                   on = false;                   RADIUS = 5;         color = "Blue";         } public int GetSpeed () {return speed;         } public boolean Geton () {return on;         } public double Getradius () {return radius; } public String GetColor () {                   return color;         } public void Modifyspeed (int.) {this.speed = speed;         The public void Modifyon (Boolean in) {This.on = on;         } public void Modifyradius (double radius) {This.radius = radius;         The public void Modifycolor (String color) {this.color = color; The public string, toString () {if (on = True) return new String (speed + "+ color +" "+ Radiu                   s);         else return new String ("Fan is off" + "+ Color +" "+ radius);         } final static int SLOW = 1, MEDIUM = 2, FAST = 3;         int speed = SLOW;         Boolean on = false;         Double radius = 5; String color = "Blue";}

Import Java.util.scanner;public class Cross {static line L1, L2;         static Scanner input = new Scanner (system.in); public static void Main (string[] args) {System.out.println ("Enter the endpoints of the first line SEGM                    ENT: ");         L1 = new Line ();         L2 = new Line ();         L1.read ();         System.out.println ("Enter The endpoints of the second line segment:");         L2.read ();         Point ans = getcrosspoint (L1, L2);         System.out.println ("The intersecting point is:" + ans.tostring ());                    public static point Getcrosspoint (line L1, line L2) {Double A = L1.B.Y-L1.A.Y;                    Double b = l1.a.x-l1.b.x;                    Double p = l1.a.x * l1.b.y-l1.b.x * L1.A.Y;                    Double C = l2.b.y-l2.a.y;                    Double d = l2.a.x-l2.b.x;                    Double q = l2.a.x * l2.b.y-l2.b.x * L2.A.Y;               Double U, v;     if (Math.Abs (b * c-a * d) > 1e-10) {v = (p * c-q * a)/(b * c-a * d);                            if (Math.Abs (a) > 1e-10) u = (p-b * v)/A;                    else U = (q-d * v)/C;                            } else {u = (p * d-q * b)/(A * d-c * b);                            if (Math.Abs (b) > 1e-10) v = (P-A * u)/b;                    else V = (Q-C * u)/D;         } return new Point (U, v); public static Class-point {Public-point (Double x, double y) {thi                            s.x = x;                    This.y = y;                    The public point () {x = y = 0;                            } public void Read () {x = Input.nextdouble ();                 y = input.nextdouble ();   } public string toString () {return new string ("(" + x + "," + y + ")");         } double x, y; } public static class line {public line (point A, point B) {THIS.A                            = A;                    this.b = b;                            Public Line () {a = new point ();                    b = new Point ();                       } public void Read () {a.read ();                    B.read ();         } point A, B; }}

public class Triangle2d {public static void main (string[] args) {triangle2d T1 = new Triangle2d (new MyPoint (2.5, 2), new M Ypoint (4.2, 3), New MyPoint (5, 3.5)); System.out.println ("area was:" + t1.getarea () + "\nperimeter is:" + t1.getperimeter ()); System.out.println (T1.contains (New MyPoint (3, 3)); System.out.println (T1.contains (New Triangle2d (New MyPoint (2.9, 2), New MyPoint (4, 1), New MyPoint (1, 3.4))); System.out.println (T1.overlaps (New Triangle2d (New MyPoint (2, 5.5), New MyPoint (4,-3), New MyPoint (2, 6.5)));} Public triangle2d () {p1 = new MyPoint ();p 2 = new MyPoint (1, 1);p 3 = new MyPoint (2, 5);} Public triangle2d (MyPoint p1, mypoint p2, MyPoint p3) {this.p1 = P1;THIS.P2 = P2;THIS.P3 = p3;} Public double Getarea () {Double A = Mypoint.distance (P1, p2);d ouble b = mypoint.distance (P2, p3);d ouble C = Mypoint.distan CE (P3, p1);d ouble p = (A + B + c)/2;return math.sqrt (P * (p-a) * (p-b) * (P-C));} Public double Getperimeter () {Double A = Mypoint.distance (P1, p2);d ouble b = mypoint.distance (P2, p3);d ouble c = mypoint.distance (P3, p1); return a + B + C;} Public boolean contains (MyPoint p) {MyPoint pa = new MyPoint (p1.x-p.x, P1.Y-P.Y); MyPoint PB = new MyPoint (p2.x-p.x, P2.Y-P.Y); MyPoint pc = new MyPoint (p3.x-p.x, p3.y-p.y);d ouble angle = Getangle (PA, Pb) + Getangle (Pb, PC) + Getangle (PC, PA); (Math.Abs (angle) > 1e-5) return True;return false;} Public Boolean contains (Triangle2d t) {return contains (T.P1) && contains (T.P2) && contains (T.P3);} Assume a coordinate system range of [ -10,10]public Boolean overlaps (triangle2d t) {if (contains (t) | | t.contains (this)) return True;if (contains (t . p1) | | Contains (T.P2) | | Contains (T.P3)) return true; MyPoint P = new MyPoint (); for (int i = 0; i < 10000000; i + +) {p.x = Math.random () * 20-10; P.Y = Math.random () * 20-10;IF (contains (p) && t.contains (p)) return true; return false;}  public static double Getangle (MyPoint v1, MyPoint v2) {Double ans = math.acos (V1.mul (v2)/V1.abs ()/V2.abs ()); if (v1.x * V2.Y-V1.Y * v2.X < 0) return ans;else Return-ans;} public void setP1 (MyPoint p1) {this.p1 = P1;} public void setP2 (MyPoint p2) {this.p2 = p2;} public void SetP3 (MyPoint p3) {this.p3 = p3;} Public MyPoint getP1 () {return p1;} Public MyPoint getP2 () {return p2;} Public MyPoint getP3 () {return p3;} public static class MyPoint {public MyPoint () {x = y = 0;} Public MyPoint (double x, double y) {this.x = X;this.y = y;} Public double Getx () {return x;} Public double gety () {return y;} Public double Mul (mypoint) {return x * that.x + y * THAT.Y;} Public double abs () {return math.sqrt (x * x + y * y);} public static double distance (MyPoint A, MyPoint B) {Double x = a.x-b.x, y = A.y-b.y;return math.sqrt (x * x + y * y);} public static double distance (double x1, double y1, double x2, double y2) {Double x = x1-x2, y = Y1-y2;return math.sqr T (x * x + y * y);} Double x, y;} MyPoint P1, p2, p3;}

public class Courseselection {public static void main (string[] args) {courseselection cs = new courseselection (); cs.addstu Dent ("Great God"), Cs.addstudent ("Zheng Tao"), Cs.addstudent ("Deng Shiqing"), Cs.addcourse ("University Language"), Cs.addcourse ("Theoretical Physics"); Cs.addcourse (" The origin of the Universe "), Cs.selectcourse (" The Great God "," The Origin of the Universe "), Cs.selectcourse (" Great God "," theoretical Physics "), Cs.selectcourse (" Deng Shiqing "," University language "); Cs.selectcourse ("Zheng Tao", "Theoretical Physics"), Cs.selectcourse ("Deng Shiqing", "Theoretical Physics"), Cs.selectcourse ("Zheng Tao", "University Language"); cs.showstudents (); Cs.showcourses (); System.out.println (), Cs.dropcourse ("Zheng Tao", "Theoretical Physics"), Cs.dropcourse ("Deng Shiqing", "University Language"), Cs.dropcourse ("The Great God", "The Origin of the Universe"); Cs.dropcourse ("Great God", "theoretical Physics"), Cs.selectcourse ("Great God", "University Language"), Cs.selectcourse ("Zheng Tao", "Origin of the Universe"), Cs.selectcourse ("Deng Shiqing", " The origin of the Universe "); Cs.showstudents (); cs.showcourses ();} public void Showstudents () {System.out.println ("--------------sutdents--------------"), for (int i = 0; i < numberofstudents; i + +) {System.out.print (Students[i].getstudentname () + ":"); for (int j = 0; J < Students[i].numberofcourses; J + +) {System.out.print ("___" + Students[I].getcourses () [j]);} System.out.println ();}} public void Showcourses () {System.out.println ("--------------courses--------------"), for (int i = 0; i < numberofcourses; i + +) {System.out.print (Courses[i].getcoursename () + ":"); for (int j = 0; J < Courses[i].numberofstudents; J + +) {System.out.print ("___" + courses[i].getstudents () [j]);} System.out.println ();}} public void Addstudent (String studentname) {students[numberofstudents] = new Student (studentname); numberofstudents + +;} public void Addcourse (String coursename) {courses[numberofcourses] = new Course (coursename); numberofcourses + +;} public void Selectcourse (string studentname, String coursename) {for (int i = 0; i < numberofstudents; i + +) {if (stude Nts[i].studentname.equals (Studentname)) {students[i].addcourse (coursename);}} for (int i = 0; i < numberofcourses; i + +) {if (Courses[i].coursename.equals (Coursename)) {courses[i].addstudent (Studen tname);}}} public void Dropcourse (string studentname, String coursename) {for (int i = 0; i < numberofstudents; i + +) {if (Students[i].studentname.equals (Studentname)) {students[i].dropcourse (coursename);}} for (int i = 0; i < numberofcourses; i + +) {if (Courses[i].coursename.equals (Coursename)) {courses[i].dropstudent (stude ntname);}}} Public courseselection () {numberofcourses = Numberofstudents = 0;} public static class Course {public Course () {numberofstudents = 0;} Public Course (String coursename) {this.coursename = Coursename;} Public string[] Getstudents () {return students;} public int getnumberofstudents () {return numberofstudents;} Public String Getcoursename () {return coursename;} public void Addstudent (String student) {Students[numberofstudents] = student;numberofstudents + +;} public void Dropstudent (String student) {for (int i = 0; i < numberofstudents; i + +) {if (This.students[i].equals (stude NT)) {for (int j = i + 1; j < Numberofstudents; J + +) {This.students[j-1] = this.students[j];} Numberofstudents--;i--;}}} public void Clear () {numberofstudents = 0;} String Coursename; String[] Students = new String[100];int numberofstudents;} public class Student {public Student () {numberofcourses = 0;} Public Student (String studentname) {this.studentname = Studentname;} public void Addcourse (String course) {courses[numberofcourses] = course;numberofcourses + +;} public void Dropcourse (String course) {for (int i = 0; i < numberofcourses; i + +) {if (This.courses[i].equals (course)) {for (int j = i + 1; j < Numberofcourses; J + +) {This.courses[j-1] = this.courses[j];} Numberofcourses--;i--;}}} Public string[] Getcourses () {return courses;} public int getnumberofcourses () {return numberofcourses;} Public String Getstudentname () {return studentname;} public void Setstudentname (String studentname) {this.studentname = Studentname;} String Studentname; String[] Courses = new String[100];int numberofcourses;} Course[] Courses = new COURSE[100]; Student[] Students = new Student[100];int numberofcourses, numberofstudents;}

  

[Java Jobs] Fan, seeking straight intersection, TRIANGLE2D, elective course

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.