JavaSE编程题目练习(三)

news/2024/5/19 3:24:28/文章来源:https://blog.csdn.net/qq_57473444/article/details/133952306

博客昵称:架构师Cool
最喜欢的座右铭:一以贯之的努力,不得懈怠的人生。
作者简介:一名Coder,欢迎关注小弟!
博主小留言:哈喽!各位CSDN的uu们,我是你的小弟Cool,希望我的文章可以给您带来一定的帮助
百万笔记知识库, 所有基础的笔记都在这里面啦,点击左边蓝字即可获取!助力每一位未来架构师!
欢迎大家在评论区唠嗑指正,觉得好的话别忘了一键三连哦!😘

编程题目解析

  • 实验十一
    • 1、程序改错
      • 1-1、题目
      • 1-2、代码
    • 2、计算不同图形面积和周长
      • 2-1、题目
      • 2-2、代码
    • 3、计算圆柱体
      • 3-1、题目
      • 3-2、代码
  • 实验十二
    • 1、接口的使用
      • 1-1、题目
      • 1-2、代码
    • 2、计算器
      • 2-1、题目
      • 2-2、代码
  • 实验十三
    • 1、监测体重
      • 1-1、题目
      • 1-2、代码
    • 2、成绩异常检测
      • 2-1、题目
      • 2-2、代码
  • 实验十四
    • 1、机票
      • 1-1、题目
      • 1-2、代码
    • 2、随机五位数验证码
      • 2-1、题目
      • 2-2、代码
    • 3、数字加密
      • 3-1、题目
      • 3-2、代码
    • 4、抢红包
      • 4-1、题目
      • 4-2、代码
  • 实验十五
    • 1、绘制基本图形
      • 1-1、题目
      • 1-2、代码一
      • 1-3、代码二
    • 2、修改snowman图形
      • 2-1、题目
      • 2-2、代码
    • 3、绘制饼图
      • 3-1、题目
      • 3-2、代码

接着上面的文章
JavaSE编程题目练习(一)
JavaSE编程题目练习(二)

实验十一

1、程序改错

1-1、题目

下列程序有错,请仔细阅读,找出错误并改正。
(1) abstract class Man{
(2) public String name;
(3) public void Man(String name){
(4) this.name=name;
(5) }
(6) public abstract void print(){ };
(7) }
(8) public class Test40 extend Man{
(9) public Test40(String name){
(10) super(name);
(11) }
(12) public void print(){
(13) System.out.println(“name=”+name);
(14) }
(15) public static void main(String[] args) {
(16) Test40 xm=new Test40(“tom”);
(17) xm.print();
(18) }
(19) }
第 行错误,改为
第 行错误,改为
第 行错误,改为

1-2、代码

第 三 行错误,改为 public Man(String name){
第 六 行错误,改为 public void print(){ };
第 八 行错误,改为 public class Test40 extends Man{

2、计算不同图形面积和周长

2-1、题目

1.编写一个抽象类(Shape),长方形、三角形和圆形均为其子类,并各有各的属性。其父类中有计算周长和面积的方法。在测试类中,分别建立如干个对象,计算并输出各对象的周长和面积。

2-2、代码

abstract class Shape {//计算周长public abstract double calculatePerimeter();//计算面积public abstract double calculateArea();}
class Rectangle extends Shape{private double length;private double width;public Rectangle(double length, double width) {this.length = length;this.width = width;}@Overridepublic double calculatePerimeter() {return length * width;}@Overridepublic double calculateArea() {return length * width;}
}
class Triangle extends Shape {private double side1;private double side2;private double side3;public Triangle(double side1, double side2, double side3) {this.side1 = side1;this.side2 = side2;this.side3 = side3;}public double calculatePerimeter() {return side1 + side2 + side3;}public double calculateArea() {//海伦公式:area=√(s*(s-a)(s-b)(s-c))double s = (side1 + side2 + side3) / 2;return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));}
}
class Circle extends Shape {private double radius;public Circle(double radius) {this.radius = radius;}public double calculatePerimeter() {return 2 * Math.PI * radius;}public double calculateArea() {return Math.PI * radius * radius;}
}
public class ShapeTest{public static void main(String[] args) {Rectangle rectangle = new Rectangle(5, 3);System.out.println("Rectangle area: " + rectangle.calculateArea());System.out.println("Rectangle perimeter: " + rectangle.calculatePerimeter());Triangle triangle = new Triangle(3, 4, 5);System.out.println("Triangle area: " + triangle.calculateArea());System.out.println("Triangle perimeter: " + triangle.calculatePerimeter());Circle circle = new Circle(4);System.out.println("Circle area: " + circle.calculateArea());System.out.println("Circle perimeter: " + circle.calculatePerimeter());}
}

3、计算圆柱体

3-1、题目

(1)设计一个表示二维平面上点的类Point,包含有表示坐标位置的protected类型的成员变量x和y,获取和设置x 和y值的public方法。
(2).设计一个表示二维平面上圆的类Circle,它继承自类Point,还包含有表示圆半径的protected类型的成员变量r、获取和设置r值的public方法、计算圆面积的public方法。
(3).设计一个表示圆柱体的类Cylinder,它继承自类Circle,还包含有表示圆柱体高的protected类型的成员变量h、获取和设置h值的public方法、计算圆柱体体积的public方法。
(4).建立若干个Cylinder对象,输出其轴心位置坐标、半径、高及其体积的值。

实验要求:
. 每个类包含无参数和有参数的构造方法。构造方法用于对成员变量初始化,无参数的构造方法将成员变量初始化为0值。
.子类的构造方法调用父类的构造方法,对父类中的成员变量初始化。
.方法名自定;

3-2、代码


public class Test01 {public static void main(String[] args) {Cylinder cylinder1 = new Cylinder(1, 2, 3, 4);Cylinder cylinder2 = new Cylinder(5, 6, 7, 8);System.out.println("圆柱体 1 - 轴心坐标: (" + cylinder1.getX() + ", " + cylinder1.getY() + ")");System.out.println("圆柱体 1 - 半径: " + cylinder1.getR());System.out.println("圆柱体 1 - 高: " + cylinder1.getH());System.out.println("圆柱体 1 - 体积: " + cylinder1.calculateCircleVolume());System.out.println("圆柱体 2 - 轴心坐标: (" + cylinder2.getX() + ", " + cylinder2.getY() + ")");System.out.println("圆柱体 2 - 半径: " + cylinder2.getR());System.out.println("圆柱体 2 - 高: " + cylinder2.getH());System.out.println("圆柱体 2 - 体积: " + cylinder2.calculateCircleVolume());}
}
class Point{protected int x;protected int y;public Point() {x = 0;y = 0;}public Point(int x, int y) {this.x = x;this.y = y;}public int getX() {return x;}public void setX(int x) {this.x = x;}public int getY() {return y;}public void setY(int y) {this.y = y;}
}
class Circle extends Point{protected int r;public Circle() {super();r = 0;}public Circle(int x, int y, int r) {super(x, y);this.r= r;}public double getR() {return r;}public void setR(int r) {this.r = r;}public double calculateCircleArea() {return Math.PI * r * r;}
}
class Cylinder extends Circle{protected int h;public Cylinder() {super();h = 0;}public Cylinder(int x, int y, int r, int h) {super(x, y, r);this.h = h;}public double getH() {return h;}public void setH(int h) {this.h = h;}public double calculateCircleVolume() {return calculateCircleArea() * h;}
}

实验十二

1、接口的使用

1-1、题目

接口的使用
1,定义一个接口Shape,它含有一个抽象方法 double area( )
2,定义一个表示三角形的类Triangle,该类实现接口Shape。此类中有两个分别用于存储三角形底边和高度的private成员变量int width和int height,在该类实现的方法area中计算并返回三角形的面积。
3,定义一个表示矩形的类Rectangle,该类实现接口Shape。此类中有两个分别表示矩形长度和高度度的成员变量int width和int height,在该类实现的方法area中计算并返回矩形的面积。
4,定义一个类ShapeTest,该类中有一个方法如下:
public static void showArea(Shape s){
System.out.println(“area=”+s.area());
}
在ShapeTest类中定义main函数,在main函数中创建Triang类的对象和Rectangle类的对象,并调用方法showArea两次以输出两个对象的面积。
 思考:两次调用showArea方法时调用的area方法各是在哪个类中定义的方法?答:三角形调用showArea方法时调用的area方法是Triangle类中定义的方法,而矩形调用showArea方法时调用的area方法是Rectangle类中定义的方法

1-2、代码

interface Shape {double area();
}
class Triangle implements Shape{private int width=50;private int height=20;@Overridepublic double area() {return width*height/2;}
}
class Rectangle implements Shape{private int width=50;private int height=20;@Overridepublic double area() {return width*height;}
}
public class ShapeTest{public static void main(String[] args) {Triangle triangle = new Triangle();Rectangle rectangle = new Rectangle();showArea(triangle);showArea(rectangle);}public static void showArea(Shape s){System.out.println("area="+s.area());}
}

2、计算器

2-1、题目

利用接口做参数, 写个计算器,能完成加减乘除运算:
(1)定义一个接口Calculator含有一个方法int computer(int n, int m)。
(2)设计四个类分别实现此接口,完成加减乘除运算。
(3)设计一个类Computer,类中含有方法:public void useCal (Calculator com, int op1, int op2),要求调用computer(),对参数进行运算。
(4)设计一个主类TestCh09_02,调用Computer中的方法computer来完成加减乘除运算。
运行结果:
25+6和为:31
32-12差为:20
15*5乘积为:75
16/2商为:8

2-2、代码

interface Calculator{int computer(int n ,int m);
}
class Addition implements Calculator {@Overridepublic int computer(int n, int m) {return n + m;}}class Subtraction implements Calculator {public int computer(int n, int m) {return n - m;}
}class Multiplication implements Calculator {public int computer(int n, int m) {return n * m;}
}class Division implements Calculator {public int computer(int n, int m) {if (m == 0) {throw new IllegalArgumentException("除数不能为0");}return n / m;}
}
class Computer{public void useCal(Calculator com ,int op1,int op2){int result = com.computer(op1,op2);System.out.print(result);}
}
public class TestCh09_02 {public static void main(String[] args) {Computer computer = new Computer();int operand1 = 25;int operand2 = 6;Calculator addition = new Addition();System.out.print(operand1+"+"+operand2+"和为:");computer.useCal(addition, operand1, operand2); // 执行加法运算System.out.println();operand1=32;operand2=12;Calculator subtraction = new Subtraction();System.out.print(operand1+"-"+operand2+"差为:");computer.useCal(subtraction, operand1, operand2); // 执行减法运算System.out.println();operand1=15;operand2=5;Calculator multiplication = new Multiplication();System.out.print(operand1+"*"+operand2+"乘积为:");computer.useCal(multiplication, operand1, operand2); // 执行乘法运算System.out.println();operand1=16;operand2=2;Calculator division = new Division();System.out.print(operand1+"/"+operand2+"商为:");computer.useCal(division, operand1, operand2); // 执行除法运算}
}

实验十三

1、监测体重

1-1、题目

1.定义一个类来监控体重是否超重,体重指数BMI=体重(kg)÷身高÷身高(m),中国成人居民BMI衡量标准是≤18.4为消瘦、18.5-23.9为正常、24-27.9为超重、≥28为肥胖。体重超重需要提示多运动。运行结果如图13- 1 超重提示图所示:
在这里插入图片描述

1-2、代码

import java.util.Scanner;
public class ExceptionTest {//1.定义一个类来监控体重是否超重,体重指数BMI=体重(kg)÷身高÷身高(m)// 中国成人居民BMI衡量标准是≤18.4为消瘦、18.5-23.9为正常// 24-27.9为超重、≥28为肥胖。体重超重需要提示多运动。public static void main(String[] args) {Scanner sc = new Scanner(System.in);Weight wg = new Weight();System.out.println("请输入体重(kg):");wg.setWeight(sc.nextDouble());System.out.println("请输入身高(m):");wg.setHeight(sc.nextDouble());double bmi=wg.getBmi(wg);if (bmi<=18.4)System.out.println("太瘦了,多吃肉");else if (bmi<=23.9 && bmi>=18.5)System.out.println("非常健康的身体哦");else if (bmi<=27.9 && bmi>=24) {System.out.println("体重超重,多运动");}else {System.out.println("肥胖人群,需要减肥了");}System.out.println(bmi);}
}
class Weight{private double height;private double weight;public void setHeight(double height) {this.height = height;}public void setWeight(double weight) {this.weight = weight;}public double getBmi(Weight wg){return weight/height/height;}
}

2、成绩异常检测

2-1、题目

定义Student类,其属性:
private String name;
private int score;
自定义IllegalScoreException异常类,代表分数相加后超出合理范围的异常。
测试学生对象。要求以new作为输入标识,输入一行学生数据,格式为姓名 年龄,后调用addScore。addScore不成功则抛出异常,并打印异常信息,然后如正常则打印学生信息。
运行结果如图13- 2成绩异常图所示:
在这里插入图片描述

2-2、代码

import java.util.Scanner;
//todo 还未完成的项目
public class StudentScore {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);String s=scanner.nextLine();//判断是否while(s.equals("new")){System.out.print("请输入姓名:");String name = scanner.nextLine();System.out.print("请输入成绩:");int score = scanner.nextInt();Student student = new Student(name,score);try {student.addScore(score);System.out.println(student.toString());}catch (IllegalScoreException e){System.out.println("IllegalScoreException:"+e.getMessage());}scanner.nextLine();s=scanner.nextLine();}}
}
class Student{private String name;private int score;public Student(String name, int score) {this.name = name;this.score = score;}public void addScore(int scoreToAdd) throws IllegalScoreException{if(scoreToAdd+score > 200) {throw new IllegalScoreException(score);}score=scoreToAdd;}@Overridepublic String toString() {return "Student[" +"name='" + name + '\'' +", score=" + score +']';}
}
class IllegalScoreException extends RuntimeException{public IllegalScoreException(int score){super("成绩超过有效范围,成绩为=" + score);}
}

实验十四

1、机票

1-1、题目

在这里插入图片描述
在这里插入图片描述

1-2、代码

import java.util.Scanner;public class AirTicketTest {public static void main(String[] args) {Scanner sc = new Scanner(System.in);double newPrice;while (true) {System.out.println("输入机票原价:");int oldPrice = sc.nextInt();if (oldPrice==-1){break;}System.out.println("输入月份:");int mouth = sc.nextInt();System.out.println("输入0则为头等舱1则为经济舱:");int wareHouse = sc.nextInt();//仓位if (mouth > 4 && mouth < 11) {System.out.println("旺季");if (wareHouse == 1) {newPrice = oldPrice * (0.85);System.out.print("经济舱");} else {newPrice = oldPrice * (0.9);System.out.print("头等舱");}} else {System.out.println("淡季");if (wareHouse == 1) {System.out.print("经济舱");newPrice = oldPrice * (0.65);} else {newPrice = oldPrice * (0.7);System.out.print("头等舱");}}System.out.println("票价为" + newPrice);}}
}

2、随机五位数验证码

2-1、题目

在这里插入图片描述
在这里插入图片描述

2-2、代码

import java.util.Random;//验证码
public class Verification {public static void main(String[] args) {String verificationCode = getCode();System.out.println("验证码:" + verificationCode);}public static String getCode() {Random random = new Random();StringBuilder code = new StringBuilder();// 生成前四位随机字母for (int i = 0; i < 4; i++) {char c = (char) (random.nextInt(26) + 'A');code.append(c);}// 生成最后一位随机数字int digit = random.nextInt(10);code.append(digit);return code.toString();}
}

3、数字加密

3-1、题目

在这里插入图片描述

3-2、代码

import java.util.Scanner;public class Encryption {public static void main(String[] args) {Code code = new Code();Scanner sc = new Scanner(System.in);int anInt = sc.nextInt();if (anInt>0) {code.enCode(anInt);}else {System.out.println("密码小于0");}}
}
class Code{public void enCode(int code){int qw,bw,sw,gw;qw=code/1000;bw=code%1000/100;sw=code/10%10;gw=code%10;int firstCode= (qw+5)%10*1000+(bw+5)%10*100+(sw+5)%10*10+(gw+5)%10;qw=firstCode/1000;bw=firstCode%1000/100;sw=firstCode/10%10;gw=firstCode%10;int nextCode=gw*1000+sw*100+bw*10+qw;System.out.println(code+"加密后的结果是"+nextCode);}
}
}

4、抢红包

4-1、题目

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4-2、代码

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;public class LuckyDraw {public static void main(String[] args) {List<Integer> prizes = new ArrayList<>();prizes.add(2588);prizes.add(888);prizes.add(1000);prizes.add(10000);prizes.add(2);Collections.shuffle(prizes); // 随机打乱奖项顺序for (int prize : prizes) {if (prize == 888) {System.out.println("888元的奖金被抽出");} else if (prize == 588) {System.out.println("588元的奖金被抽出");} else if (prize == 1000) {System.out.println("1000元的奖金被抽出");} else if (prize == 10000) {System.out.println("10000元的奖金被抽出");} else if (prize == 2) {System.out.println("2元的奖金被抽出");}}}
}

实验十五

1、绘制基本图形

1-1、题目

第一题
利用第三章的绘图知识
1,画出4个长方形:
其中一个长方形完全包含在另外一个长方形中;
第三个长方形与前两个长方形有交叉,当没有完全包含起来;
第四个长方形和其他三个长方形完全没有交叉。
在这里插入图片描述
第二题
,2. 改变图形的背景颜色。将其中两个长方形改为椭圆形,修改四个图形的背景颜色,保证每个图形颜色都和其他的不一样。
在这里插入图片描述

1-2、代码一

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;public class FourRectangle extends Application {public static void main(String[] args) {launch(args);}@Overridepublic void start(Stage primaryStage) {Pane root = new Pane();// 第一个长方形Rectangle rectangle1 = new Rectangle(50, 50, 200, 100);rectangle1.setFill(null);rectangle1.setStroke(Color.RED);root.getChildren().add(rectangle1);// 第二个长方形,完全包含在第一个长方形中Rectangle rectangle2 = new Rectangle(60, 90, 50, 25);rectangle2.setFill(null);rectangle2.setStroke(Color.BLACK);root.getChildren().add(rectangle2);// 第三个长方形,与第一个和第二个长方形有交叉Rectangle rectangle3 = new Rectangle(70, 70, 200, 100);rectangle3.setFill(null);rectangle3.setStroke(Color.YELLOW);root.getChildren().add(rectangle3);// 第四个长方形,与前三个长方形完全没有交叉Rectangle rectangle4 = new Rectangle(300, 300, 200, 100);rectangle4.setFill(null);rectangle4.setStroke(Color.GREEN);root.getChildren().add(rectangle4);Scene scene = new Scene(root, 600, 600);primaryStage.setTitle("Rectangles");primaryStage.setScene(scene);primaryStage.show();}
}

1-3、代码二

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;public class FourRectangle2 extends Application {public static void main(String[] args) {launch(args);}@Overridepublic void start(Stage primaryStage) {Pane root2 = new Pane();// 第一个长方形Rectangle rectangle1 = new Rectangle(50, 50, 200, 100);rectangle1.setFill(Color.RED);rectangle1.setStroke(Color.BLACK);root2.getChildren().add(rectangle1);// 第二个长方形,完全包含在第一个长方形中Rectangle rectangle2 = new Rectangle(60, 90, 50, 25);rectangle2.setFill(Color.BLACK);rectangle2.setStroke(Color.BLACK);root2.getChildren().add(rectangle2);// 第三个长方形,与第一个和第二个长方形有交叉Ellipse ellipse1 = new Ellipse(170, 110, 100, 50);ellipse1.setFill(Color.YELLOW);ellipse1.setStroke(Color.BLACK);root2.getChildren().add(ellipse1);// 第四个长方形,与前三个长方形完全没有交叉Ellipse ellipse2 = new Ellipse(300, 300, 100, 50);ellipse2.setFill(Color.GREEN);ellipse2.setStroke(Color.GREEN);root2.getChildren().add(ellipse2);Scene scene = new Scene(root2, 600, 600);primaryStage.setTitle("Rectangles");primaryStage.setScene(scene);primaryStage.show();}
}

2、修改snowman图形

2-1、题目

按照以下要求修改程序Snowman.java(参考源码)
将雪人的嘴型变成哭脸的倒弧嘴样;
把太阳移动到图片的右上角;
在图片左上角显示你的名字;
将整个雪人右移50个像素。
在这里插入图片描述
在这里插入图片描述

2-2、代码

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;public class SnowMan extends Application {@Overridepublic void start(Stage stage) {try {//最底层的雪球Ellipse baseSnowball =new Ellipse(80,210,80,60);baseSnowball.setFill(Color.WHITE);// 连接的中间雪球Ellipse connectSnowball =new Ellipse(80,130,50,40);connectSnowball.setFill(Color.WHITE);//头部的雪球Circle headerSnowball = new Circle(80,70,30);headerSnowball.setFill(Color.WHITE);//眼部Circle rightEye = new Circle(70,60,5);Circle leftEye = new Circle(90,60,5);// 手部Line leftArm= new Line(110,130,160,130);leftArm.setStrokeWidth(3);Line rightArm= new Line(50,130,0,100);rightArm.setStrokeWidth(3);// 嘴巴Arc mouth = new Arc(80,85,15,10,360,180);mouth.setFill(null);mouth.setStrokeWidth(2);mouth.setStroke(Color.BLACK);//设置画笔颜色//纽扣Circle upperButton = new Circle(80,120,6);upperButton.setFill(Color.RED);Circle lowerButton = new Circle(80,140,6);lowerButton.setFill(Color.RED);Rectangle upperHat = new Rectangle(60,0,40,50);Rectangle lowerHat = new Rectangle(50,45,60,5);//将图案放入面板Group hat = new Group(upperHat,lowerHat);hat.setTranslateX(10);hat.setRotate(15);// 组成雪人Group snowman = new Group(baseSnowball,connectSnowball,headerSnowball,leftEye,rightEye,leftArm,rightArm,mouth,upperButton,lowerButton,hat);snowman.setTranslateX(170);snowman.setTranslateY(50);// 太阳Circle sun = new Circle(450,50,30);sun.setFill(Color.GOLD);// 下面的蓝色背景Rectangle ground = new Rectangle(0,250,500,100);ground.setFill(Color.STEELBLUE);//文字栏目Text bannerName=new Text();bannerName.setText("理工学院软件学院");bannerName.setX(50);bannerName.setY(50);// 组成图形Group root = new Group(ground,sun,snowman,bannerName);Scene scene = new Scene(root,500,350,Color.LIGHTBLUE);//画板背景为浅蓝色stage.setScene(scene);stage.setTitle("Snowman");stage.show();} catch(Exception e) {e.printStackTrace();}}public static void main(String[] args) {launch(args);}
}

3、绘制饼图

3-1、题目

编写一段JavaFX小程序,保存为PieChat.java,给出家庭收入的消费状况,具体数据如下:
Rent and Utilities 35%
Transportation 15%
Food 15%
Education 25%
Miscellaneous 10%

要求:饼图的每个部分要有不同的颜色。给每个部分设定一个标签,该标签出现在饼图的外围部分(提示:使用Arc方法画扇形图)。
在这里插入图片描述

3-2、代码

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.chart.PieChart;
import javafx.stage.Stage;import java.util.Arrays;
import java.util.List;public class PieChat extends Application {public static void main(String[] args) {launch(args);}@Overridepublic void start(Stage stage) {// 创建饼图的数据列表List<PieChart.Data> pieChartData = Arrays.asList(new PieChart.Data("Miscellaneous", 10),new PieChart.Data("Education", 25),new PieChart.Data("Food", 15),new PieChart.Data("Transportation", 15),new PieChart.Data("Rent and Utilities", 35));// 创建饼图PieChart pieChart = new PieChart();pieChart.getData().addAll(pieChartData);pieChart.setLabelLineLength(0);//设置标签线长度// 设置饼图的颜色int colorIndex = 0;for (PieChart.Data data : pieChartData) {data.getNode().setStyle("-fx-pie-color: " + getColor(colorIndex));colorIndex++;}pieChart.setLegendVisible(false);//取消图例// 创建场景Group root = new Group(pieChart);Scene scene = new Scene(root);stage.setTitle("Expense Pie Chart");stage.setScene(scene);stage.show();}// 获取不同的颜色private String getColor(int index) {String[] colors = { "PINK", "#0000FF", "#00FFFF","GREEN", "#FF0000"};return colors[index % colors.length];}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_186307.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

超低延迟直播技术路线,h265的无奈选择

超低延迟&#xff0c;多窗显示&#xff0c;自适应编解码和渲染&#xff0c;高分辨低码率&#xff0c;还有微信小程序的标配&#xff0c;这些在现今的监控和直播中都成刚需了&#xff0c;中国的音视频技术人面临着困境&#xff0c;核心门户浏览器不掌握在自己手上&#xff0c;老…

前言:自动化框架的设计模式

1、UI自动化框架的设计模式 自动化测试框架有很多种&#xff0c;常见的自动化框架分类如下&#xff1a; 在使用上面的自动化框架时&#xff0c;通常会结合使用分层思想&#xff0c;也就是一些自动化框架设计模式&#xff0c;今天重点分享一下UI自动化框架设计使用比较多的一种…

2023/10/30-LED灯驱动开发

k1.c #include <linux/init.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/uaccess.h> #include <linux/io.h> #include "head.h" char kbuf[128] {}; unsigned int major; //定义三个指针指向映射后的虚拟内…

STM32:TIM通道输入捕获

本文主要讲解如何使用TIMER通道的输入脉冲捕获功能。基于STM32F7的Timer2 Channel3来进行讲解。 配置时钟 Timer2的时钟频率&#xff0c;对应APB1 Timer。 分频设置为96-1&#xff0c;这样设置每次count计数&#xff0c;对应的时间为1us。Counter设置为最大即可&#xff0c;默…

VMware Workstation里面安装ubuntu20.04的流程

文章目录 前言一、获取 desktop ubuntu20.04 安装镜像二、VMware Workstation下安装ubuntu20.041. VMware Workstation 创建一个新的虚拟机2. ubuntu20.04的安装过程3. 登录ubuntu20.044. 移除 ubuntu20.04 安装镜像总结参考资料前言 本文主要介绍如何在PC上的虚拟机(VMware W…

使用Spyder进行动态网页爬取:实战指南

导语 知乎数据的攀爬价值在于获取用户观点、知识和需求&#xff0c;进行市场调查、用户画像分析&#xff0c;以及发现热门话题和可能的新兴领域。同时&#xff0c;知乎上的问题并回答也是宝贵的学习资源&#xff0c;用于知识图谱构建和自然语言处理研究。爬取知乎数据为决策和…

SolidWorks2021 安装教程(亲测可用)

1.安装教程&#xff1a;&#xff08;断网进行&#xff0c;否则安装了后还是无法用&#xff09; 1.运行sw2021_network_serials_licensing 2. 注册表编辑器确定 3.成功添加到注册表中 4.复制SolidWorks_Flexnet_Server文件夹 5.运行SolidWorks_Flexnet_Server下的lserver_insta…

测试Android webview 加载本地html

最近开发一个需要未联网功能的App, 不熟悉使用Java原生开发界面&#xff0c;于是想使用本地H5做界面&#xff0c;本文测试了使用本地html加载远程数据。直接上代码&#xff1a; MainActivity.java package com.alex.webviewlocal;import androidx.appcompat.app.AppCompatAct…

UE4 UltrDynamicSky与场景物体进行交互

找到材质 找到其最父类的材质 把这个拖过去连上即可

OSI笔记

由7层组成&#xff0c;由下自上分别为&#xff1a; 物理层&#xff08;硬件方面&#xff0c;例如物理网络设备、布线电缆、光纤等&#xff09;&#xff0c; 传输数据主要是比特流0 1 、电信号数据链路层&#xff08;确定了0 1 的分组方式&#xff0c;通过广播的方式&#xff0…

VTK8.0.0编译+QT5.9.2+VS2017

背景 VTK网上资料较多并且使用较多的版本可能是VTK8.2.0&#xff0c;但是由于之前先配置了QT 5.9.2 msvc2017 PCL1.8.1 VTK8.0.0环境&#xff0c;听说有人PCL1.8.1配置VTK8.2.0实测版本不兼容&#xff0c;需修改源码调试&#xff0c;比较麻烦&#xff0c;所以之前就使用的VT…

元梦之星内测上线,如何在B站打响声量?

元梦之星是腾讯天美工作室群研发的超开星乐园派对手游&#xff0c;于2023年1月17日通过审批。该游戏风格可爱软萌&#xff0c;带有社交属性&#xff0c;又是一款开黑聚会的手游&#xff0c;备受年轻人关注。 飞瓜数据&#xff08;B站版&#xff09;显示&#xff0c;元梦之星在…

迅为RK3588开发板Android12单摄方案设备树修改

打开 3588-android12/kernel-5.10/arch/arm64/boot/dts/rockchip/topeet_camera_config.dtsi 设备树&#xff0c;此设备树中对底板上的摄像头接口进行了配置&#xff0c;如下图所示&#xff1a; 如果想要使用 J1 接口打开摄像头 OV5695 或者 摄像头 OV13850&#xff0c;只需要在…

在 Windows Server RDS 服务器 上重置 120 天宽限期

如果您出于测试目的安装了 RDS Server 2016/2019/2022&#xff0c;并且 RDS 许可宽限期已过期&#xff0c;请继续阅读下面的内容以了解如何重置 120 天宽限期。您可能知道&#xff0c;在安装 RDS Server 2016 时&#xff0c;您有 120 天的时间来安装 RD 客户端访问许可证 &…

nginx负载均衡(动静分离)

nginx负载均衡&#xff08;动静分离&#xff09; 文章目录 nginx负载均衡&#xff08;动静分离&#xff09;工作原理&#xff1a;环境说明&#xff1a;部署nginx负载均衡步骤&#xff1a;在负载均衡&#xff08;NGINX&#xff09;主机上做配置&#xff1a;测试&#xff1a;在浏…

驱动编写应用程序控制三盏灯亮灭

应用程序 #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <string.h> int main(int argc, char const *argv[]) {char buf[128] {0};int fd open("/dev/mych…

点云平面拟合新国标怎么应对?

文章目录 一、应用背景二、算法原理三、代码实现首先我们看一下平面度的概念: 平面度:测量点集合中,在平面上方且距离基准平面最远的点到平面的距离+在平面下方且距离基准平面最远的点到平面的距离。 一、应用背景 在旧标准中,使用最小二乘法去拟合全部点,以拟合平面作为…

QT的QStringList的使用

初始 化 默认构造函数创建一个空列表。可以使用初始值设定项列表构造函数创建包含元素的列表&#xff1a; QStringList fonts { "Arial", "Helvetica", "Times" }; 添加字符串 可以使用insert 、append&#xff08;&#xff09; 和 operator…

RK3568驱动指南|第七期-设备树-第57章 实例分析:中断

瑞芯微RK3568芯片是一款定位中高端的通用型SOC&#xff0c;采用22nm制程工艺&#xff0c;搭载一颗四核Cortex-A55处理器和Mali G52 2EE 图形处理器。RK3568 支持4K 解码和 1080P 编码&#xff0c;支持SATA/PCIE/USB3.0 外围接口。RK3568内置独立NPU&#xff0c;可用于轻量级人工…

操作系统【OS】微内核

基本概念 微内核结构将操作系统划分为两大部分&#xff1a;微内核多个服务器微内核包含&#xff1a; 与硬件处理紧密相关的部分一些较基本的功能客户和服务器间的通信客户与服务器之间是借助微内核提供的消息传递机制来实现交互的 基本功能 进程管理 进程的通信、切换、调度…