Java 课程作业 20240514
This commit is contained in:
parent
4bcb09a45c
commit
b6ee03b691
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Function: 盒子类
|
||||
* Function: 创建 盒子 类
|
||||
* Date: 2024 04 18
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
@ -7,30 +7,33 @@
|
||||
package javaAssignment_20240418;
|
||||
|
||||
public class box {
|
||||
double length;
|
||||
double width;
|
||||
double height;
|
||||
private double length;
|
||||
private double width;
|
||||
private double height;
|
||||
|
||||
public void setBox_length (double l){
|
||||
length = l;
|
||||
this.length = l;
|
||||
}
|
||||
public void setBox_width (double w){
|
||||
width = w;
|
||||
this.width = w;
|
||||
}
|
||||
public void setBox_height (double h){
|
||||
height = h;
|
||||
this.height = h;
|
||||
}
|
||||
public void printVolume(){
|
||||
System.out.println(height * width * length);
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
// 实例化 box 类
|
||||
box b_1 = new box();
|
||||
|
||||
// 赋值
|
||||
b_1.setBox_height(5);
|
||||
b_1.setBox_length(2);
|
||||
b_1.setBox_width(3);
|
||||
|
||||
// 输出体积
|
||||
b_1.printVolume();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Function: 虚数和
|
||||
* Function: 创建类计算两个虚数和
|
||||
* Date: 2024 04 18
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
@ -23,6 +23,7 @@ public class complex {
|
||||
this.imaginePart = i;
|
||||
}
|
||||
|
||||
// 计算两个虚数和
|
||||
public complex complexAdd (complex a){
|
||||
complex temp = new complex();
|
||||
temp.realPart = this.realPart + a.realPart;
|
||||
@ -30,6 +31,7 @@ public class complex {
|
||||
return temp;
|
||||
}
|
||||
|
||||
// 返回计算结果 String
|
||||
public String ToString (){
|
||||
return this.realPart + " + " + this.imaginePart + "i";
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ public class sumNum {
|
||||
private int m;
|
||||
// 列
|
||||
private int n;
|
||||
// 和
|
||||
private int sum;
|
||||
|
||||
// 带参构造方法
|
||||
@ -27,6 +28,11 @@ public class sumNum {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sum value.
|
||||
*
|
||||
* @return the sum value
|
||||
*/
|
||||
public int getSum (){
|
||||
return this.sum;
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Function: Java 多线程
|
||||
* Date: 2024 05 10
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240510;
|
||||
|
||||
class myThread extends Thread{
|
||||
// 成员变量
|
||||
private String who;
|
||||
// 构造方法
|
||||
public myThread(String who){
|
||||
super();
|
||||
this.who = who;
|
||||
}
|
||||
|
||||
public myThread(){
|
||||
super();
|
||||
}
|
||||
|
||||
// 覆盖 run 方法
|
||||
public void run(){
|
||||
for (int i = 0; i < 5; i++){
|
||||
try{
|
||||
sleep(1000);
|
||||
}
|
||||
catch (InterruptedException e){
|
||||
|
||||
}
|
||||
System.out.println(who + "is running");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class thread {
|
||||
public static void main(String[] args){
|
||||
// 创建线程
|
||||
myThread test01Thread = new myThread("test01_Thread");
|
||||
myThread test02Thread = new myThread("test02_Thread");
|
||||
|
||||
test01Thread.start();
|
||||
test02Thread.start();
|
||||
|
||||
System.out.println("system out");
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class bus implements charge{
|
||||
@Override
|
||||
public void charge() {
|
||||
System.out.println("publicBus: 1$/sheet, No Limit Kilometer");
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public interface charge {
|
||||
public void charge();
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class cinema implements play, charge {
|
||||
@Override
|
||||
public void play() {
|
||||
System.out.println("Now Showing");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void charge() {
|
||||
System.out.println("Cinema: 30$/sheet, Student half");
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class goods {
|
||||
private String goodsName;
|
||||
|
||||
public goods(String name){
|
||||
this.goodsName = name;
|
||||
}
|
||||
|
||||
// 返回商品名
|
||||
public String getName(){
|
||||
return this.goodsName;
|
||||
}
|
||||
|
||||
// 设置商品名
|
||||
public void setName(String name){
|
||||
this.goodsName = name;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class market {
|
||||
private String marketName;
|
||||
private String marketGoodsList;
|
||||
|
||||
public market(String name){
|
||||
this.marketName = name;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.marketName;
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
this.marketName = name;
|
||||
}
|
||||
|
||||
public void getGoodsList(){
|
||||
System.out.println(this.marketGoodsList);
|
||||
}
|
||||
|
||||
public void setGoodsList(String goodlist){
|
||||
this.marketGoodsList = goodlist;
|
||||
}
|
||||
|
||||
public String sell(){
|
||||
return "yee~";
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class person {
|
||||
// 姓名
|
||||
private String personName;
|
||||
// 性别
|
||||
private String personGender;
|
||||
// 年龄
|
||||
private int personAge;
|
||||
|
||||
public person(String name, String gender, int age){
|
||||
this.personName = name;
|
||||
this.personGender = gender;
|
||||
this.personAge = age;
|
||||
}
|
||||
|
||||
public String getInfo(){
|
||||
String bunchInfo;
|
||||
bunchInfo = this.personName + "-" + this.personGender + "-" + this.personAge;
|
||||
return bunchInfo;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class person_no3 {
|
||||
private String personName;
|
||||
|
||||
public String getName(){
|
||||
return this.personName;
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
this.personName = name;
|
||||
}
|
||||
|
||||
public void shopping(){
|
||||
System.out.println("rob");
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public interface play {
|
||||
public void play();
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class student extends person {
|
||||
// 学号
|
||||
private int studentID;
|
||||
// 哲学成绩
|
||||
private int studentPhilosophyScore;
|
||||
// 英语成绩
|
||||
private int studentEnglishScore;
|
||||
// 计算机成绩
|
||||
private int studentComputerScore;
|
||||
|
||||
// 构造函数
|
||||
public student(String name, String gender, int age, int id, int philosophy, int english, int computer) {
|
||||
super(name, gender, age);
|
||||
this.studentID = id;
|
||||
this.studentPhilosophyScore = philosophy;
|
||||
this.studentEnglishScore = english;
|
||||
this.studentComputerScore = computer;
|
||||
}
|
||||
|
||||
// 三门课平均成绩
|
||||
public int aver(){
|
||||
return (this.studentPhilosophyScore + this.studentEnglishScore + this.studentComputerScore) / 3;
|
||||
}
|
||||
|
||||
// 最高分
|
||||
public double max(){
|
||||
return Math.max(Math.max(this.studentComputerScore, this.studentEnglishScore), this.studentPhilosophyScore);
|
||||
}
|
||||
|
||||
// 最低分
|
||||
public int min(){
|
||||
return Math.min(Math.min(this.studentComputerScore, this.studentPhilosophyScore), this.studentEnglishScore);
|
||||
}
|
||||
|
||||
public String getInfo(){
|
||||
String bunchInfo;
|
||||
bunchInfo = this.studentID + "-" + super.getInfo() + "-" + aver() + "-" + max() + "-" + min();
|
||||
return bunchInfo;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class taxi implements play{
|
||||
@Override
|
||||
public void play() {
|
||||
System.out.println("Taxi: 1.6$/Kilometer, Starting 3 Kilometer");
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class test{
|
||||
|
||||
/*
|
||||
* class:
|
||||
* person.java
|
||||
* student.java
|
||||
public static void main (String[] args){
|
||||
student s1 = new student("test", "man", 10, 101, 80, 60, 50);
|
||||
|
||||
System.out.println(s1.getInfo());
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* interface:
|
||||
* charge.java
|
||||
* play.java
|
||||
* class:
|
||||
* bus.java
|
||||
* taxi.java
|
||||
* cinema.java
|
||||
public static void main (String[] args){
|
||||
cinema c1 = new cinema();
|
||||
|
||||
c1.charge();
|
||||
c1.play();
|
||||
|
||||
bus b1 = new bus();
|
||||
b1.charge();
|
||||
|
||||
taxi t1 = new taxi();
|
||||
t1.play();
|
||||
}
|
||||
*/
|
||||
|
||||
public static void main (String[] args){
|
||||
goods g1 = new goods("black_man");
|
||||
|
||||
System.out.println(g1.getName());
|
||||
g1.setName("rainbow_main");
|
||||
|
||||
market m1 = new market("limit");
|
||||
|
||||
System.out.println(m1.getName());
|
||||
m1.setName("no limit");
|
||||
m1.setGoodsList("one black_man - two black_man - three black-man");
|
||||
m1.getGoodsList();
|
||||
System.out.println(m1.sell());
|
||||
|
||||
person_no3 pn1 = new person_no3();
|
||||
|
||||
System.out.println(pn1.getName());
|
||||
pn1.setName("todd");
|
||||
pn1.shopping();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user