JAVA
6-Tong
a super student in BUPT!
展开
-
EBU4201 Mini Project 完整版
import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.BorderFactory;import javax.swing.JOptionPane;/** * Description : this is the main method and can store the information that * entered .原创 2021-06-28 22:43:44 · 745 阅读 · 0 评论 -
EBU4201 Java Mid-Term Test
原创 2021-06-16 21:29:30 · 2047 阅读 · 0 评论 -
EBU4201 Mini Project 操作指南
Task1: public class MyFrame extends JFrame implements ActionListener1、关于panel的使用panel1 = new JPanel(new BorderLayout());panel2 = new JPanel();// panel1 panel1.add(label1, BorderLayout.CENTER); // panel2 panel2.add(textField1); panel2.add(t原创 2021-06-05 11:44:50 · 1061 阅读 · 1 评论 -
Week 4 界面的第二个例子——用类的方法创建一个界面
package GUI;import javax.swing.JButton;import javax.swing.JFrame;public class FrameDemo extends JFrame{ public FrameDemo() { this.setTitle("testTitle"); this.setSize(200, 500); JButton myButton = new JButton("click"); this.getContentPane(原创 2021-05-25 21:08:36 · 111 阅读 · 0 评论 -
Week4 一个简单的界面
package GUI;import javax.swing.JButton;import javax.swing.JFrame;public class SimpleGUI{ public static void main(String[] args) { // TODO Auto-generated method stub JFrame myFrame = new JFrame(); myFrame.setSize(200, 200); JButton myButto原创 2021-05-25 21:01:14 · 116 阅读 · 0 评论 -
EBU4201 MidTerm Sample Questions期中考试样题
b6注意选项之间的差别,有空格!package MidTerm;public class Example1{ public static void main(String[] args) { // question1 byte a = 0; a++; System.out.println(a);// 1 // question2 System.out.println((int) (5.7 + 1)); System.out.println();.原创 2021-05-12 11:55:26 · 821 阅读 · 0 评论 -
JAVA Lab 5 Problem-2 答案与解析
package problem2;public abstract class Monster{ String name; double spAttackPropability = 0.2;// public Monster(String name, double spAttackPropability)// {// this.name = name;// this.spAttackPropability = spAttackPropability;// }//// publi.原创 2021-05-10 16:10:12 · 605 阅读 · 0 评论 -
javadoc 生成方法详细讲解
1、javadoc 为何物?** 大致来讲是为了让其他人快速了解本这个文件 及文件中方法的参数调用情况、返回值类型的“清单”2、javadoc 生成方法step1: 在文件内写描述整个文件的注释/** * Title: Cat.java Description: This class contains the definition of a cat * * @author wang * @version 1.1 * */Note: 第一行/ 后面一定是两个星号step2: 在原创 2021-05-08 12:55:42 · 772 阅读 · 0 评论 -
JAVA Lab 5 答案与解析 problem1
package problem1;public class Monster{ String name; public Monster(String name) { this.name = name; } public int attack() { int x; x = (int) (Math.random() * 5 + 1); System.out.println( this.name + " ," + "of type" + getClass() + .原创 2021-05-07 20:47:02 · 799 阅读 · 2 评论 -
Week2-12 abstractExample
package abstractExample;import java.awt.Color;public abstract class Creature{ protected String name, tailType; protected Color color; protected int speed; public abstract int run(int duration, boolean zigzag); public void swim(int duration) {原创 2021-05-05 11:27:05 · 107 阅读 · 0 评论 -
解决The package java.awt is not accessible
提示The package java.awt is not accessible?解决办法:在modules.java里声明 requires java.desktop;如图:原创 2021-04-17 13:46:07 · 515 阅读 · 0 评论 -
Week2 -11example 2 用ArrayList 实现游戏功能
import java.util.ArrayList;public class Version2{ private ArrayList<String> myList; private void setArrayList(ArrayList<String> x) { myList = x; } public String check(String x) { String result = "miss"; boolean result2 = myLis原创 2021-04-12 22:40:31 · 68 阅读 · 0 评论 -
Week 2-11 example 1 Basic of ArrayList
import java.util.ArrayList;public class Test{ public static void main(String[] args) { // make a list of flower ArrayList<Flower> myList = new ArrayList<>(); Flower f = new Flower(); Flower m = new Flower(); myList.add(f); myLi原创 2021-04-12 22:38:16 · 57 阅读 · 0 评论 -
Week 2 -10 SimpleDotCom
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;/** * GameHelper class from Head First Java: Second Edition, Authors: Kathy Sierra * and Bert Bates. * */public class GameHelper.原创 2021-04-11 22:28:10 · 152 阅读 · 0 评论 -
JAVA LAB3 问题3-答案与解析
public class Counter{ private int count; private int max;//question 1 create a constructor public Counter() { this.count = 0; this.max = 10; }//question 2 create getter and setter for count and max public int getCount() { return count; .原创 2021-04-07 14:44:26 · 515 阅读 · 0 评论 -
JAVA LAB3 问题2-答案与解析
public class Rectangle{ private int l; private int w; public Rectangle(int l, int w) { this.l = l; this.w = w; } public int area() { return l * w; } public static void main(String[] args) { Rectangle r1 = new Rectangle(8, 6); Sys.原创 2021-04-07 13:28:19 · 349 阅读 · 0 评论 -
JAVA LAB3 问题1-答案与解析
import java.awt.Color;public class Cat{ private String name, furType; private boolean tail; private Color colour; private int speed; public String getName() { return name; } public void setName(String name) { this.name = name; } publi.原创 2021-04-07 13:16:02 · 588 阅读 · 0 评论 -
LAB2 问题四 答案与解析
public class CountDownExample{ public void countdown(int count) { for (int i = count; i > 0; i--) { System.out.println(i); } System.out.println("\nTime is up"); } public static void main(String[] args) { CountDownExample counter = .原创 2021-04-02 08:04:40 · 165 阅读 · 0 评论 -
LAB2 问题3 答案与解析
public class Pattern1{ public void printfPattern1(int x) { for (int i = 1; i <= x; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } }}public class Pattern2{ public void print.原创 2021-03-29 14:10:19 · 146 阅读 · 0 评论 -
LAB2 问题2 答案与解析
public class Pattern2{ public static void main(String[] args) { int x = Integer.parseInt(args[0]); for (int i = x; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j); } System.out.println(); } }}终端操作代.原创 2021-03-29 13:54:22 · 132 阅读 · 0 评论 -
LAB2 问题1 答案与解析
public class Pattern1{ public static void main(String[] args) { int x = Integer.parseInt(args[0]); for (int i = 1; i <= x; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } }}操.原创 2021-03-29 13:44:54 · 204 阅读 · 0 评论 -
Week2-09-Example5 数组作为参数
public class TestPass{ public static void main(String[] args) { double d[] = { 2, 2, 2 }; PassByTest b = new PassByTest(); System.out.println("Before Mutate:"); b.printArray(d); System.out.println("After Mutate:"); b.mutate(d); b.printA原创 2021-03-22 16:12:03 · 71 阅读 · 0 评论 -
Week2-09-Example4 整体复制一个数组的两种方法
public class CopyArrays{ public static void main(String[] args) { double array[] = new double[6]; array[0] = 9.8; array[1] = 4.8; array[2] = 5; array[3] = 7.0088; double array2[] = new double[array.length]; for (int i = 0; i < array.le原创 2021-03-22 15:12:46 · 62 阅读 · 0 评论 -
Week2-09-Example3 toString 用成员方法+主函数的println 输出一个类的所有信息
在主函数中:for (int i = 0; i < racers.length; i++) { System.out.println(racers[i].toString()); }Note: 主函数中不要忘记System.out.println在class中:public String toString() { return this.getName() + " is a " + this.getFurtype() + " Rabbit that runs at " +原创 2021-03-22 13:54:47 · 147 阅读 · 0 评论 -
Week2-09-Example2使用array.length 输出数组
public class Example2{ public static void main(String[] args) { double array[] = new double[6]; array[0] = 9.8; array[1] = 4.8; array[2] = 5; array[3] = 7.0088; System.out.println(array.length); for (int i = 0; i < array.length; i++)原创 2021-03-22 10:47:54 · 96 阅读 · 0 评论 -
Week2-09-Example1 在main 的字符串数组,统计输入字符串个数,单独输出每个字符串
需要用终端操作,如图:代码public class Example1{ public static void main(String[] args) { System.out.println(args.length); for (int i = 0; i < args.length; i++) { System.out.println(args[i]); } }}原创 2021-03-22 10:40:59 · 59 阅读 · 0 评论 -
Week2-09-Rabbit 类数组实现具体方法
类数组的声明方法:类数组与“结构体数组”思想类似~Rabbit[] racers = new Rabbit[3];使用方法:racers[0] = new Rabbit("Bugs", "Fluffy", 150);按照此格式,对类数组中的每一个元素进行赋值```csspublic class Rabbit{ public Rabbit(String name, String furtype, int speed) { super(); this.name = name;原创 2021-03-21 17:30:16 · 127 阅读 · 0 评论 -
超级实用 在eclipse中自动建立 constructor,getter 和 setter的方法:
在eclipse中自动建立 constructor,getter 和 setter的方法:选中相关变量 右键,点击下图对应的按钮即可,之后就会发现相关的代码就被写在里面了!原创 2021-03-21 17:23:40 · 336 阅读 · 0 评论 -
Java Lab1 Problem5--EBU4201 Lab1 答案与解析
public class Problem5{ public static void main(String[] args) { int loopUntil = Integer.parseInt(args[0]); for (int i = 0; i < loopUntil; i++) { System.out.print(" " + i); System.out.print(":"); for (int j = loopUntil; j > 0; j--).原创 2021-03-21 16:25:45 · 379 阅读 · 0 评论 -
Java Lab1 Problem4--EBU4201 Lab1 答案与解析
public class DoublingNumbers_v1_problem4{ public static void main(String[] args) { int i = 1; while (i <= 10) { System.out.println("The double of " + i + "is" + 2 * i); i++; } // do-while method System.out.println(); i = 1; d..原创 2021-03-21 16:02:37 · 302 阅读 · 0 评论 -
Java Lab1 Problem3--EBU4201 Lab1 答案与解析
public class BMICalculator{ public static void main(String[] args) { double weight = Integer.parseInt(args[0]); double height = Integer.parseInt(args[1]); height = height / 100; double BMI; BMI = weight / height / height;//// System.out.p.原创 2021-03-21 16:00:52 · 349 阅读 · 0 评论 -
Java Lab1 Problem2--EBU4201 Lab1 答案与解析
Integer.parseInt(args[0]) 是把读到的字符串转化成int类型solution:public class WeekDayConverter{ public static void main(String[] args) { int weekDay = Integer.parseInt(args[0]); switch (weekDay) { case 1: System.out.println("The 1th day of the week is .原创 2021-03-21 13:30:55 · 341 阅读 · 0 评论 -
Java Lab1 Problem1--EBU4201 Lab1 答案与解析
一、背景知识:利用String[] args 读入字符串参数必须要用终端操作二、以macOS为例:1、首先创建好.java 文件保存到一个文件夹里public class TestArgs{ public static void main(String[] args) { System.out.println("args[0] = " + args[0]); }}2、打开终端,选择路径:cd+空格,然后把刚才的文件夹拖到终端编译:javac TestArgs.java.原创 2021-03-20 21:40:07 · 611 阅读 · 0 评论 -
Flower_OOexample-6
package flower;public class Test{ public static void main(String[] args) { Flower f1 = new Flower("red", 2.5); Flower f2 = new Flower("blue", 4.5); f1.getColour(); f1.getHeight(); f2.getColour(); f2.getHeight(); f1.setHeight(4.0); f1.原创 2021-03-18 15:02:44 · 77 阅读 · 0 评论 -
SomeThing_OOexample-6 实例变量可以不初始化但方法中的(本地)变量必须要初始化
```javapackage someThing;public class Test{ public static void main(String[] args) { SomeThing sth = new SomeThing(); sth.getAandB(); System.out.println("after the executing the method doIt:"); int total = sth.doIt(); System.out.println(t.原创 2021-03-18 14:06:13 · 61 阅读 · 0 评论 -
Encapsulation_OOexample-5
package dataEncapsulation;public class CatMain{ public static void main(String[] args) { CatNew cat1 = new CatNew("Catty", "red", 4);// System.out.println(cat1.name); String colour = cat1.getCoulur(); System.out.println(colour); cat1.eat()原创 2021-03-16 17:54:43 · 83 阅读 · 0 评论 -
保姆级Java环境配置与VSCode配置
推荐一个同学录制的JAVA环境配置:https://www.bilibili.com/video/av802018331/备注:MacOS 不需要配置JAVA运行环境~原创 2021-03-11 13:39:55 · 159 阅读 · 0 评论 -
CatThisClassTest_example-4 Java中this的用法;利用类的方法初始化类参数
package week1;public class CatThisClassTest{ public static void main(String[] args) { CatThis cat1 = new CatThis("Fluffy", "", 3); CatThis cat2 = new CatThis("Catty", "red", 4); System.out.println("information about cat1: "); cat1.information原创 2021-03-11 13:36:46 · 69 阅读 · 0 评论 -
CatTestClass_OOexample-3
package week1;public class CatTestClass{ public static void main(String[] args) { Cat myCat = new Cat(); myCat.name = "Fluffy"; System.out.print(myCat.name + " "); myCat.meow(); Cat myCat2 = new Cat(); myCat2.name = "Catty"; myCat2.eat(原创 2021-03-11 11:46:46 · 91 阅读 · 0 评论 -
TestMaths_OOexample 2
public class TestMaths{// public int doSomeMaths(int x, int y) int doSomeMaths(int x, int y) { int temp; if (x > y) temp = x * y; else if (x < y) temp = x + y; else temp = x; return temp; } public static void main(String[]原创 2021-03-11 11:24:57 · 72 阅读 · 0 评论