首页 > > 详细

讲解Programming、Java语言辅导、hierarchy讲解、Java编程程序调试调试C/C++编程|解析Haskell程序

Programming Project 3

Due Wednesday, November 6 at 11:59pm

IMPORTANT: Read the Do's and Dont's in the Course Honor Policy found on blackboard.

I. Overview

The purpose of this project is to give you practice designing a class/type hierarchy. It is important that you spend time designing your class hierarchy before you start coding. If you properly organize your classes and/or interfaces, you can achieve the desired program behavior below with significantly less code than with a poorly organized hierarchy. This project will also how there are limitations to what we can do with Java's classes and interfaces.

II. Code Readability (20% of your project grade)

New for this assignment: The comments above the class or interface and above each method must be written in JavaDoc format. You will be introduced to JavaDoc style commenting in the labs. You can also find a description in the Java in a Nutshell text. Be sure to run JavaDoc and view the webpage in order to verify that you have implemented the comments correctly.

To receive the full readability marks, your code must follow the following guideline:

All variables (fields, parameters, local variables) must be given appropriate and descriptive names.
All variable and method names must start with a lowercase letter. All class and interface names must start with an uppercase letter.
The class body should be organized so that all the fields are at the top of the file, the constructors are next, the non-static methods next, and the static methods at the bottom.
There should not be two statements on the same line.
All code must be properly indented (see page 644 of the Lewis book for an example of good style). The amount of indentation is up to you, but it should be at least 2 spaces, and it must be used consistently throughout the code.
You must be consistent in your use of {, }. The closing } must be on its own line and indented the same amount as the line containing the opening {.
There must be an empty line between each method.
There must be a space separating each operator from its operands as well as a space after each comma.
There must be a comment at the top of the file that is in proper JavaDoc format and includes both your name and a description of what the class represents. The comment should include tags for the author.
There must be a comment directly above each method (including constructors) that is in proper JavaDoc format and states what task the method is doing, not how it is doing it. The comment should include tags for any parameters, return values and exceptions, and the tags should include appropriate comments that indicate the purpose of the inputs, the value returned, and the meaning of the exceptions.
There must be a comment directly above each field that, in one line, states what the field is storing.
There must be a comment either above or to the right of each non-field variable indicating what the variable is storing. Any comments placed to the right should be aligned so they start on the same column.
There must be a comment above each loop that indicates the purpose of the loop. Ideally, the comment would consist of any preconditions (if they exist) and the subgoal for the loop iteration.
Any code that is complicated should have a short comment either above it or aligned to the right that explains the logic of the code.
III. Program Testing (20% of your project grade)

New for this assignment: The testing routines should be included in a JUnit test class.

You are to write a test report that indicates the types of tests needed to thoroughly test your project. The tests should demonstrate that all of your methods behave correctly. An conditional statements will need tests that go through each branch of the execution. Any loops will need tests that cover the "test 0, test 1, test many" and "test first, test middle, test last" guidelines. Your testing report should not list the actual tests and results.

You are to have a JUnit test class or classes that implement each of the needed tests. Comments and method names in your JUnit class should connect to your testing report. For example, if your testing report states "method xxx must be tested with string inputs of different lengths", then the reader should be able to go to the JUnit class and easily identify the tests that test that method on inputs of length 0, 1, and more than 1.

The testing report must be separate from the JUnit class. In most companies, the testing document will be written in a style that allows both programmers and non-programmers to read it and recognize whether all the needed test cases were included.

IV. Java Programming (60% of your grade)

Design Rules: Your project must contain the following seven types and each type must contain the listed methods. The project may use any combination of classes, abstract classes, or interfaces that you feel is appropriate. The project may add additional types to the ones listed. The classes/types may contain additional methods to the ones listed if you feel they are needed. You may use any combination of inheritance, method overriding, and method overloading to achieve the needed behavior. Part of the coding grade will be the quality of the hierarchy you create.

Hint (repeated from above): Spend a lot of time designing your hierarchy before you code. A well designed hierarchy will reduce the amount of code you have to write.

A note on types: you may find generic types and wrapper classes to be useful in this assignment though they are not required. We will be covering both generic types and wrapper classes before this project is due but, again, they are not required for this project. If you know about generic types and wrapper classes and want to use them, you are welcome to do so because they can help reduce your coding. However, you should use them properly. That means that if the compiler gives you a warning message that you are using one incorrectly, be sure to correct the error and do not submit code that gives warnings.

Programming (60% of the project grade)

Here are two Java shortcuts you will use: enum and variable length parameters.

An overview of enum

The project will be using enum types. An enum is a shortcut for a class with a private constructor. The code

enum WeekDay {
Monday, Tuesday, Wednesday, Thursday, Friday;
you may add additional methods here
}
is identical to
public static class WeekDay {
public static final WeekDay Monday = new WeekDay();
public static final WeekDay Tuesday = new WeekDay();
public static final WeekDay Wednesday = new WeekDay();
public static final WeekDay Thursday = new WeekDay();
public static final WeekDay Friday = new WeekDay();

private WeekDay() {
}

some special helper methods provided for enums (see your text)

you may add additional methods here
}
So, WeekDay will be a static "inner" or "nested" class of whatever class you place the enum inside. The Monday, Tuesday, etc. are fields set to instances of the WeekDay class. Because the constructor is private, no other instances can be created than one instance for each of the listed fields. (Note that we do not need to override the equals method in an enum. Since no other instances can be created than those stored in the fields, you can use == to compare enum values.) As entered, you have a default private constructor for the enum, but you can create your own constructor if you wish. For example, we could create a constructor that takes a String that is the name of the day. If we do that, we would need to do the following:
enum WeekDay {
Monday("Monday"), Tuesday("Tuesday"), Wednesday("Wednesday"), Thursday("Thursday"), Friday("Friday");

private String name;

private WeekDay(String name) {
this.name = name;
}

you may add additional methods here
}
An overview of variable length parameters

A variable length parameter is a Java shortcut that can be used by a method that takes an array as input. With the shortcut, you do not need to create the array explicitly. For example:

public int maximum(int[] a) {
int max = 0;
for (int i = 1; i < a.length; i++)
if (a[i] > a[max])
max = i;
return max;
}
is the normal way we pass an array to a method. To call maximum, we must create an array first: maximum(new int[]{1, 2, 3}).
If we change maximum to take a variable length parameter, it looks like this:

public int maximum(int... a) {
int max = 0;
for (int i = 1; i < a.length; i++)
if (a[i] > a[max])
max = i;
return max;
}
Notice that the body of maximum did not change. The input a is still an array of int. However, we now have two ways to call a. We can still use the traditional way of passing in an array: maximum(new int[]{1, 2, 3}) or we can just pass in the elements and Java will automatically place them in an array of the correct size: maximum(1, 2, 3). Note that there can be only one variable length parameter per method, and the variable length parameter must be the last parameter of the method. (Can you see why?)
Your programming task

Some programming languages, like Scratch, are designed for beginning programmers, and especially children, to learn the basics of coding. In these languages, coding structures are often displayed graphically as colored blocks and shaped in a way to indicate what types of structures can be contained in other structures. The purpose of this code is to design the underlying model used for a simple Scratch-like programming language. You will design classes that represent different programming language strucrures, and then a user can program by combining the different structures together.

Your project should contain the following types. Each type can be a class or an interface. You may need to create additional types to accomplish all the tasks. The goal is to write a good hierachy that limits the amount of code you need to write:

State: The state represents the variables and their contents. Because our language is geared to true novices, the only type we will allow is integer types. Since everything is an integer, we will not have errors if a variable is used before it is assigned a value.

The State should contain a Hashtable from the Java API. You should set the key of the hashtable to be String (this will represent the names of the variables) and the values of the hashtable to be type Integer (this will represent the values stored in the variables. That is, you will represent the state as a Hashtable

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!