Write a Java program that performs the appropriate action. The program must meet the following requirements:
- It should be packed into an executable jar archive.
- The expression must be evaluated in accordance with the rules for evaluating mathematical expressions (the order of actions must be followed, etc.).
- The program must use math functions from the Java standard library.
- The result of evaluating the expression must be output to the standard output stream in the specified format.
The execution of the program must be demonstrated on the helios
server.
- Create a one-dimensional array d of type
long
. Fill it in with even numbers from 2 to 20 inclusive in descending order. - Create a one-dimensional array x of type
double
. Fill it with 16 random numbers ranging from -11.0 to 5.0. - Create a 10x16 two-dimensional array d. Calculate its elements using the following formula (where x = x [j]):
- Print the resulting array in two decimal places.
- The text of the task.
- The source code of the program.
- The result of the program.
- Conclusions on the work.
- Java language. Features of the language.
- Development tools. JDK and JRE.
- Primitive data types in Java.
- Working with variables. Declaration. Initialization. Assignment.
- Branching and looping instructions.
- Operators and Expressions in Java. Features of the calculation, priorities of operations.
- Mathematical functions in the Java standard library. Class
java.lang.Math
. - Formatted numeric output.
Based on the base Pokemon
class, write your own classes for the specified types of Pokemon. Each type of Pokémon must have one or two types and standard basic characteristics:
- health points (HP)
- attack
- defense
- special attack
- special defense
- speed
Pokémon classes must be inherited according to the Pokémon evolutionary chain. Based on the base classes PhysicalMove
, SpecialMove
 and StatusMove
, implement your own classes for the specified types of attacks.
The attack must be of standard type, power and accuracy. Standard attack effects must be implemented. Assign attacks to each type of Pokémon according to the option. The Pokémon level is chosen as the minimum required for all implemented attacks.
Using the Battle
simulation class, create 2 Pokémon teams (each Pokémon must have a name) and start the battle.
The base classes and the battle simulator are in the jar-archive (updated on 10/9/2018, a bug with the addition of attacks and encoding was fixed). Documentation in Javadoc format is here.
Information about Pokémon, evolution chains and attacks can be found at http://poke-universe.ru, http://pokemondb.net, http://veekun.com/dex/pokemon
Purpose of work: using a simple example to understand the basic concepts of OOP and learn how to use them in programs.
- Check out the documentation with a special focus on the Pokemon and Move classes. As you continue to complete the lab, read the documentation a few more times.
- Download the Pokemon.jar file. It will need to be used both for compilation and for running the program. You don't need to unpack it! You need to learn how to connect external jar files to your program.
- Write a minimal program and see how it works.
Battle b = new Battle();
Pokemon p1 = new Pokemon("Stranger", 1);
Pokemon p2 = new Pokemon("Predator", 1);
b.addAlly(p1);
b.addFoe(p2);
b.go();
- Create one of the
Pokemon
classes for your variant. The class must inherit from the base Pokemon class. In the constructor, you will need to set the types of the Pokemon and its basic characteristics. After that, try adding Pokemon to the battle. - Create one of the attack classes for your variant (it is best to start with a physical or special attack). The class must inherit from the
PhysicalMove
orSpecialMove
class. In the constructor, you will need to set the type of attack, its strength and accuracy. After that, add an attack to the Pokémon and test its action in battle. Don't forget to override the describe method to display the desired message. - If the attack action differs from the standard one, for example, the Pokemon does not miss, or the attacking Pokemon also receives damage, then the corresponding methods must be additionally redefined in the attack class (see the documentation). When implementing attacks that change the status of a Pokemon (inherited from StatusMove), you will most likely have to deal with the Effect class. It allows you to change the state of the Pokemon or the modifier of its basic characteristics for one or several turns.
- Finish all the necessary attacks and all the Pokémon, distribute the Pokémon into teams, start the battle.
- The text of the task.
- Class diagram of the implemented object model.
- The source code of the program.
- The result of the program.
- Conclusions on the work.
- Object Oriented Programming. Basic concepts: objects, inheritance, polymorphism, encapsulation.
- Class concept. Classes and objects in Java.
- Class members. Access modifiers.
- Creation and initialization of objects. Calling methods.
- Variable scopes.
Final
andstatic
modifiers.- Packages,
import
statement.
- The modified model must comply with the SOLID principles.
- The program must contain at least two interfaces and one abstract class (the nomenclature must be agreed with the teacher).
- The developed classes must override the
equals()
,toString()
andhashCode()
methods. - The program must contain at least one enumerated type (enum).
- Refine the application object model.
- Redraw the class diagram according to the changes made to the model.
- Agree with the teacher about the changes made to the model.
- Modify the program in accordance with the changes made to the model.
Text has been lost. It was part of “Neznayka on the Moon” fairy tale. The arrival of the expedition to the moon was described, a dialogue between a Neznayka with a local journalist about the differences between life on Earth and the Moon. Further, according to the plot, Neznayka handed over samples of terrestrial plants to lunar scientists who began to study them.
- The text of the task.
- Class diagram of the implemented object model.
- The source code of the program.
- The result of the program.
- Conclusions on the work.
- The principles of object-oriented programming SOLID and STUPID.
Object
class. The default implementation of its methods.- Features of the implementation of inheritance in Java. Simple and multiple inheritance.
- Abstract class concept. The
abstract
modifier. - Interface concept. Implementation of interfaces in Java, default methods. Differences from abstract classes.
- Enumerated data type (enum) in Java. Features of implementation and use.
- Methods and fields with
static
andfinal
modifiers. - Overloading and overriding methods. Return data type covariants.
- Elements of functional programming in Java syntax. Functional interfaces, lambda expressions. Method references.
- The program must implement 2 of its own exception classes (checked and unchecked), as well as the exception handling of these classes.
- The use of local, anonymous and nested classes (static and non-static) must be added to the program.
- Refine the application object model.
- Redraw the class diagram according to the changes made to the model.
- Agree with the teacher about the changes made to the model.
- Modify the program in accordance with the changes made to the model.
Text for this laboratory work has been lost too. In was a large text. The plot of the previous laboratory work was described, as well as the further development of the business on the Moon according to the model of market relations. Various shops and hospitals were opened. A joint-stock company was opened, headed by travelers well-known according to the previous assignment. They started selling shares. The process of creating this organization and its interior were also described. Further in the plot, this company was robbed and the subsequent arrival of the police.
- The text of the task.
- Object model class diagram.
- The source code of the program.
- The result of the program.
- Conclusions on the work.
- Exception handling, three types of exceptions.
- Nested, local and anonymous classes.
- The reflection mechanism in Java. Class
Class
.
Implement a console application that implements interactive management of a collection of objects. The collection must store objects of the Person
class, which is described below.
- A class whose collection of instances is managed by a program must implement default sorting.
- All requirements for class fields (specified in the form of comments) must be met.
- For storage, you must use a collection of type
java.util.HashSet
- When the application starts, the collection should be automatically filled with values from the file.
- The filename must be passed to the program using: command line argument.
- The data must be stored in a file in
xml
format - Reading data from a file must be implemented using the
java.io.BufferedReader
class - Writing data to a file must be implemented using the
java.io.FileWriter
class - All classes in the program must be documented in javadoc format.
- The program must work correctly with incorrect data (user input errors, lack of access rights to the file, etc.).
help
: display help for available commandsinfo
: print information about the collection (type, date of initialization, number of elements, etc.) to standard outputshow
: display all elements of the collection in string representation to standard outputadd {element}
: add a new element to the collectionupdate id {element}
: update the value of the collection element whose id is equal to the givenremove_by_id id
: remove an item from the collection by its idclear
: clear the collectionsave
: save the collection to a fileexecute_script file_name
: read and execute the script from the specified file. The script contains commands in the same form in which the user enters them interactively.exit
: exit the program (without saving to file)add_if_min {element}
: add a new element to the collection if its value is less than the smallest element in this collectionremove_greater {element}
: remove all elements greater than the specified one from the collectionremove_lower {element}
: remove all elements from the collection that are less than the given onesum_of_height
: Print the sum of the values of the height field for all elements of the collectiongroup_counting_by_nationality
: group the elements of the collection by the value of the nationality field, display the number of elements in each groupcount_greater_than_nationality nationality
: Print the number of items whose nationality is greater than the specified value
- All command arguments that are standard data types (primitive types, wrapper classes, String, date storage classes) must be entered on the same line as the command name.
- All composite data types (class objects stored in a collection) must be entered one field per line.
- When entering composite data types, the user should be shown an input prompt containing the field name (for example, "Enter date of birth:")
- If the field is an enum, then the name of one of its constants is entered (in this case, the list of constants must be previously displayed).
- In case of incorrect user input (a string is entered that is not the name of a constant in the enum; a string is entered instead of a number; the entered number is not included in the specified limits, etc.) an error message should be displayed and the field should be prompted to re-enter the field.
- Use an empty string to enter null values.
- Fields with the comment "The value of this field should be generated automatically" should not be entered manually by the user when adding.
public class Person {
private int id; //The field value must be greater than 0, The value of this field must be unique, The value of this field must be generated automatically
private String name; //Field cannot be null, String cannot be empty
private Coordinates coordinates; //The field cannot be null
private java.time.LocalDateTime creationDate; //The field cannot be null, the value of this field must be generated automatically
private long height; //The field value must be greater than 0
private Color eyeColor; //The field can be null
private Color hairColor; //The field can be null
private Country nationality; //The field can be null
private Location location; //The field can be null
}
public class Coordinates {
private long x; //Maximum Field Value: 690
private float y;
}
public class Location {
private long x;
private Float y; //The field cannot be null
private String name; //The field cannot be null
}
public enum Color {
GREEN,
RED,
BLUE;
}
public enum Color {
BLUE,
YELLOW,
ORANGE;
}
public enum Country {
GERMANY,
CHINA,
NORTH_KOREA;
}
Divide the program from laboratory work #5 into client and server modules. The server module must execute commands for managing the collection. The client module must interactively read commands, send them for execution to the server, and output the results of execution.
- Collection object processing operations must be implemented using the Stream API using lambda expressions.
- Objects between client and server must be serialized.
- Objects in the collection passed to the client should be sorted by default
- The client must correctly handle temporary server unavailability.
- The exchange of data between the client and the server must be carried out using the UDP protocol
- To exchange data on the server, you must use a network channel
- To exchange data on the client, you must use datagrams
- Network links must be used in non-blocking mode.
- Working with a file that stores a collection.
- Managing a collection of objects.
- Assigning automatically generated fields to objects in a collection.
- Waiting for connections and requests from the client.
- Processing received requests (commands).
- Saving the collection to a file when the application exits.
- Saving a collection to a file when executing a special command available only to the server (the client cannot send such a command).
The server application should consist of the following modules (implemented as one or more classes):
- The module for accepting connections.
- Request reader. 1.The module for processing received commands.
- Module for sending responses to the client.
The server must be running in single threaded mode.
- Reading commands from the console.
- Validation of input data.
- Serialization of the entered command and its arguments.
- Sending the received command and its arguments to the server.
- Processing a response from the server (outputting the result of command execution to the console).
- The
save
command must be removed from the client application. - The
exit
command terminates the client application.
Important! Commands and their arguments must be class objects. The exchange of "simple" strings is inadmissible. So, for the add
command or its equivalent, you need to form an object containing the command type and the object that should be stored in your collection.
Additional task:
Implement logging of various stages of server operation (starting work, receiving a new connection, receiving a new request, sending a response, etc.) using Logback
- The text of the task.
- Class diagram of the developed program (both client and server applications).
- The source code of the program.
- Conclusions on the work.
- Networking - client-server architecture, basic protocols, their similarities and differences.
- TCP protocol.
Socket
andServerSocket
classes. - UDP protocol. The
DatagramSocket
andDatagramPacket
classes. - Differences between blocking and non-blocking Input/Output, their advantages and disadvantages. Working with network channels.
SocketChannel
andDatagramChannel
classes.- Data transmission over the network. Serialization of objects.
Serializable
interface. Object graph, serialization and deserialization of fields and methods.- Java Stream API. Creation of conveyors. Intermediate and terminal operations.
- Design patterns: Decorator, Iterator, Factory method, Command, Flyweight, Interpreter, Singleton, Strategy, Adapter, Facade, Proxy.
Modify the program from laboratory work #6 as follows:
- Organize collection storage in a relational DBMS (PostgresQL). Remove storage of the collection in a file.
- Use the database facility (sequence) to generate the id field.
- Update the state of the collection in memory only when the object is successfully added to the database
- All data retrieval commands must work with the collection in memory, not in the database
- Organize the possibility of registration and authorization of users. The user has the option to specify a password.
- Store passwords hashed using the
SHA-512
algorithm - Prevent unauthorized users from executing commands.
- When storing objects, store information about the user who created this object.
- Users should be able to view all objects in the collection, but only those that belong to them can be modified.
- To identify the user, send a username and password with each request.
It is necessary to implement multithreaded request processing.
- For multi-threaded reading of requests, use the
Cached thread pool
- For multithreaded processing of the received request, use the
Cached thread pool
- Use
Cached thread pool
for multithreaded response - To synchronize access to the collection use synchronization read and write using
java.util.concurrent.locks.ReadWriteLock
- Use PostgreSQL as a database.
- To connect to the database on the cathedral server, use the host
pg
, the database name isstuds
, the username / password are the same as for connecting to the server.
- The text of the task.
- Class diagram of the developed program.
- The source code of the program.
- Conclusions on the work.
- Multithreading.
Thread
class, interfaceRunnable
. Thesynchronized
modifier. - The
wait()
,notify()
methods of theObject
class, theLock
andCondition
interfaces. - Synchronizing classes from the
java.util.concurrent
package. - The
volatile
modifier. Atomic data types and operations. - Collections from the
java.util.concurrent
package. Executor
,ExecutorService
,Callable
,Future
interfaces- Thread pools
- JDBC. The order of interaction with the database.
DriverManager
class.Connection
interface - Interfaces
Statement
,PreparedStatement
,ResultSet
,RowSet
- Design patterns.