辅导java Assignment、讲解UML Class Diagram程序、辅导讲解java程序讲解McMaster-Carr、讲解CS5010 java

- 首页 >> Java编程


Please push your individual solutions to your designated repo within the CS5010 GitHub 
organization. Commit, push and tag a release after each part of each exercise. 
Resources 
You might find the following online resource useful while tackling this assignment:

Java 8 Online Documentation 


JUnit 4 Getting Started Online Documentation 


UML Diagram Online Documentation 
Submission Requirements 
Your repository should contain a separate package for every problem. 
The package names should follow this naming convention: assignmentN.problemM, where you replace N with the assignment number, and M with the problem number, e.g., all your code for problem 1 for this assignment must be in a package named.assignment1.problem1. 
Additional expectations for every package: 


One file per Java class 


One file per Java test class 


One pdf or image file for each UML Class Diagram that you create 


All methods must have tests 


All non-test classes and non-test methods must have valid Javadoc 
Your packages should not contain: 


Any files 


Any files 


Any IntelliJ specific files 
Lastly, a few more rules that you should follow in this assignment☺: 


•Your classes should have a public modifier

     

.java .java

.class

.html

Instance fields should have a private modifier 


Static methods or fields are not allowed 


Use this to access instance methods and fields inside a class 
ASSIGNMENT 2: Due Sept 24 Hardware Orders, Part 1 
You are implementing an automated order management and validation program for a hardware supplier. Specifically, your system will be designed to handle rotary shafts, sprockets, and standard ball and roller bearings as stocked by McMaster-Carr: 
Rotary shafts (available in metric and standard measurements): 
https://www.mcmaster.com/ - rotary-shafts/=62554d3ecbe644dd9f72e1b6addcd19ajm0sbuef 
Sprockets (standard measurement): 
https://www.mcmaster.com/ - sprockets/=f1d073e90fbf48fe9ba226127f66a2fdjm0sa73b 
Sprockets (metric measurement): 
https://www.mcmaster.com/ - sprockets/=1defba01cc5747a687323b85c2b675a4jm0sbc0d 
Precision ball bearings (metric measurement): 
https://www.mcmaster.com/ - standard-ball-and-roller- bearings/=a21dba81bd62403e9192ab90ff78e17fjm0scgth 
Refer to the links above and use real items from these lists as your test objects and to populate your stock service. 
Classes and interfaces 
For Hardware Orders, Part 1, you should begin by organizing your data in classes, subclasses, and interfaces. Your system should implement (at least) the following classes. Some of these classes may be best implemented as abstract classes, to be in turn extended by concrete classes: 


StockItem. All items that can be ordered within the system have a category, a SKU (stock-keeping unit) number, and a price. The category is at the top of the McMaster- Carr page (e.g. "Precision Ball Bearings"). The SKU# for items is listed in the unlabeled second-to-last column on the McMaster-Carr page. The price is in the last (rightmost) column. 


RotaryShaft. Rotary shafts in your system must have the following characteristics represented: length, diameter, and system of measurement. 


Sprocket. Sprockets are shaft-mounted hardware. Sprockets in your system must have the following characteristics represented: number of teeth, system of measurement, and "for shaft diameter", which indicates which sized shaft the sprocket fits on. 


         

•BallBearing. Ball bearings are also shaft-mounted. Ball bearings must have the following characteristics represented: seal type, width, and "for shaft diameter". Your system handles only ball bearings in metric measurements, so "system of measurement" is optional. You should decide whether or not to add that field, and be prepared to explain your decision as to why or why not.

Some tips:

For working with money, it's good to avoid using float and double types due to rounding errors. It's better to use int types and to deal with indivisible monetary units (i.e. cents in US currency) when possible. You may consider defining a Price class to take advantage of the toString() method for printing prices. How should such a class's constructor work? What getters and setters should it have? 


System of measurement and ball bearing seal type are two attributes that would be well represented by enum classes. Read the docs to see how to use enums to represent types with a strictly limited set of values. 
Your tasks for Hardware Orders, Part 1: 


1.Implement all required classes as concisely as possible. Use abstract classes, subclasses, and interfaces where appropriate (all of these have appropriate uses in this problem, so your solution will be expected to make use of all of them). 


2.Implement any other classes that seem appropriate to the problem domain. Try to keep the structure of the implementation as simple, clear, and consistent as possible. Think about how best to future-proof your implementation; consider realistic future changes to the requirements of a system like this, and code your solution in a way that would make accommodating foreseeable changes as easy as possible. Be prepared to discuss ways in which you have done this. 


3.Write unit tests for successful and unsuccessful cases and to test for various combinations of systems of measurement, etc. using actual data from the McMaster-Carr website links listed above. 


4.Write appropriate JavaDoc comments for all classes and methods. 


5.Provide your final UML diagram that includes the methods you defined. 


6.Commit, push, and tag a release representing your work on Hardware Orders, Part 1. 


ASSIGNMENT 3: Due Oct 8 Hardware Orders, Part 2

Now it's time to focus on the functionality of the application you began in Hardware Orders, Part 1. Extend the code from Part 1 to incorporate (at least) the following classes. As you work on the following functionality, you may find cause to re-think some of the decisions you made on Part 1. Modify those classes as necessary. The classes and methods you'll implement for Part 2 are:

•StockService. This class will mimic the behavior of a database interface. In a real application, you would have a service that retrieves items from an actual database and provides them via an API. Instead, for the purposes of this exercise, you will implement

a class that has a hand-coded hash map of stock items keyed on the items' SKU#s. The stock should include multiple instances of each category in multiple sizes and with varying attributes and measurement systems, in order to test all the necessary functionality of the system.

•OrderManager. This will be where the main functionality of your program resides. It will maintain a current order in the form of a list of SKU#s. It should implement the following public methods:

o addToOrder should take a SKU# as an argument and add that item to the current order if that item is in stock. It should give useful feedback by standard output indicating whether the item was added to the order (a SKU# that is not in stock should not be added, and the user should be informed of the issue).

o removeOneFromOrder should take a SKU# as an argument and remove one instance of that item from the current order. It should give useful feedback via standard output as to whether the item was removed.

o validateMeasurementSystem should confirm that all items in the current order conform to the same measurement system. It should return a Boolean value ("true" if all items conform and "false" if the order includes mixed measurement systems). It should also print a report to the standard output giving useful information about the measurements (it is up to you to decide what this method should report).

o filterByMeasurementSystem should take a measurement system (metric or standard) as an argument and delete all items in the order that do not conform to that measurement system, leaving only those items in the order that do conform to the measurement system.

o orderCategory will check each item in the order for its category (e.g. "Precision Ball Bearings") and return the category if all items share the same category, and return "Mixed" if the order contains items of different categories.

o printDocket should print out (to standard output) a tabulated report of the current order listing the category, SKU#, and price of each item in the order, with the total cost at the bottom of the report.

o checkFit should take two arbitrary stock item SKU#s and determine whether they represent a shaft/shaft-mounted pair of items for which the diameter of the shaft matches the "for shaft diameter" value of the shaft-mounted part. It should return a Boolean value representing whether the two items fit each other. If so, it should print a report to standard output following this format:

Precision Ball Bearings SKU# 6661K13 for 10mm shaft fits on Rotary Shafts SKU# 1482K11

If the items are a shaft/shaft-mounted pair but do not fit each other, the system should report:

Precision Ball Bearings SKU# 6661K12 for 8mm shaft does not fit on Rotary Shafts SKU# 1482K11

If the items are not a shaft/shaft-mounted pair at all (i.e. two shafts or two shaft- mounted items), or if they are not in stock at all, the system should simply report:

Not a shaft/shaft-mounted pair

This should work regardless of the order that the items are passed to the method as arguments.

Working with HashMaps and ArrayLists:

For creating a set of objects keyed on the SKU# (a String object), a hash map is a useful Java data structure. For representing the current order an ArrayList (either of SKU#s or of StockItems, you decide) would be appropriate.

Both HashMaps and ArrayLists can be specified to contain objects of certain classes using generics. A HashMap is a collection of key/value pairs and an ArrayList is an indexed sequential collection. Both are included in the java.utils library and must be imported into any file where they are used with the following import commands, which should come at the very beginning of the file:

import java.util.HashMap; import java.util.ArrayList;

Once you've imported them, you can create objects by calling the constructor with the contained classes indicated between angle brackets. So in the case of a HashMap of StockItems keyed on a String class SKU#, your HashMap initialization might look like this:

private HashMap<String, StockItem> stock = new HashMap<String, StockItem>();

Key value pairs can be added to a HashMap object using the .put() method, for example:

stock.put("2302K53", new SprocketForMetricChain("2302K53", 3111, 30, 8));

Refer to the Java API documentation for further details on working with both ArrayLists and HashMaps.

Your tasks for Hardware Orders, Part 2:

1.Implement the required classes and methods for Part 2. 


2.Implement any other classes that seem appropriate to the problem domain, and update 
any classes from Part 1 as appropriate. Be prepared to discuss your choices and any 
changes you've made. 


3.Create a manual stock of items for your StockService class using actual data from the 
McMaster-Carr web pages above. 


4.Write unit tests for successful and unsuccessful cases and to test for various 
combinations of systems of measurement, etc. 


5.Write appropriate JavaDoc comments for all classes and methods. 


6.Provide your final UML diagram that includes the methods you defined. 


7.Commit, push, and tag a release representing your work on Hardware Orders, Part 2. 


Theater Reservations, Part 1

For this exercise, you'll implement a reservation system for movie theaters that automatically places users in the most desirable seats available for their party.

The user will interact with the system on the command line. The system will prompt the user with the phrase "What would you like to do" and the user can enter "reserve <number>" to

reserve that number of seats, "show" to display the current available seating in the theater, and "done" to shut down the system.

When a user requests to reserve some number of seats, the system automatically finds the best seats in the theater that share a single row. The "best seats" are assumed to be in the rows nearest the middle of the theater (not too close, not too far). If no rows contain a sufficient number of unreserved seats, the system will apologize and decline to make a reservation.

A few points to consider:

Best seats are filled first-come/first-serve, provided there are enough empty seats in a row to accommodate a party 


Best seats are determined by proximity to the center row. A seat N rows ahead of the center row is regarded as approximately equivalent to a seat N rows behind the center row. The front row and the back row (in either order) should be the last two rows assigned. 


Left/right/center priority need not be considered. Rows can fill up from left to right or vice versa, or from the center, as long as parties are not separated. 


No party is separated by the system across multiple rows. The number of seats in a single reservation must all be together on the same row, or the reservation will not be made. 
A session with the reservations system might look as follows: 
What would you like to do? reserve 7
What's your name?
Tony 


I've reserved 7 seats for you at the Roxy in row 7, Tony. What would you like to do?
show

1__________ 2__________ 3__________ 4__________ 5__________ 6__________ 7__________ 8XXXXXXX___ 9__________

10 _ _ _ _ 11 _ _ _ _ 12 _ _ _ _ 13 _ _ _ _ 14 _ _ _ _ 15 _ _ _ _

What would
reserve 11
Sorry, we don't have that many seats together for you.

What would you like to do? reserve 9
What's your name?

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

you like to do?

Sara
I've reserved 9 seats for you at the Roxy in row 6, Sara.

What would you like to do? show

1__________ 2__________ 3__________ 4__________ 5__________ 6__________ 7XXXXXXXXX_ 8XXXXXXX___ 9__________

10 _ _ _ _ _ _ _ _ _ _ 11 _ _ _ _ _ _ _ _ _ _ 12 _ _ _ _ _ _ _ _ _ _ 13 _ _ _ _ _ _ _ _ _ _ 14 _ _ _ _ _ _ _ _ _ _ 15 _ _ _ _ _ _ _ _ _ _

What would you like to do? reserve 5
What's your name?
Jo

I've reserved 5 seats for you at the Roxy in row 8, Jo.

What would you like to do? show

1__________ 2__________ 3__________ 4__________ 5__________ 6__________ 7XXXXXXXXX_ 8XXXXXXX___ 9XXXXX_____

10 _ _ _ _ _ _ _ _ _ _ 11 _ _ _ _ _ _ _ _ _ _ 12 _ _ _ _ _ _ _ _ _ _ 13 _ _ _ _ _ _ _ _ _ _ 14 _ _ _ _ _ _ _ _ _ _ 15 _ _ _ _ _ _ _ _ _ _

What would you like to do? reserve 3
What's your name?
Jean Claude

I've reserved 3 seats for you at the Roxy in row 7, Jean Claude. What would you like to do?
show

1__________ 2__________ 3__________ 4__________ 5__________

6__________ 7XXXXXXXXX_ 8XXXXXXXXXX 9XXXXX_____

10 _

11 _

12 _

13 _

14 _

15 _

What

done

Have

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

would you like to do? a nice day!

Your system should define the following classes:

•Seat. A seat object must have:
o A seat name, which is a string value representing a capital letter from A to Z.
o A "reserved for" value which represents the name of the person for whom it has

been reserved, or is null if the seat has not been reserved
•Row. A row is a list of seats. The Row class should extend ArrayList of Seat objects.

o A Row object should have a row number (1 is closest to the screen, etc.)

o The Row constructor should take a number of seats as an argument. •Theater. A theater has:

o A name.
o A collection of rows (you may implement this however you choose).

ReservationsService. This class will implement the actual service as a public method that takes a theater as its argument. 


ReservationSystem. This class will only contain a main method. It will create a new instance of Theater and call the service implemented in ReservationsService with the theater object as its argument. 
Your tasks: 


1.Write a code to implement the classes listed above. Decide where the appropriate functionality should reside. For example, consider how the "show" command should interact with the various class's toString() methods. 


2.Design the algorithm that finds the optimal row based on its proximity to the center. Use the simplest approach you can to determine the optimal row. 


3.Write tests for all classes. 


4.Provide your final UML diagram that includes all relevant methods. 


5.Commit, push, and tag a release representing your work on Theater Reservations, Part 1. 


Theater Reservations, Part 2

The above system needs an overhaul to take into consideration the requirements of accessible design. We now need to make sure that at least one row in every movie theater is wheelchair accessible, and we need to factor this into the reservations process.

•Row:
o A Row must now have a field indicating whether or not it is wheelchair

accessible •Theater:

o A theater should take a non-empty list (or array) of integers indicating which of its rows are accessible

Functionality:

The system will function as before, but now, when the user requests to reserve seats it will respond with the prompt "Do you need wheelchair accessible seats?" If the user answers "yes," the system will search for the best seats from among the rows that are wheelchair accessible. If the user answers "no," the system will search for the best seats from among the rows that are not wheelchair accessible.

If and only if all other rows are occupied, then the system will reserve seats in accessible rows to users who do not need accessible seats.

The "show" command should indicate which rows are wheelchair-accessible. Whereas seats in rows that are not accessible are represented by "_" seats in rows that are wheelchair-accessible should be represented by "=".

Extend your work from Theater Reservations, Part 1 in the following ways.

Your tasks:

1.Ensure that the Theater constructor takes a list of values indicating which of its rows are accessible. A theater without accessible rows should not be allowed. 


2.Ensure that Row contains a field stipulating whether or not it is wheelchair accessible 


3.Modify the reservation interface such that the necessary prompts are given to the user 
and the necessary information is collected from the user. 


4.Modify the reservation process such that users are assigned seats appropriately based on 
their need for wheelchair-accessibility. 


5.Modify the appropriate toString() code such that accessible rows are distinguished 
from non-accessible rows when the "show" command is given. 


6.Write tests to cover new functionality. 


7.Provide your final UML diagram that includes all relevant methods. 


8.Commit, push, and tag a release representing your work on Theater Reservations, Part 2. 



站长地图