跳至主要內容

Project B

AI悦创原创Python 一对一教学uicUTSPython 一对一教学uicUTS大约 12 分钟...约 3632 字

ASSESSMENT TASK 2 : CREATING ADVANCED JAVA CLASSES AND ARRAYS

评估任务2:创建高级Java类和数组

TASK DESCRIPTION

任务描述

This project requires you to write advanced Java classes with attributes, methods, arrays, if statements and loops. Code must be written that creates objects, stores them in an array and uses loops to iterate through the array of objects. You also need to use a menu to drive the program.

这个项目需要你编写高级的Java类,包括属性、方法、数组、if语句和循环。必须编写代码创建对象、将它们存储在数组中,并使用循环来遍历对象数组。你还需要使用菜单来驱动程序。

OBJECTIVES

目标

  • Design and code a software system that correctly implements a solution to a small problem defined by a specification, and follows specific design rules

设计和编写一个软件系统,正确地实现规范定义的小问题的解决方案,并遵循特定的设计规则。

  • Comprehend and use basic program control constructs of sequence, selection and iteration

理解并使用程序控制结构中的顺序、选择和迭代基本构造。

  • Comprehend and use code that implements arrays and the basic sorting and searching algorithms

理解和使用实现数组、基本排序和搜索算法的代码。

BRIEF

简短的

Take home assessment to evaluate your understanding of object oriented concepts taught so far in IPRG001. The assessment will use your solution for Project A as a base. Project B will be composed of 3 parts: the updated scenario, the code and explanation (including proof of testing).

家庭作业评估,用于评估您对于IPRG001中到目前为止教授的面向对象概念的理解。该评估将以您对于A项目的解决方案为基础。B项目将由三个部分组成:更新的场景,代码和解释(包括测试证明)。

The scenario:

情境:

You will adapt your scenario from Project A to meet the requirements for project B. Perhaps it is a shop that sells class1 objects.

您将根据项目B的要求调整您从项目A中得出的场景。也许这是一家出售一类物品的商店。

Use class diagrams to document your class design.

使用类图来记录您的类设计。

The code:

这是一个代码:

Choose one of the thing classes(class1 or class2) and write a main class to store an array of objects.

选择一个事物类别(class1或class2),并编写一个主类来存储对象数组。

Write a menu() in the main class, to allows the user to view the contents of each object in the array, change the attribute value of one specific object, change the attribute value of all objects in the array.

在主类中编写一个 menu() 方法,允许用户查看数组中每个对象的内容,更改特定对象的属性值,以及更改数组中所有对象的属性值。

The explanation:

解释/说明

You will explain the code you wrote, at minimum you need to identify:

你将解释你编写的代码,至少需要识别以下内容:

Array size, name, objects held and indexes available.

数组大小、名称、包含的对象以及可用的索引。

For loops used, what conditions you chose and why.

使用for循环时,你选择了什么条件,以及为什么选择这些条件。

The menu code and explain what control structures are present in a menu and why they are needed.

菜单代码并解释菜单中存在哪些控制结构以及它们的必要性。

You also need to include at least 1 screen shot of your code being testing on the object bench.

您还需要至少包括一张代码在物体测试台上测试的截屏。

Please double check your code compiles and your submission document contains the updated version of all code prior to submission.

请务必确认您的代码可以编译,并且在提交之前,您的提交文档包含了所有更新版本的代码。

SUBMISSION

You will submit your assessment in MS Word document format – yourName-studNo.doc.

您将以 MS Word 文档格式提交您的评估报告 - 您的姓名-学号.doc。

The document will have 3 sections:

这份文件将分为3个部分:

The scenario: You will write the back story for your program – this will be assessed using LLO minimum 100 words

情景:您将为您的程序编写背景故事 - 这将使用LLO进行评估,最少100个单词。

The Code: You will copy the code from your BlueJ project into this section

代码:您将把BlueJ项目中的代码复制到此部分。

The explanation: you will explain your code choices and reasoning. You also need to include at least one screenshot of testing your code. Include any issues you had and how you resolved them. Minimum 300 words.

说明:您将解释您的代码选择和推理。您还需要包括至少一张测试您的代码的屏幕截图。包括您遇到的任何问题以及如何解决它们。最少300个单词。

在编写代码时,编程者通常需要做出许多决策,这些决策可能包括算法、数据结构、变量名等等。在此次项目中,我选择了一种用于检测图像中人脸的算法,这个算法名为人脸识别算法。我选择这个算法是因为它在识别人脸方面非常准确和可靠。

为了实现这个算法,我使用了Python编程语言和OpenCV库。我首先导入了OpenCV库,并将其用于读取图像文件和检测人脸。然后,我使用了一个名为Haar级联分类器的算法来检测图像中的人脸。这个算法通过识别人脸特征来确定人脸的位置,如眼睛、鼻子和嘴巴等。

在代码的实现过程中,我遇到了一些问题。例如,我发现有时候算法无法正确检测到图像中的人脸,特别是在图像中存在遮挡物或光线不足的情况下。为了解决这个问题,我尝试了几种不同的方法,包括增加训练数据、调整算法参数等。最终,我发现通过增加训练数据可以有效提高算法的准确性。

在测试我的代码时,我运行了几个图像文件,以确保它们能够正确地检测到人脸。我还创建了一个测试套件,其中包括了一系列不同的图像和场景,以测试算法的鲁棒性和准确性。在测试过程中,我发现我的代码在大多数情况下都能够正确检测到人脸,但在某些情况下可能会出现错误的检测结果。为了解决这个问题,我进一步调整了算法参数,并增加了一些特殊情况的处理逻辑。

总的来说,这个项目让我更深入地了解了人脸识别算法和OpenCV库,并提高了我的编程技能和解决问题的能力。我相信这个项目将对我的未来职业发展有所帮助。

Compress you BlueJ project and submit it and a zip file studentNo.zip as evidence of your work.

压缩您的BlueJ项目,并将其作为学号.zip文件一并提交,作为您的工作证据。

The deadline for this project is Friday 11:59pm, week 9.

这个项目的截止日期是第9周的星期五晚上11:59。

Week 8 tutorial B - Incorporate Feedback from Project A

第八周教程B - 合并项目A的反馈意见

All projects submitted after the deadline will incur late penalties of 1 grade band every 2 days (or part thereof).

所有在截止日期之后提交的项目将会产生迟交惩罚,每延迟两天(或不足两天)将会扣除一级分数。

ASSESSMENT CRITERIA

评估标准

**ASSESSMENT TASK 2 : CREATING ADVANCED JAVA CLASSES AND ARRAYS**
**TASK DESCRIPTION**
This project requires you to write advanced Java classes with attributes, methods, arrays, if statements and loops. Code must be written that creates objects, stores them in an array and uses loops to iterate through the array of objects. You also need to use a menu to drive the program.
**OBJECTIVES**
- Design and code a software system that correctly implements a solution to a small problem defined by a specification, and follows specific design rules
- Comprehend and use basic program control constructs of sequence, selection and iteration
- Comprehend and use code that implements arrays and the basic sorting and searching algorithms
**BRIEF**
Take home assessment to evaluate your understanding of object oriented concepts taught so far in IPRG001. The assessment will use your solution for Project A as a base. Project B will be composed of 3 parts: the updated scenario, the code and explanation (including proof of testing).
The scenario:
You will adapt your scenario from Project A to meet the requirements for project B. Perhaps it is a shop that sells class1 objects.
Use class diagrams to document your class design.
The code:
Choose one of the thing classes(class1 or class2) and write a main class to store an array of objects. 
Write a menu() in the main class, to allows the user to view the contents of each object in the array, change the attribute value of one specific object, change the attribute value of all objects in the array.
The explanation:
You will explain the code you wrote, at minimum you need to identify:
Array size, name, objects held and indexes available.
For loops used, what conditions you chose and why.
The menu code and explain what control structures are present in a menu and why they are needed.
You also need to include at least 1 screen shot of your code being testing on the object bench.
**Please double check your code compiles and your submission document contains the updated version of all code prior to submission.**
**SUBMISSION**
You will submit your assessment in MS Word document format – yourName-studNo.doc. 
The document will have 3 sections:
The scenario: You will write the back story for your program – this will be assessed using LLO minimum 100 words
The Code: You will copy the code from your BlueJ project into this section
The explanation: you will explain your code choices and reasoning. You also need to include at least one screenshot of testing your code. Include any issues you had and how you resolved them. Minimum 300 words.
Compress you BlueJ project and submit it and a zip file studentNo.zip as evidence of your work.
**The deadline for this project is Friday 11:59pm, week 9.**
Week 8 tutorial B - Incorporate Feedback from Project A
**All projects submitted after the deadline will incur late penalties of 1 grade band every 2 days (or part thereof).**
公众号:AI悦创【二维码】

AI悦创·编程一对一

AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh

C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh

方法一:QQopen in new window

方法二:微信:Jiabcdefh

.
Part A 的项目代码如下:
文件名称:src/MainEntry.java,代码内容如下:
import TokTacToe.TicTacToeGame;
import Card.CardGame;
import java.util.InputMismatchException;
import java.util.Scanner;
public class MainEntry {
    public static void main(String[] args) {
        int selectGame = -1;
        while (selectGame == -1) {
            Scanner in = new Scanner(System.in);
            try {
                System.out.println("1. 3*3 TicTacToeGame:");
                System.out.println("2. 扑克牌比大小 ");
                System.out.println("请输入要玩的游戏:");
                int userSelect = in.nextInt();
                if (userSelect == 1 || userSelect == 2) {
                    selectGame = userSelect;
                    break;
                } else {
                    System.out.println(
                            "输入的数字无效!请重新选择要玩的游戏:");
                    continue;
                }

            } catch (InputMismatchException e) {
                System.out.println(
                        "输入的数字无效!请重新输入一个数字:");
                continue;
            }
        }
        if (selectGame == 1) {
            new TicTacToeGame().startGame();
        }
        if (selectGame == 2) {
            new CardGame().startGame();
        }
    }
}
文件名称:src/Card/Card.java,代码内容如下:
package Card;
public class Card {
    public String rank;
    public Card(String rank) {
        this.rank = rank;
    }
    public String getRank() {
        return rank;
    }
    public void setRank(String rank) {
        this.rank = rank;
    }

    @Override
    public String toString() {
        return "Card{" +
                "rank='" + rank + '\'' +
                '}';
    }
}

文件名称:src/Card/CardGame.java,代码内容如下:
package Card;
public class CardGame {
    private GameControl control;
    public void startGame() {
        System.out.println("====扑克游戏开始====");
        control = new GameControl(); 
        Card playerCard = control.randomGetCard();
        Card computerCard = control.randomGetCard();
        System.out.println(playerCard.toString());
        System.out.println(computerCard.toString());
        System.out.println("玩家卡片:" + playerCard.getRank());
        System.out.println("电脑卡片:" + computerCard.getRank());
        String result = control.isSmall(playerCard, computerCard);
        if (!result.isEmpty()) {
            if (result.equals("equal")) {
                System.out.println("平局!");
            }
            if (result.equals("smaller")) {
                System.out.println("电脑获胜!" + computerCard.toString());
            }
            if (result.equals("large")) {
                System.out.println("玩家获胜!" + playerCard.toString());
            }
        } else {
            System.out.println("程序异常,请重新开始!");
        }
    }
}
文件名称:src/Card/GameControl.java,代码内容如下:
package Card;
import java.util.ArrayList;
import java.util.Random;
public class GameControl {
    ArrayList<Card> cards = new ArrayList<Card>();
    ArrayList<Card> allCards = new ArrayList<Card>();
    public GameControl() {
        initCards();
        intiGame();
    }
    private void initCards() {
        String[] cardNum = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        for (int i = 0; i < cardNum.length; i++) {
            cards.add(new Card(cardNum[i]));
        }
    }
    private void intiGame() {
        for (int i = 0; i < cards.size(); i++) {
            for (int j = 1; j < 5; j++) {
                allCards.add(cards.get(i));
            }
        }
    }
    public Card randomGetCard() {
        int index = new Random().nextInt(allCards.size());
        return allCards.get(index);
    }
    public String isSmall(Card first, Card second) {
        int firstIndex = -1;
        int secondIndex = -1;
        for (int i = 0; i < cards.size(); i++) {
            Card card = cards.get(i);
            if (card.getRank().equals(first.getRank())) {
                firstIndex = i;
            }
            if (card.getRank().equals(second.getRank())) {
                secondIndex = i;
            }
        }
        if (firstIndex == secondIndex) {
            return "equal";
        }
        if (firstIndex < secondIndex) {
            return "smaller";
        }
        if (firstIndex > secondIndex) {
            return "large";
        }
        return "";
    }

    @Override
    public String toString() {
        return "GameControl{" +
                "cards=" + cards +
                ", allCards=" + allCards +
                '}';
    }
}
文件名称:src/TokTacToe/GamePanel.java,代码内容如下:
package TokTacToe;
import java.util.Arrays;
public class GamePanel {
    private String[] gamePlaneBlock;
    private int playGroudSize = 9;
    public GamePanel(int playGroudSize) {
        this.playGroudSize = playGroudSize;
    }
    public String[] getGamePlaneBlock() {
        return gamePlaneBlock;
    }
    public String getTargetBlock(int index) {
        if (getGamePlaneBlock().length > 0) {
            return getGamePlaneBlock()[index];
        } else
            return "";
    }
    public void setBlock(int index, String playerName) {
        if (getGamePlaneBlock().length > 0) {
            getGamePlaneBlock()[index] = playerName;
        }
    }
    public boolean hasEmptyBLock() {
        for (int i = 0; i < getGamePlaneBlock().length; i++) {
            if (getGamePlaneBlock()[i].equals(String.valueOf(i + 1))) {
                return true;
            }
        }
        return false;
    }
    public void setGamePlaneBlock(String[] gamePlaneBlock) {
        this.gamePlaneBlock = gamePlaneBlock;
    }
    public int getPlayGroudSize() {
        return playGroudSize;
    }
    public void setPlayGroudSize(int playGroudSize) {
        this.playGroudSize = playGroudSize;
    }

    public void printGamePlane() {
        System.out.println("|---|---|---|");
        System.out.println("| " + getGamePlaneBlock()[0] + " | "
                + getGamePlaneBlock()[1] + " | " + getGamePlaneBlock()[2]
                + " |");
        System.out.println("|-----------|");
        System.out.println("| " + getGamePlaneBlock()[3] + " | "
                + getGamePlaneBlock()[4] + " | " + getGamePlaneBlock()[5]
                + " |");
        System.out.println("|-----------|");
        System.out.println("| " + getGamePlaneBlock()[6] + " | "
                + getGamePlaneBlock()[7] + " | " + getGamePlaneBlock()[8]
                + " |");
        System.out.println("|---|---|---|");
    }

    @Override
    public String toString() {
        return "GamePanel{" +
                "gamePlaneBlock=" + Arrays.toString(gamePlaneBlock) +
                ", playGroudSize=" + playGroudSize +
                '}';
    }
}
文件名称:src/TokTacToe/Player.java,代码内容如下:
package TokTacToe;
public class Player {
    private String name;
    public Player(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Override
    public String toString() {
        return "Player{" +
                "name='" + name + '\'' +
                '}';
    }
}
文件名称:src/TokTacToe/TicTacToeGame.java,代码内容如下:
package TokTacToe;
import java.util.InputMismatchException;
import java.util.Scanner;
public class TicTacToeGame {
    static String currentPlayer;
    static GamePanel gamePanel;
    static int playGroudSize = 9;
    static Player xplayer;
    static Player oplayer;
    static Player winner;
    private static boolean hasWinner = false;
    static Player checkWinner(Player winner) {
        for (int a = 0; a < 8; a++) {
            String line = null;
            switch (a) {
                case 0:
                    line = gamePanel.getTargetBlock(0) + gamePanel.getTargetBlock(1) + gamePanel.getTargetBlock(2);
                    break;
                case 1:
                    line = gamePanel.getTargetBlock(3) + gamePanel.getTargetBlock(4) + gamePanel.getTargetBlock(5);
                    break;
                case 2:
                    line = gamePanel.getTargetBlock(6) + gamePanel.getTargetBlock(7) + gamePanel.getTargetBlock(8);
                    break;
                case 3:
                    line = gamePanel.getTargetBlock(0) + gamePanel.getTargetBlock(3) + gamePanel.getTargetBlock(6);
                    break;
                case 4:
                    line = gamePanel.getTargetBlock(1) + gamePanel.getTargetBlock(4) + gamePanel.getTargetBlock(7);
                    break;
                case 5:
                    line = gamePanel.getTargetBlock(2) + gamePanel.getTargetBlock(5) + gamePanel.getTargetBlock(8);
                    break;
                case 6:
                    line = gamePanel.getTargetBlock(0) + gamePanel.getTargetBlock(4) + gamePanel.getTargetBlock(8);
                    break;
                case 7:
                    line = gamePanel.getTargetBlock(2) + gamePanel.getTargetBlock(4) + gamePanel.getTargetBlock(6);
                    break;
            }
            if (line.equals("XXX")) {
                hasWinner = true;
                return xplayer;
            } else if (line.equals("OOO")) { 
                hasWinner = true;
                return oplayer;
            }
        }
        if (gamePanel.hasEmptyBLock()) {
            winner.setName("");
            hasWinner = false;
        } else {
            winner.setName("equal");
            hasWinner = false;
            return winner;
        }
        System.out.println("轮到 " + currentPlayer + " 请输入一个数字的数字: ");
        return winner;
    }

    public void startGame() {
        System.out.println("====Tic Tac游戏开始====");
        gamePanel = new GamePanel(playGroudSize);
        xplayer = new Player("X");
        oplayer = new Player("O");
        System.out.println(xplayer.toString());
        System.out.println(oplayer.toString());
        winner = new Player("");
        currentPlayer = xplayer.getName();
        String[] blocks = new String[9];
        for (int i = 0; i < playGroudSize; i++) {
            blocks[i] = String.valueOf(i + 1);
        }
        gamePanel.setGamePlaneBlock(blocks);
        System.out.println("欢迎来带 3x3 Tic Tac Toe 游戏");
        gamePanel.printGamePlane();

        System.out.println(
                "玩家 X 先玩。请输入数字来把 X 放入指定格子 :");

        while (winner.getName().equals("")) {
            int numInput;
            Scanner in = new Scanner(System.in);
            try {
                numInput = in.nextInt();
                if (!(numInput > 0 && numInput <= 9)) {
                    System.out.println(
                            "输入的数字无效!请重新输入一个数字:");
                    continue;
                }
            } catch (InputMismatchException e) {
                System.out.println(
                        "输入的数字无效!请重新输入一个数字:");
                continue;
            }
            if (gamePanel.getTargetBlock(numInput - 1).equals(String.valueOf(numInput))) {
                gamePanel.setBlock(numInput - 1, currentPlayer);
                if (currentPlayer.equals("X")) {
                    currentPlayer = "O";
                } else {
                    currentPlayer = "X";
                }
                gamePanel.printGamePlane();
                winner = checkWinner(winner);
            } else {
                System.out.println(
                        "当前格子已被占领,请重新输入一个格子数字:");
            }
        }
        if (winner.getName().equals("equal")) {
            System.out.println(
                    "平局,感谢参与!");
        } else {
            System.out.println(
                    "恭喜! " + winner.getName()
                            + " 获得游戏胜利!");
        }
    }
}
上次编辑于:
贡献者: AndersonHJB
你认为这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • 按正序
  • 按倒序
  • 按热度