「javaline类」javaonline

博主:adminadmin 2022-11-24 18:44:07 53

今天给各位分享javaline类的知识,其中也会对javaonline进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Java 定义一个Line类。该类包含两个Point型的实例变量。用以表示一条线段的两个端点。

package hello;

class Point {

double x, y;

Point(double x, double y) {

this.x = x;

this.y = y;

}

public boolean equals(Object o) {

if (o == this) return true;

if (!(o instanceof Point)) return false;

Point p = (Point) o;

return x == p.x y == p.y;

}

public String toString() { return "(" + x + ", " + y + ")"; }

}

class Line {

Point p1, p2;

Line(Point p1, Point p2) {

this.p1 = p1;

this.p2 = p2;

}

double length() {

double dx = p1.x - p2.x, dy = p1.y - p2.y;

return Math.sqrt(dx * dx + dy * dy);

}

boolean isHorizontal() { return p1.y == p2.y; }

boolean isVertical() { return p1.x == p2.x; }

double slope() { return (p1.y - p2.y) / (p1.x - p2.x); }

Point midPoint() { return new Point((p1.x + p2.x) / 2, (p1.y + p2.y) / 2); }

public boolean equals(Object o) {

if (o == this) return true;

if (!(o instanceof Line)) return false;

Line line = (Line) o;

return (p1.equals(line.p1) p2.equals(line.p2)) ||

(p1.equals(line.p2) p2.equals(line.p1));

}

}

public class newbeett {

public static void main(String[] args) {

Point p1 = new Point(1, 2), p2 = new Point(3, 4);

Line line = new Line(p1, p2);

System.out.println("线段长度为:");

System.out.println(line.length());

System.out.println("是否为水平线段:");

System.out.println(line.isHorizontal());

System.out.println("是否为垂直线段:");

System.out.println(line.isVertical());

System.out.println("线段斜率为:");

System.out.println(line.slope());

System.out.println("线段中点为:");

System.out.println(line.midPoint());

System.out.println("俩条线段是否相等:");

System.out.println(line.equals(line));

}

}

line在java是什么意思?

换行的意思

Line”英音 [lain] ;美音 [lain] ;

释义:

1)n. (名词)

1、line的基本意思是“线,线条”,指在物体表面上留下的长的痕迹,可以是直的,也可以是弯的;可指具体的线,也可指抽象的线。具体的线如电话线、绳子、铁路线等;抽象的线如行业、专长、方针、路线等。

2、line作“行”解时是单位词,其后常可接“of+ n. ”, of后的名词如是不可数名词表示复数意义时, line用复数形式;of后的名词如是可数名词,用于复数意义时,line和该名词均用复数形式。

3、line还可作“赤道”解,其前须加定冠词the。“a line of+ n. ”作主语时,谓语动词的数由line决定,而不依其后的名词。

2)v. (动词)

1、line的基本意思是“用线表示,画线于”,引申可指“排成一行”“排队,排齐”。line还可作“给…加衬里”解,作此解时,常与介词with连用。

2、line可用作及物动词,接名词或代词作宾语。可用于被动结构。例:

a line与a few lines可以解释为“短信”的意思。Please drop me a line (或a few lines) as soon as possible.

在a line of加名词作主语的句子中,谓语动词要与a line保持一致性,而不是与of后的名词保持一致性;

在信的开头,通常会出现Just a line to tell you that ...或者A line to say that ...等,这些都是习惯用语。Just a line to tell you that I have failed to the examination.

Java里面的line在哪儿

在java工具栏里面。

我们知道,java程序的启动入口是main方法,我们其实已经可以通过main中的args参数来实现将外界变量传入main方法内部了,那为什么还需要CommandLine。因为args参数使用不够方便,主要是因为其实现是一个数组,整个传递过程需要依赖顺序。编程者和程序调用需要记忆参数的顺序,才能正确传递参数。

当需要换行时,通常建议使用line。

java 判断直线状况

public class LineTest {

public static void main(String[] args) {

Point p1 = new Point(0, 3), p2 = new Point(4, 0);

Line l1 = new Line(0, 3, 4, 0),

l2 = new Line(p1, p2),

l3 = new Line(0,4,0,3),

l4 = new Line(4,4,0,4),

l5 = new Line(0,0,3,3);

System.out.println("l1:"+l1);

System.out.println("l2:"+l2);

System.out.println("l3:"+l3);

System.out.println("l4:"+l4);

System.out.println("l5:"+l5);

System.out.println("l1 length:"+l1.getLength());

System.out.println("l2 length:"+l2.getLength());

System.out.println("l3 length:"+l3.getLength());

System.out.println("l4 length:"+l4.getLength());

System.out.println("l1 isHorizontal:"+l1.isHorizontal());

System.out.println("l3 isHorizontal:"+l3.isHorizontal());

System.out.println("l1 isVertical:"+l1.isVertical());

System.out.println("l4 isVertical:"+l4.isVertical());

System.out.println("l1 slope:"+l1.getSlope());

System.out.println("l3 slope:"+l3.getSlope());

System.out.println("l4 slope:"+l4.getSlope());

System.out.println("l5 slope:"+l5.getSlope());

System.out.println("l1 midpoint:"+l1.getMidpoint().toString());

System.out.println("l3 midpoint:"+l3.getMidpoint().toString());

System.out.println("l1 equals l2:"+l1.equals(l2));

System.out.println("l1 equals l3:"+l1.equals(l3));

System.out.println("l2 equals l3:"+l2.equals(l3));

}

}

class Line {

private Point p1,p2;

public Line(Point p1, Point p2) {

super();

this.p1 = p1;

this.p2 = p2;

}

public Line(int x1,int y1,int x2,int y2){

super();

this.p1=new Point(x1, y1);

this.p2=new Point(x2, y2);

}

public int getLength(){

int a=(int) Math.abs(p1.getX()-p2.getX());

int b=(int) Math.abs(p1.getY()-p2.getY());

return (int) Math.sqrt(a*a+b*b);

}

public boolean isHorizontal(){

return Math.abs(p1.getX()-p2.getX())=0.00001;

}

public boolean isVertical(){

return Math.abs(p1.getY()-p2.getY())=0.00001;

}

public double getSlope(){

double a=p1.getX()-p2.getX();

double b=p1.getY()-p2.getY();

if(b==0.0)return Double.MAX_VALUE;

return a/b;

}

public Point getMidpoint(){

return new Point((int)((p1.getX()+p2.getX())/2)

,(int)((p1.getY()+p2.getY())/2));

}

public boolean equals(Line ol){

return (this.p1.equals(ol.getP1()))

(this.p2.equals(ol.getP2()));

}

public Point getP1() {

return p1;

}

public void setP1(Point p1) {

this.p1 = p1;

}

public Point getP2() {

return p2;

}

public void setP2(Point p2) {

this.p2 = p2;

}

@Override

public String toString(){

StringBuilder sb=new StringBuilder();

sb.append("[")

.append("(").append(p1.getX()).append(",")

.append(p1.getY()).append(")").append(",")

.append("(").append(p2.getX()).append(",")

.append(p2.getY()).append(")")

.append("]");

return sb.toString();

}

}

有个小问题就是你要求用Point做点,而Point点的数据类型是int,计算中点时会损失精度,可以改成Point2D实现。

如何在java中实现一个Line类

在百度文库中上传过一个文档,里面有你要的东西的,图文并茂的说明。

java中怎样创建一个Line类以便创建一个Vector数组来接受g.drawline绘画出的直线

import java.util.ArrayList;

import java.util.List;

public class Line {

/*

* x1 the first point's coordinate.

* y1 the first point's coordinate.

* x2 the second point's coordinate.

* y2 the second point's coordinate.

*/

private int x1;

private int y1;

private int x2;

private int y2;

private ListLine lines =new ArrayListLine();

public Line() {}

public Line(int x1, int y1, int x2, int y2) {

this.x1 = x1;

this.y1 = y1;

this.x2 = x2;

this.y2 = y2;

}

public int getX1() {

return x1;

}

public void setX1(int x1) {

this.x1 = x1;

}

public int getY1() {

return y1;

}

public void setY1(int y1) {

this.y1 = y1;

}

public int getX2() {

return x2;

}

public void setX2(int x2) {

this.x2 = x2;

}

public int getY2() {

return y2;

}

public void setY2(int y2) {

this.y2 = y2;

}

public ListLine Lines(){

return this.lines;

}

}

关于javaline类和javaonline的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-24,除非注明,否则均为首码项目网原创文章,转载请注明出处。