第一个:
该回答引用于ChatGPT:
class Rectangle{
private int height;
private int width;
public Rectangle(){
this.height = 0;
this.width = 0;
}
public Rectangle(int height, int width){
this.height = height;
this.width = width;
}
public int getHeight(){
return this.height;
}
public void setHeight(int height){
this.height = height;
}
public int getWidth(){
return this.width;
}
public void setWidth(int width){
this.width = width;
}
public int getArea(){
return this.height * this.width;
}
public int getPerimeter(){
return 2 * (this.height + this.width);
}
}
class MyPoint{
private double x;
private double y;
public MyPoint(){
this.x = 0.0;
this.y = 0.0;
}
public MyPoint(double x, double y){
this.x = x;
this.y = y;
}
public double getX(){
return this.x;
}
public void setX(double x){
this.x = x;
}
public double getY(){
return this.y;
}
public void setY(double y){
this.y = y;
}
public double getDistance(MyPoint point){
double dx = this.x - point.getX();
double dy = this.y - point.getY();
return Math.sqrt(dx*dx + dy*dy);
}
}
class Triangle{
private double side1;
private double side2;
private double side3;
public Triangle(double a, double b, double c){
if(a + b > c && a + c > b && b + c > a){
this.side1 = a;
this.side2 = b;
this.side3 = c;
}
else if(a > 0 || b > 0 || c > 0){
double max = Math.max(a, Math.max(b, c));
this.side1 = max;
this.side2 = max;
this.side3 = max;
}
else{
this.side1 = 0.0;
this.side2 = 0.0;
this.side3 = 0.0;
}
}
public double getArea(){
double s = (side1 + side2 + side3) / 2;
return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
}
}
测试代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//----------------------------------
// 测试 Rectangle 类
//----------------------------------
int height = sc.nextInt();
int width = sc.nextInt();
Rectangle rect = new Rectangle(height, width);
System.out.println(rect.getArea() + " " + rect.getPerimeter());
//----------------------------------
// 测试 MyPoint 类
//----------------------------------
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
MyPoint p1 = new MyPoint(x1, y1);
MyPoint p2 = new MyPoint(x2, y2);
System.out.println(p1.getDistance(p2));
//----------------------------------
// 测试 Triangle 类
//----------------------------------
double a = sc.nextDouble();
double b = sc.nextDouble();
double c = sc.nextDouble();
Triangle tri = new Triangle(a, b, c);
System.out.println(tri.getArea());
sc.close();
}
}
进入网址写代码呀各位!!
马上
该回答引用ChatGPT
public static void question1() {
// 打开网页并答题
WebDriver driver = new ChromeDriver();
driver.get("https://codecheck.io/private/resume/23032911332gvtuz80517tniyu6ad0bwkd3/kobu-wyty-vopy-neca/6XZD4FH36LGSEEG21AVYMWJI5");
WebElement button = driver.findElement(By.xpath("//button[text()='Take the Test']"));
button.click();
WebElement question1 = driver.findElement(By.xpath("//div[text()='Which of the following data types can store a decimal value?']/following-sibling::div"));
question1.findElement(By.xpath(".//label[text()='float']")).click();
question1.findElement(By.xpath(".//label[text()='double']")).click();
WebElement submit = driver.findElement(By.xpath("//button[text()='Submit']"));
submit.click();
// 关闭浏览器
driver.quit();
}
public static void question2() {
// 打开网页并答题
WebDriver driver = new ChromeDriver();
driver.get("https://codecheck.io/private/resume/23032911332gvtuz80517tniyu6ad0bwkd3/kobu-wyty-vopy-neca/6XZD4FH36LGSEEG21AVYMWJI5");
WebElement button = driver.findElement(By.xpath("//button[text()='Take the Test']"));
button.click();
WebElement question2 = driver.findElement(By.xpath("//div[text()='Which of the following keywords is used by classes to inherit methods and properties from another class?']/following-sibling::div"));
question2.findElement(By.xpath(".//label[text()='extends']")).click();
WebElement submit = driver.findElement(By.xpath("//button[text()='Submit']"));
submit.click();
// 关闭浏览器
driver.quit();
}
public static void question3() {
// 打开网页并答题
WebDriver driver = new ChromeDriver();
driver.get("https://codecheck.io/private/resume/23032911332gvtuz80517tniyu6ad0bwkd3/kobu-wyty-vopy-neca/6XZD4FH36LGSEEG21AVYMWJI5");
WebElement button = driver.findElement(By.xpath("//button[text()='Take the Test']"));
button.click();
WebElement question3 = driver.findElement(By.xpath("//div[text()='Which of the following shows the correct syntax for creating a new instance of a class named Dog?']/following-sibling::div"));
question3.findElement(By.xpath(".//label[text()='Dog myDog = new Dog();']")).click();
WebElement submit = driver.findElement(By.xpath("//button[text()='Submit']"));
submit.click();
// 关闭浏览器
driver.quit();
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class QuestionTest {
public static void main(String[] args) {
question1();
question2();
question3();
}
public static void question1() {
// 打开网页并答题
WebDriver driver = new ChromeDriver();
driver.get("https://codecheck.io/private/resume/23032911332gvtuz80517tniyu6ad0bwkd3/kobu-wyty-vopy-neca/6XZD4FH36LGSEEG21AVYMWJI5");
WebElement button = driver.findElement(By.xpath("//button[text()='Take the Test']"));
button.click();
WebElement question1 = driver.findElement(By.xpath("//div[text()='Which of the following data types can store a decimal value?']/following-sibling::div"));
question1.findElement(By.xpath(".//label[text()='float']")).click();
question1.findElement(By.xpath(".//label[text()='double']")).click();
WebElement submit = driver.findElement(By.xpath("//button[text()='Submit']"));
submit.click();
// 关闭浏览器
driver.quit();
}
public static void question2() {
// 打开网页并答题
WebDriver driver = new ChromeDriver();
driver.get("https://codecheck.io/private/resume/23032911332gvtuz80517tniyu6ad0bwkd3/kobu-wyty-vopy-neca/6XZD4FH36LGSEEG21AVYMWJI5");
WebElement button = driver.findElement(By.xpath("//button[text()='Take the Test']"));
button.click();
WebElement question2 = driver.findElement(By.xpath("//div[text()='Which of the following keywords is used by classes to inherit methods and properties from another class?']/following-sibling::div"));
question2.findElement(By.xpath(".//label[text()='extends']")).click();
WebElement submit = driver.findElement(By.xpath("//button[text()='Submit']"));
submit.click();
// 关闭浏览器
driver.quit();
}
public static void question3() {
// 打开网页并答题
WebDriver driver = new ChromeDriver();
driver.get("https://codecheck.io/private/resume/23032911332gvtuz80517tniyu6ad0bwkd3/kobu-wyty-vopy-neca/6XZD4FH36LGSEEG21AVYMWJI5");
WebElement button = driver.findElement(By.xpath("//button[text()='Take the Test']"));
button.click();
WebElement question3 = driver.findElement(By.xpath("//div[text()='Which of the following shows the correct syntax for creating a new instance of a class named Dog?']/following-sibling::div"));
question3.findElement(By.xpath(".//label[text()='Dog myDog = new Dog();']")).click();
WebElement submit = driver.findElement(By.xpath("//button[text()='Submit']"));
submit.click();
// 关闭浏览器
driver.quit();
}
}