[POO] aula09 and some other simple changes | [LSD] miniproj added #57

[POO] created email validation method
[POO] guide for aula09 added
[POO] equals and hashcode added to aula06.ex1.Person.java
[POO] aula09 added
[POO] README update

[LSD] 2022-2023 mini project added

[LABI] added tcp socket chat server
This commit is contained in:
Tiago Garcia 2023-05-02 11:23:19 +01:00 committed by GitHub
commit af3519ac00
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
24 changed files with 1269 additions and 0 deletions

View File

@ -0,0 +1,56 @@
# encoding=utf-8
import socket
import select
def main ():
tcp_s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
tcp_s.bind (("0.0.0.0", 8080))
tcp_s.listen (10)
connections = []
connections.append (tcp_s)
print ("Chat server started")
while 1:
# Get the list sockets which are ready to be read through select
read_sockets = select.select (connections, [], [])[0]
for sock in read_sockets:
#New connection
if sock == tcp_s:
# Handle the case in which there is a new connection received through server_socket
client_s, addr = tcp_s.accept ()
connections.append (client_s)
print ("Client connected: %s" % str (addr))
else:
#Some incoming message from a client, process it
try:
# Incoming message
data = sock.recv (4096)
if len (data) != 0:
print ("From client: %s" % str (sock.getpeername()))
print ("Got Data: " + data.decode ('utf-8'))
else:
print ("Client disconnected: %s" % str (sock.getpeername()))
sock.close()
connections.remove (sock)
break
#Do not send the message to master socket
#Create the message identifying the client
message = ('<' + " Fom client: " + str(sock.getpeername()) + '> \n').encode('utf-8') + data.upper()
for client in connections:
if client != tcp_s: # Eventually do not send the message to the source client !!!
client.send (message)
except:
print ("Client socket error: %s" % str (addr))
sock.close()
connections.remove (sock)
continue
tcp_s.close()
main ()

View File

@ -0,0 +1,37 @@
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity Bin2Bcd is
port
(
hexIn : in std_logic_vector(3 downto 0);
decOut0 : out std_logic_vector(3 downto 0);
decOut1 : out std_logic_vector(3 downto 0)
);
end Bin2Bcd;
architecture Behavioral of Bin2Bcd is
begin
process (hexIn) is
begin
if hexIn < "1010" then
decOut0 <= hexIn;
decOut1 <= "0000";
else
if hexIn = "1010" then
decOut0 <= "0000";
elsif hexIn = "1011" then
decOut0 <= "0001";
elsif hexIn = "1100" then
decOut0 <= "0010";
elsif hexIn = "1101" then
decOut0 <= "0011";
elsif hexIn = "1110" then
decOut0 <= "0100";
else
decOut0 <= "0101";
end if;
decOut1 <= "0001";
end if;
end process;
end Behavioral;

View File

@ -0,0 +1,24 @@
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity Bin7SegDecoder is
port
(
binInput : in std_logic_vector(3 downto 0);
decOut_n : out std_logic_vector(6 downto 0)
);
end Bin7SegDecoder;
architecture Behavioral of Bin7SegDecoder is
begin
decOut_n <= "1111001" when (binInput = "0001") else --1
"0100100" when (binInput = "0010") else --2
"0110000" when (binInput = "0011") else --3
"0011001" when (binInput = "0100") else --4
"0010010" when (binInput = "0101") else --5
"0000010" when (binInput = "0110") else --6
"1111000" when (binInput = "0111") else --7
"0000000" when (binInput = "1000") else --8
"0010000" when (binInput = "1001") else --9
"1000000"; --0
end Behavioral;

View File

@ -0,0 +1,31 @@
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
entity Counter is
port
(
clk : in std_logic;
reset : in std_logic;
start : in std_logic;
count : out std_logic_vector(3 downto 0)
);
end Counter;
architecture Behavioral of Counter is
signal s_count : unsigned(3 downto 0) := to_unsigned(0, 4);
begin
process(clk, reset)
begin
if (reset = '1') then
s_count <= to_unsigned(0, 4);
elsif (start = '1' and rising_edge(clk)) then
if (std_logic_vector(s_count) = "1111") then
s_count <= to_unsigned(0, 4);
else
s_count <= s_count + 1;
end if;
end if;
end process;
count <= std_logic_vector(s_count);
end Behavioral;

View File

@ -0,0 +1,79 @@
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
entity CounterDemo is
port
(
CLOCK_50 : in std_logic;
KEY : in std_logic_vector(1 downto 0);
HEX0 : out std_logic_vector(6 downto 0);
HEX1 : out std_logic_vector(6 downto 0)
);
end CounterDemo;
architecture Shell of CounterDemo is
signal s_pulse, s_reset, s_toggle : std_logic;
signal s_count : std_logic_vector(3 downto 0);
signal s_startStop : std_logic := '1';
signal s_display0, s_display1 : std_logic_vector(3 downto 0);
begin
s_reset <= not KEY(1);
pulse_gen : entity work.pulse_gen(Behavioral)
generic map (MAX => 20_000_000)
port map
(
clk => CLOCK_50,
pulse => s_pulse
);
key_debounce : entity work.Debouncer(Behavioral)
port map
(
refClk => CLOCK_50,
dirtyIn => KEY(0),
pulsedOut => s_toggle
);
start_stop : entity work.ToggleSwitch(Behavioral)
port map
(
toggle => s_toggle,
reset => s_reset,
startStop => s_startStop
);
counter : entity work.Counter(Behavioral)
port map
(
clk => s_pulse,
reset => s_reset,
start => s_startStop,
count => s_count
);
bin2bcd : entity work.Bin2Bcd(Behavioral)
port map
(
hexIn => s_count,
decOut0 => s_display0,
decOut1 => s_display1
);
display0 : entity work.Bin7SegDecoder(Behavioral)
port map
(
binInput => s_display0,
decOut_n => HEX0
);
display1 : entity work.Bin7SegDecoder(Behavioral)
port map
(
binInput => s_display1,
decOut_n => HEX1
);
end Shell;

View File

@ -0,0 +1,311 @@
/*<simulation_settings>
<ftestbench_cmd>quartus_eda --gen_testbench --tool=modelsim_oem --format=vhdl --write_settings_files=off CounterDemo -c CounterDemo --vector_source="/home/tiagorg/repos/uaveiro-leci/1ano/2semestre/lsd/projects/MiniProj_Demo_22-23/CounterSimulation.vwf" --testbench_file="/home/tiagorg/repos/uaveiro-leci/1ano/2semestre/lsd/projects/MiniProj_Demo_22-23/simulation/qsim/CounterSimulation.vwf.vht"</ftestbench_cmd>
<ttestbench_cmd>quartus_eda --gen_testbench --tool=modelsim_oem --format=vhdl --write_settings_files=off CounterDemo -c CounterDemo --vector_source="/home/tiagorg/repos/uaveiro-leci/1ano/2semestre/lsd/projects/MiniProj_Demo_22-23/CounterSimulation.vwf" --testbench_file="/home/tiagorg/repos/uaveiro-leci/1ano/2semestre/lsd/projects/MiniProj_Demo_22-23/simulation/qsim/CounterSimulation.vwf.vht"</ttestbench_cmd>
<fnetlist_cmd>quartus_eda --write_settings_files=off --simulation --functional=on --flatten_buses=off --tool=modelsim_oem --format=vhdl --output_directory="/home/tiagorg/repos/uaveiro-leci/1ano/2semestre/lsd/projects/MiniProj_Demo_22-23/simulation/qsim/" CounterDemo -c CounterDemo</fnetlist_cmd>
<tnetlist_cmd>quartus_eda --write_settings_files=off --simulation --functional=off --flatten_buses=off --timescale=1ps --tool=modelsim_oem --format=vhdl --output_directory="/home/tiagorg/repos/uaveiro-leci/1ano/2semestre/lsd/projects/MiniProj_Demo_22-23/simulation/qsim/" CounterDemo -c CounterDemo</tnetlist_cmd>
<modelsim_script>onerror {exit -code 1}
vlib work
vcom -work work CounterDemo.vho
vcom -work work CounterSimulation.vwf.vht
vsim -c -t 1ps -L cycloneive -L altera -L altera_mf -L 220model -L sgate -L altera_lnsim work.CounterDemo_vhd_vec_tst
vcd file -direction CounterDemo.msim.vcd
vcd add -internal CounterDemo_vhd_vec_tst/*
vcd add -internal CounterDemo_vhd_vec_tst/i1/*
proc simTimestamp {} {
echo "Simulation time: $::now ps"
if { [string equal running [runStatus]] } {
after 2500 simTimestamp
}
}
after 2500 simTimestamp
run -all
quit -f
</modelsim_script>
<modelsim_script_timing>onerror {exit -code 1}
vlib work
vcom -work work CounterDemo.vho
vcom -work work CounterSimulation.vwf.vht
vsim -novopt -c -t 1ps -sdfmax CounterDemo_vhd_vec_tst/i1=CounterDemo_vhd.sdo -L cycloneive -L altera -L altera_mf -L 220model -L sgate -L altera_lnsim work.CounterDemo_vhd_vec_tst
vcd file -direction CounterDemo.msim.vcd
vcd add -internal CounterDemo_vhd_vec_tst/*
vcd add -internal CounterDemo_vhd_vec_tst/i1/*
proc simTimestamp {} {
echo "Simulation time: $::now ps"
if { [string equal running [runStatus]] } {
after 2500 simTimestamp
}
}
after 2500 simTimestamp
run -all
quit -f
</modelsim_script_timing>
<hdl_lang>vhdl</hdl_lang>
</simulation_settings>*/
/*
WARNING: Do NOT edit the input and output ports in this file in a text
editor if you plan to continue editing the block that represents it in
the Block Editor! File corruption is VERY likely to occur.
*/
/*
Copyright (C) 2020 Intel Corporation. All rights reserved.
Your use of Intel Corporation's design tools, logic functions
and other software and tools, and any partner logic
functions, and any output files from any of the foregoing
(including device programming or simulation files), and any
associated documentation or information are expressly subject
to the terms and conditions of the Intel Program License
Subscription Agreement, the Intel Quartus Prime License Agreement,
the Intel FPGA IP License Agreement, or other applicable license
agreement, including, without limitation, that your use is for
the sole purpose of programming logic devices manufactured by
Intel and sold by Intel or its authorized distributors. Please
refer to the applicable agreement for further details, at
https://fpgasoftware.intel.com/eula.
*/
HEADER
{
VERSION = 1;
TIME_UNIT = ns;
DATA_OFFSET = 0.0;
DATA_DURATION = 1000.0;
SIMULATION_TIME = 0.0;
GRID_PHASE = 0.0;
GRID_PERIOD = 10.0;
GRID_DUTY_CYCLE = 50;
}
SIGNAL("clk")
{
VALUE_TYPE = NINE_LEVEL_BIT;
SIGNAL_TYPE = SINGLE_BIT;
WIDTH = 1;
LSB_INDEX = -1;
DIRECTION = INPUT;
PARENT = "";
}
SIGNAL("count")
{
VALUE_TYPE = NINE_LEVEL_BIT;
SIGNAL_TYPE = BUS;
WIDTH = 4;
LSB_INDEX = 0;
DIRECTION = OUTPUT;
PARENT = "";
}
SIGNAL("count[3]")
{
VALUE_TYPE = NINE_LEVEL_BIT;
SIGNAL_TYPE = SINGLE_BIT;
WIDTH = 1;
LSB_INDEX = -1;
DIRECTION = OUTPUT;
PARENT = "count";
}
SIGNAL("count[2]")
{
VALUE_TYPE = NINE_LEVEL_BIT;
SIGNAL_TYPE = SINGLE_BIT;
WIDTH = 1;
LSB_INDEX = -1;
DIRECTION = OUTPUT;
PARENT = "count";
}
SIGNAL("count[1]")
{
VALUE_TYPE = NINE_LEVEL_BIT;
SIGNAL_TYPE = SINGLE_BIT;
WIDTH = 1;
LSB_INDEX = -1;
DIRECTION = OUTPUT;
PARENT = "count";
}
SIGNAL("count[0]")
{
VALUE_TYPE = NINE_LEVEL_BIT;
SIGNAL_TYPE = SINGLE_BIT;
WIDTH = 1;
LSB_INDEX = -1;
DIRECTION = OUTPUT;
PARENT = "count";
}
SIGNAL("reset")
{
VALUE_TYPE = NINE_LEVEL_BIT;
SIGNAL_TYPE = SINGLE_BIT;
WIDTH = 1;
LSB_INDEX = -1;
DIRECTION = INPUT;
PARENT = "";
}
SIGNAL("start")
{
VALUE_TYPE = NINE_LEVEL_BIT;
SIGNAL_TYPE = SINGLE_BIT;
WIDTH = 1;
LSB_INDEX = -1;
DIRECTION = INPUT;
PARENT = "";
}
TRANSITION_LIST("clk")
{
NODE
{
REPEAT = 1;
NODE
{
REPEAT = 50;
LEVEL 0 FOR 10.0;
LEVEL 1 FOR 10.0;
}
}
}
TRANSITION_LIST("count[3]")
{
NODE
{
REPEAT = 1;
LEVEL X FOR 1000.0;
}
}
TRANSITION_LIST("count[2]")
{
NODE
{
REPEAT = 1;
LEVEL X FOR 1000.0;
}
}
TRANSITION_LIST("count[1]")
{
NODE
{
REPEAT = 1;
LEVEL X FOR 1000.0;
}
}
TRANSITION_LIST("count[0]")
{
NODE
{
REPEAT = 1;
LEVEL X FOR 1000.0;
}
}
TRANSITION_LIST("reset")
{
NODE
{
REPEAT = 1;
LEVEL 0 FOR 40.0;
LEVEL 1 FOR 50.0;
LEVEL 0 FOR 910.0;
}
}
TRANSITION_LIST("start")
{
NODE
{
REPEAT = 1;
LEVEL 1 FOR 1000.0;
}
}
DISPLAY_LINE
{
CHANNEL = "clk";
EXPAND_STATUS = COLLAPSED;
RADIX = Binary;
TREE_INDEX = 0;
TREE_LEVEL = 0;
}
DISPLAY_LINE
{
CHANNEL = "reset";
EXPAND_STATUS = COLLAPSED;
RADIX = Binary;
TREE_INDEX = 1;
TREE_LEVEL = 0;
}
DISPLAY_LINE
{
CHANNEL = "start";
EXPAND_STATUS = COLLAPSED;
RADIX = Binary;
TREE_INDEX = 2;
TREE_LEVEL = 0;
}
DISPLAY_LINE
{
CHANNEL = "count";
EXPAND_STATUS = COLLAPSED;
RADIX = Binary;
TREE_INDEX = 3;
TREE_LEVEL = 0;
CHILDREN = 4, 5, 6, 7;
}
DISPLAY_LINE
{
CHANNEL = "count[3]";
EXPAND_STATUS = COLLAPSED;
RADIX = Binary;
TREE_INDEX = 4;
TREE_LEVEL = 1;
PARENT = 3;
}
DISPLAY_LINE
{
CHANNEL = "count[2]";
EXPAND_STATUS = COLLAPSED;
RADIX = Binary;
TREE_INDEX = 5;
TREE_LEVEL = 1;
PARENT = 3;
}
DISPLAY_LINE
{
CHANNEL = "count[1]";
EXPAND_STATUS = COLLAPSED;
RADIX = Binary;
TREE_INDEX = 6;
TREE_LEVEL = 1;
PARENT = 3;
}
DISPLAY_LINE
{
CHANNEL = "count[0]";
EXPAND_STATUS = COLLAPSED;
RADIX = Binary;
TREE_INDEX = 7;
TREE_LEVEL = 1;
PARENT = 3;
}
TIME_BAR
{
TIME = 0;
MASTER = TRUE;
}
;

View File

@ -0,0 +1,61 @@
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
entity Debouncer is
generic( kHzClkFreq : positive := 50_000;
mSecMinInWidth : positive := 100;
inPolarity : std_logic := '0';
outPolarity : std_logic := '1');
port( refClk : in std_logic;
dirtyIn : in std_logic;
pulsedOut : out std_logic);
end Debouncer;
architecture Behavioral of Debouncer is
constant MIN_IN_WIDTH_CYCLES : positive := mSecMinInWidth * kHzClkFreq;
subtype TCounter is natural range 0 to MIN_IN_WIDTH_CYCLES;
signal s_debounceCnt : TCounter := 0;
signal s_dirtyIn, s_previousIn, s_pulsedOut : std_logic;
begin
in_sync_proc : process(refClk)
begin
if (rising_edge(refClk)) then
if (inPolarity = '1') then
s_dirtyIn <= dirtyIn;
else
s_dirtyIn <= not dirtyIn;
end if;
s_previousIn <= s_dirtyIn;
end if;
end process;
count_proc : process(refClk)
begin
if (rising_edge(refClk)) then
if ((s_dirtyIn = '0') or
(s_debounceCnt > MIN_IN_WIDTH_CYCLES)) then
s_debounceCnt <= 0;
s_pulsedOut <= '0';
elsif (s_dirtyIn = '1') then
if (s_previousIn = '0') then
s_debounceCnt <= MIN_IN_WIDTH_CYCLES;
s_pulsedOut <= '0';
else
if (s_debounceCnt >= 1) then
s_debounceCnt <= s_debounceCnt - 1;
end if;
if (s_debounceCnt = 1) then
s_pulsedOut <= '1';
else
s_pulsedOut <= '0';
end if;
end if;
end if;
end if;
end process;
pulsedOut <= s_pulsedOut when (outPolarity = '1') else not s_pulsedOut;
end Behavioral;

View File

@ -0,0 +1,31 @@
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity ToggleSwitch is
port
(
toggle : in std_logic;
reset : in std_logic;
startStop : out std_logic := '1'
);
end ToggleSwitch;
architecture Behavioral of ToggleSwitch is
signal current_state : std_logic := '1';
begin
process(toggle, reset)
begin
if (reset = '1') then
current_state <= '1';
else
if (toggle = '1') then
if (current_state = '1') then
current_state <= '0';
else
current_state <= '1';
end if;
end if;
end if;
end process;
startStop <= current_state;
end Behavioral;

View File

@ -0,0 +1,28 @@
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity pulse_gen is
generic (MAX : positive := 50_000_000);
port
(
clk : in STD_LOGIC;
pulse : out STD_LOGIC
);
end pulse_gen;
architecture Behavioral of pulse_gen is
signal s_cnt : natural range 0 to MAX-1;
begin
process(clk)
begin
if (rising_edge(clk)) then
pulse <= '0';
s_cnt <= s_cnt + 1;
if (s_cnt = MAX-1) then
s_cnt <= 0;
pulse <= '1';
end if;
end if;
end process;
end Behavioral;

View File

@ -0,0 +1,109 @@
<internal_error>
<sub_system>ERR</sub_system>
<callstack>
0x7f1abe1b7be6: ccl_err + 0x7be6 (_ZN15ERR_STACKWALKER15get_stack_traceEPPKviiPv + 0xd8)
0x7f1abe1bae95: ccl_err + 0xae95 (_Z14err_terminatorv + 0x5a)
0x7f1ace73eae6: jtag_client + 0x82ae6 (_ZN10__cxxabiv111__terminateEPFvvE + 0x6)
0x7f1ace75df29: jtag_client + 0xa1f29
0x7f1ace73e715: jtag_client + 0x82715 (__gxx_personality_v0 + 0x2b5)
0x7f1ace7c0b23: jtag_client + 0x104b23 (_Unwind_RaiseException_Phase2 + 0x43)
0x7f1ace7c11da: jtag_client + 0x1051da (_Unwind_RaiseException + 0xfa)
0x7f1ace73ec2b: jtag_client + 0x82c2b (__cxa_throw + 0x5b)
0x7f1abe1bad4f: ccl_err + 0xad4f (err_sigaction_handler + 0x7a)
0x7f1aaba42520: c.so.6 + 0x42520
0x7f1ab18a8f86: QtGui.so.4 + 0x6a8f86
0x7f1ab18a9c86: QtGui.so.4 + 0x6a9c86
0x7f1ac9dc9864: QtCore.so.4 + 0x1c9864 (_ZN7QObject5eventEP6QEvent + 0x94)
0x7f1ab1465b3f: QtGui.so.4 + 0x265b3f (_ZN7QWidget5eventEP6QEvent + 0x7f)
0x7f1ab187c47b: QtGui.so.4 + 0x67c47b (_ZN6QFrame5eventEP6QEvent + 0x2b)
0x7f1ab190e089: QtGui.so.4 + 0x70e089 (_ZN19QAbstractScrollArea5eventEP6QEvent + 0xa9)
0x7f1ab18aa65b: QtGui.so.4 + 0x6aa65b (_ZN8QMdiArea5eventEP6QEvent + 0x10b)
0x7f1ab140484f: QtGui.so.4 + 0x20484f (_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent + 0xaf)
0x7f1ab140aea3: QtGui.so.4 + 0x20aea3 (_ZN12QApplication6notifyEP7QObjectP6QEvent + 0x183)
0x7f1ac9db5ac4: QtCore.so.4 + 0x1b5ac4 (_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent + 0x84)
0x7f1ac9deba5d: QtCore.so.4 + 0x1eba5d
0x7f1ac9de881d: QtCore.so.4 + 0x1e881d
0x7f1ac9de8841: QtCore.so.4 + 0x1e8841
0x7f1ab631bd3b: glib-2.0.so.0 + 0x55d3b (g_main_context_dispatch + 0x26b)
0x7f1ab63706c8: glib-2.0.so.0 + 0xaa6c8
0x7f1ab63193e3: glib-2.0.so.0 + 0x533e3 (g_main_context_iteration + 0x33)
0x7f1ac9de8af5: QtCore.so.4 + 0x1e8af5 (_ZN20QEventDispatcherGlib13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE + 0x65)
0x7f1ab14b889f: QtGui.so.4 + 0x2b889f
0x7f1ac9db4ad5: QtCore.so.4 + 0x1b4ad5 (_ZN10QEventLoop13processEventsE6QFlagsINS_17ProcessEventsFlagEE + 0x35)
0x7f1ac9db4ea8: QtCore.so.4 + 0x1b4ea8 (_ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE + 0x128)
0x7f1ab194f9f7: QtGui.so.4 + 0x74f9f7 (_ZN7QDialog4execEv + 0xe7)
0x7f1acdda49f3: gcl_afcq + 0x1a49f3 (_ZN16AFCQ_MSG_DISPLAY22internal_error_displayESs + 0x279)
0x7f1abf15a23d: ccl_msg + 0x4923d (_ZN10MSG_REPORT14internal_errorERKSs + 0x155)
0x7f1abf1761b5: ccl_msg + 0x651b5 (_ZN14MSG_ERROR_INFO8finalizeEv + 0x5f)
0x7f1abf17642d: ccl_msg + 0x6542d (_ZN18MSG_INTERNAL_ERROR12report_fatalEPKcPv + 0x6b)
0x7f1abe1bab0e: ccl_err + 0xab0e (_Z26err_report_fatal_exceptionPKcPv + 0x75)
0x7f1abe1bae0d: ccl_err + 0xae0d (err_sigaction_handler + 0x138)
0x7f1aaba42520: c.so.6 + 0x42520
0x7f1ab18a8f86: QtGui.so.4 + 0x6a8f86
0x7f1ab18a9c86: QtGui.so.4 + 0x6a9c86
0x7f1ab18aac8d: QtGui.so.4 + 0x6aac8d (_ZN8QMdiArea11resizeEventEP12QResizeEvent + 0x1ad)
0x7f1ab1466572: QtGui.so.4 + 0x266572 (_ZN7QWidget5eventEP6QEvent + 0xab2)
0x7f1ab187c47b: QtGui.so.4 + 0x67c47b (_ZN6QFrame5eventEP6QEvent + 0x2b)
0x7f1ab190c6e7: QtGui.so.4 + 0x70c6e7 (_ZN19QAbstractScrollArea13viewportEventEP6QEvent + 0x17)
0x7f1ab18aa285: QtGui.so.4 + 0x6aa285 (_ZN8QMdiArea13viewportEventEP6QEvent + 0x45)
0x7f1ab190f108: QtGui.so.4 + 0x70f108
0x7f1ac9db5dbf: QtCore.so.4 + 0x1b5dbf (_ZN23QCoreApplicationPrivate29sendThroughObjectEventFiltersEP7QObjectP6QEvent + 0x7f)
0x7f1ab1404820: QtGui.so.4 + 0x204820 (_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent + 0x80)
0x7f1ab140aea3: QtGui.so.4 + 0x20aea3 (_ZN12QApplication6notifyEP7QObjectP6QEvent + 0x183)
0x7f1ac9db5ac4: QtCore.so.4 + 0x1b5ac4 (_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent + 0x84)
0x7f1ab14acb7d: QtGui.so.4 + 0x2acb7d (_ZN14QWidgetPrivate15setGeometry_sysEiiiib + 0x37d)
0x7f1ab145ed08: QtGui.so.4 + 0x25ed08 (_ZN7QWidget11setGeometryERK5QRect + 0x78)
0x7f1ab190d576: QtGui.so.4 + 0x70d576 (_ZN26QAbstractScrollAreaPrivate14layoutChildrenEv + 0x3d6)
0x7f1ab18a66c1: QtGui.so.4 + 0x6a66c1
0x7f1ab18a97b3: QtGui.so.4 + 0x6a97b3
0x7f1ab18aa451: QtGui.so.4 + 0x6aa451 (_ZN8QMdiArea13viewportEventEP6QEvent + 0x211)
0x7f1ab190f108: QtGui.so.4 + 0x70f108
0x7f1ac9db5dbf: QtCore.so.4 + 0x1b5dbf (_ZN23QCoreApplicationPrivate29sendThroughObjectEventFiltersEP7QObjectP6QEvent + 0x7f)
0x7f1ab1404820: QtGui.so.4 + 0x204820 (_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent + 0x80)
0x7f1ab140aea3: QtGui.so.4 + 0x20aea3 (_ZN12QApplication6notifyEP7QObjectP6QEvent + 0x183)
0x7f1ac9db5ac4: QtCore.so.4 + 0x1b5ac4 (_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent + 0x84)
0x7f1ab18b96fc: QtGui.so.4 + 0x6b96fc (_ZN13QMdiSubWindow10closeEventEP11QCloseEvent + 0xcc)
0x7f1acf2a88cf: sys_qui + 0xb28cf (_ZN15QUI_MDI_SUB_WND10closeEventEP11QCloseEvent + 0x567)
0x7f1ab14668aa: QtGui.so.4 + 0x2668aa (_ZN7QWidget5eventEP6QEvent + 0xdea)
0x7f1ab18b996b: QtGui.so.4 + 0x6b996b (_ZN13QMdiSubWindow5eventEP6QEvent + 0x18b)
0x7f1ab140484f: QtGui.so.4 + 0x20484f (_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent + 0xaf)
0x7f1ab140aea3: QtGui.so.4 + 0x20aea3 (_ZN12QApplication6notifyEP7QObjectP6QEvent + 0x183)
0x7f1ac9db5ac4: QtCore.so.4 + 0x1b5ac4 (_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent + 0x84)
0x7f1ab145d3f8: QtGui.so.4 + 0x25d3f8 (_ZN14QWidgetPrivate12close_helperENS_9CloseModeE + 0x1f8)
0x7f1ab145d4e2: QtGui.so.4 + 0x25d4e2 (_ZN7QWidget5closeEv + 0x12)
0x7f1acf28c00a: sys_qui + 0x9600a (_ZN13QUI_FRAME_WND17close_all_in_listE5QListIP13QMdiSubWindowES2_5_GUID + 0x374)
0x7f1acf28c137: sys_qui + 0x96137 (_ZN13QUI_FRAME_WND17close_all_windowsE5_GUID + 0xed)
0x7f1acf29b269: sys_qui + 0xa5269 (_ZN13QUI_FRAME_WND10closeEventEP11QCloseEvent + 0x25f)
0x7f1acf3f5aa9: sys_qgq + 0x19aa9 (_ZN15QGQ_MAIN_WINDOW10closeEventEP11QCloseEvent + 0x35)
0x7f1ab14668aa: QtGui.so.4 + 0x2668aa (_ZN7QWidget5eventEP6QEvent + 0xdea)
0x7f1ab189995c: QtGui.so.4 + 0x69995c (_ZN11QMainWindow5eventEP6QEvent + 0x13c)
0x7f1ab140484f: QtGui.so.4 + 0x20484f (_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent + 0xaf)
0x7f1ab140aea3: QtGui.so.4 + 0x20aea3 (_ZN12QApplication6notifyEP7QObjectP6QEvent + 0x183)
0x7f1ac9db5ac4: QtCore.so.4 + 0x1b5ac4 (_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent + 0x84)
0x7f1ab145d3f8: QtGui.so.4 + 0x25d3f8 (_ZN14QWidgetPrivate12close_helperENS_9CloseModeE + 0x1f8)
0x7f1ab147e882: QtGui.so.4 + 0x27e882
0x7f1ab1480fa5: QtGui.so.4 + 0x280fa5 (_ZN12QApplication16x11ClientMessageEP7QWidgetP7_XEventb + 0x1e5)
0x7f1ab148d7a1: QtGui.so.4 + 0x28d7a1 (_ZN12QApplication15x11ProcessEventEP7_XEvent + 0xfa1)
0x7f1ab14b8d62: QtGui.so.4 + 0x2b8d62
0x7f1ab631bd3b: glib-2.0.so.0 + 0x55d3b (g_main_context_dispatch + 0x26b)
0x7f1ab63706c8: glib-2.0.so.0 + 0xaa6c8
0x7f1ab63193e3: glib-2.0.so.0 + 0x533e3 (g_main_context_iteration + 0x33)
0x7f1ac9de8af5: QtCore.so.4 + 0x1e8af5 (_ZN20QEventDispatcherGlib13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE + 0x65)
0x7f1ab14b889f: QtGui.so.4 + 0x2b889f
0x7f1ac9db4ad5: QtCore.so.4 + 0x1b4ad5 (_ZN10QEventLoop13processEventsE6QFlagsINS_17ProcessEventsFlagEE + 0x35)
0x7f1ac9db4ea8: QtCore.so.4 + 0x1b4ea8 (_ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE + 0x128)
0x7f1ac9db9cc4: QtCore.so.4 + 0x1b9cc4 (_ZN16QCoreApplication4execEv + 0xb4)
0x401eab: quartus + 0x1eab (_Z8qgq_mainiPPKc + 0x7b)
0x7f1abf14fe30: ccl_msg + 0x3ee30 (_Z15msg_main_threadPv + 0x10)
0x7f1abe181acc: ccl_thr + 0x5acc (thr_final_wrapper + 0xc)
0x7f1abf14feef: ccl_msg + 0x3eeef (_Z18msg_thread_wrapperPFPvS_ES_ + 0x62)
0x7f1abe1e9f9c: ccl_mem + 0x9f9c (_Z18mem_thread_wrapperPFPvS_ES_ + 0x5c)
0x7f1abe1b8b39: ccl_err + 0x8b39 (_Z18err_thread_wrapperPFPvS_ES_ + 0x27)
0x7f1abe181b0f: ccl_thr + 0x5b0f (thr_thread_wrapper + 0x15)
0x7f1abf151ea1: ccl_msg + 0x40ea1 (_Z12msg_exe_mainiPPKcPFiiS1_E + 0xb2)
</callstack>
<error>*** Fatal Error: Unhandled Exception</error>
<date>Tue May 2 10:47:59 2023
</date>
<version>Version 20.1.1 Build 720 11/11/2020 SJ Lite Edition</version>
</internal_error>

View File

@ -21,6 +21,7 @@
| [06](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula06) | Inheritance |
| [07](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula07) | Polymorphism |
| [08](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula08) | Interfaces, Collections |
| [09](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula09) | Collections |
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

Binary file not shown.

View File

@ -13,6 +13,7 @@
| [06](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula06) | Inheritance |
| [07](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula07) | Polymorphism |
| [08](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula08) | Interfaces, Collections |
| [09](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula09) | Collections |
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

View File

@ -2,6 +2,8 @@ package aula06.ex1;
import utils.DateYMD;
import java.util.Objects;
public class Person {
private String name;
private int cc;
@ -44,4 +46,17 @@ public class Person {
public String toString() {
return String.format("%s; CC: %d; Data de nascimento: %s", this.name, this.cc, this.birthDate);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Person person = (Person) o;
return cc == person.cc && Objects.equals(name, person.name) && Objects.equals(birthDate, person.birthDate);
}
@Override
public int hashCode() {
return Objects.hash(name, cc, birthDate);
}
}

View File

@ -0,0 +1,23 @@
# Programação Orientada a Objetos
## Aula 09
### Tópico principal da aula: Collections
* [Guião](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/guides/POO-2022-aula09.pdf)
### File List per Exercise
#### Ex1
* [ALDemo.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula09/ex1/ALDemo.java)
#### Ex2
* [CollectionTester.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula09/ex2/CollectionTester.java)
#### Ex3
* [PlaneTester.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula09/ex3/PlaneTester.java)
* [PlaneManager.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula09/ex3/PlaneManager.java)
* [Plane.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula09/ex3/Plane.java)
* [CommercialPlane.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula09/ex3/CommercialPlane.java)
* [MilitaryPlane.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula09/ex3/MilitaryPlane.java)
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

View File

@ -0,0 +1,42 @@
package aula09.ex1;
import aula06.ex1.Person;
import utils.DateYMD;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class ALDemo {
public static void main(String[] args) {
ArrayList<Integer> c1= new ArrayList<>();
for(int i= 10; i<= 100; i+=10) c1.add(i);System.out.println("Size: "+ c1.size());
for(int i= 0; i< c1.size(); i++)
System.out.println("Elemento: "+ c1.get(i));
ArrayList<String> c2= new ArrayList<>();
c2.add("Vento");
c2.add("Calor");
c2.add("Frio");
c2.add("Chuva");
System.out.println(c2);
Collections.sort(c2);
System.out.println(c2);
c2.remove("Frio");
c2.remove(0);
System.out.println(c2);
Set<Person> c3 = new HashSet<>();
c3.add(new Person("Ana", 12345678, new DateYMD(1, 1, 2000)));
c3.add(new Person("Joao", 42342289, new DateYMD(1, 1, 2000)));
c3.add(new Person("Maria", 12346789, new DateYMD(1, 1, 2000)));
c3.add(new Person("Marco", 12356789, new DateYMD(1, 1, 2000)));
c3.add(new Person("Ana", 12346789, new DateYMD(1, 1, 2000)));
for (Person p : c3) {
System.out.println(p);
}
}
}

View File

@ -0,0 +1,46 @@
package aula09.ex2;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class CollectionTester {
public static void main(String[] args) {
int DIM= 5000;
Collection<Integer> col= new ArrayList<>();
checkPerformance(col, DIM);
}
private static void checkPerformance(Collection<Integer> col, int DIM) {
double start, stop, delta;
// Add
start = System.nanoTime(); // clock snapshot before
for(int i=0; i<DIM; i++)
col.add(i);
stop = System.nanoTime(); // clock snapshot after
delta = (stop-start)/1e6; // convert to milliseconds
System.out.println(col.size()+ ": Add to "+col.getClass().getSimpleName() +" took "+ delta+ "ms");
// Search
start = System.nanoTime(); // clock snapshot before
for(int i=0; i<DIM; i++) {
int n = (int) (Math.random()*DIM);
if(!col.contains(n))
System.out.println("Not found???"+n);
}
stop = System.nanoTime(); // clock snapshot after
delta = (stop-start)/1e6; // convert nanoseconds to milliseconds
System.out.println(col.size()+ ": Search to "+ col.getClass().getSimpleName() +" took "+ delta+ "ms");
// Remove
start = System.nanoTime(); // clock snapshot before
Iterator<Integer> iterator = col.iterator();
while(iterator.hasNext()) {
iterator.next();
iterator.remove();
}
stop = System.nanoTime(); // clock snapshot after
delta = (stop-start)/1e6; // convert nanoseconds to milliseconds
System.out.println(col.size() + ": Remove from "+ col.getClass().getSimpleName() +" took "+ delta+ "ms");
}
}

View File

@ -0,0 +1,50 @@
package aula09.ex3;
import java.util.Objects;
public class CommercialPlane extends Plane {
private int numOfCrewMembers;
public CommercialPlane(String id, String manufacturer, String model, int year, int maxNumOfPassengers, double maxSpeed, int numOfCrewMembers) {
super(id, manufacturer, model, year, maxNumOfPassengers, maxSpeed);
this.numOfCrewMembers = numOfCrewMembers;
}
public int getNumOfCrewMembers() {
return this.numOfCrewMembers;
}
public void setNumOfCrewMembers(int numOfCrewMembers) {
this.numOfCrewMembers = numOfCrewMembers;
}
public String getPlaneType() {
return "Commercial";
}
@Override
public String toString() {
return "CommercialPlane {" +
"\n\tid='" + super.getId() + '\'' +
",\n\tmanufacturer='" + super.getManufacturer() + '\'' +
",\n\tmodel='" + super.getModel() + '\'' +
",\n\tproductionYear=" + super.getProductionYear() +
",\n\tmaxPassengers=" + super.getMaxPassengers() +
",\n\tmaxSpeed=" + super.getMaxSpeed() +
",\n\tnumOfCrewMembers=" + this.getNumOfCrewMembers() +
",\n}";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CommercialPlane plane)) return false;
if (!super.equals(o)) return false;
return this.getNumOfCrewMembers() == plane.getNumOfCrewMembers();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.getNumOfCrewMembers());
}
}

View File

@ -0,0 +1,50 @@
package aula09.ex3;
import java.util.Objects;
public class MilitaryPlane extends Plane {
private int numMissiles;
public MilitaryPlane(String id, String manufacturer, String model, int year, int maxPassengers, double maxSpeed, int numMissiles) {
super(id, manufacturer, model, year, maxPassengers, maxSpeed);
this.numMissiles = numMissiles;
}
public int getNumMissiles() {
return this.numMissiles;
}
public void setNumMissiles(int numMissiles) {
this.numMissiles = numMissiles;
}
public String getPlaneType() {
return "Military";
}
@Override
public String toString() {
return "MilitaryPlane {" +
"\n\tid='" + super.getId() + '\'' +
",\n\tmanufacturer='" + super.getManufacturer() + '\'' +
",\n\tmodel='" + super.getModel() + '\'' +
",\n\tproductionYear=" + super.getProductionYear() +
",\n\tmaxPassengers=" + super.getMaxPassengers() +
",\n\tmaxSpeed=" + super.getMaxSpeed() +
",\n\tnumMissiles=" + this.getNumMissiles() +
",\n}";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MilitaryPlane plane)) return false;
if (!super.equals(o)) return false;
return this.getNumMissiles() == plane.getNumMissiles();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.getNumMissiles());
}
}

View File

@ -0,0 +1,90 @@
package aula09.ex3;
import java.util.Objects;
public class Plane {
private final String id;
private String manufacturer;
private String model;
private int productionYear;
private int maxPassengers;
private double maxSpeed;
public Plane(String id, String manufacturer, String model, int productionYear, int maxPassengers, double maxSpeed) {
this.id = id;
this.manufacturer = manufacturer;
this.model = model;
this.productionYear = productionYear;
this.maxPassengers = maxPassengers;
this.maxSpeed = maxSpeed;
}
public String getId() {
return id;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getProductionYear() {
return productionYear;
}
public void setProductionYear(int productionYear) {
this.productionYear = productionYear;
}
public int getMaxPassengers() {
return maxPassengers;
}
public void setMaxPassengers(int maxPassengers) {
this.maxPassengers = maxPassengers;
}
public double getMaxSpeed() {
return maxSpeed;
}
public void setMaxSpeed(double maxSpeed) {
this.maxSpeed = maxSpeed;
}
@Override
public String toString() {
return "Plane {" +
"\n\tid='" + id + '\'' +
",\n\tmanufacturer='" + manufacturer + '\'' +
",\n\tmodel='" + model + '\'' +
",\n\tproductionYear=" + productionYear +
",\n\tmaxPassengers=" + maxPassengers +
",\n\tmaxSpeed=" + maxSpeed +
",\n}";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Plane plane)) return false;
return this.getProductionYear() == plane.getProductionYear() && this.getMaxPassengers() == plane.getMaxPassengers() && Double.compare(plane.getMaxSpeed(), this.getMaxSpeed()) == 0 && Objects.equals(this.getId(), plane.getId()) && Objects.equals(this.getManufacturer(), plane.getManufacturer()) && Objects.equals(this.getModel(), plane.getModel());
}
@Override
public int hashCode() {
return Objects.hash(this.getId(), this.getManufacturer(), this.getModel(), this.getProductionYear(), this.getMaxPassengers(), this.getMaxSpeed());
}
}

View File

@ -0,0 +1,76 @@
package aula09.ex3;
import java.util.*;
public class PlaneManager {
private final LinkedList<Plane> planes = new LinkedList<>();
public void addPlane(Plane plane) {
planes.add(plane);
}
public void removePlane(String id) {
for (Plane plane : planes) {
if (plane.getId().equals(id)) {
planes.remove(plane);
return;
}
}
}
public Plane searchPlane(String id) {
for (Plane plane : planes) {
if (plane.getId().equals(id)) {
return plane;
}
}
return null;
}
public LinkedList<Plane> getCommercialPlanes() {
LinkedList<Plane> commercialPlanes = new LinkedList<>();
for (Plane plane : planes) {
if (plane instanceof CommercialPlane) {
commercialPlanes.add(plane);
}
}
return commercialPlanes;
}
public LinkedList<Plane> getMilitaryPlanes() {
LinkedList<Plane> militaryPlanes = new LinkedList<>();
for (Plane plane : planes) {
if (plane instanceof MilitaryPlane) {
militaryPlanes.add(plane);
}
}
return militaryPlanes;
}
public Plane getFastestPlane() {
Plane fastestPlane = null;
for (Plane plane : planes) {
if (fastestPlane == null || plane.getMaxSpeed() > fastestPlane.getMaxSpeed()) {
fastestPlane = plane;
}
}
return fastestPlane;
}
public void printAllPlanes() {
for (Plane plane : planes) {
System.out.println(plane);
}
}
public void printAllPlanes(String type) {
for (Plane plane : planes) {
if (plane instanceof CommercialPlane && type.equals("commercial")) {
System.out.println(plane);
}
else if (plane instanceof MilitaryPlane && type.equals("military")) {
System.out.println(plane);
}
}
}
}

View File

@ -0,0 +1,104 @@
package aula09.ex3;
import java.util.Scanner;
public class PlaneTester {
public static void main(String[] args) {
PlaneManager planeManager = new PlaneManager();
Scanner scanner = new Scanner(System.in);
int choice;
do {
System.out.println("\nPlane Fleet Menu:");
System.out.println("1. Add a plane to the fleet");
System.out.println("2. Remove a plane from the fleet");
System.out.println("3. Search for a plane");
System.out.println("4. Print summary of all planes in the fleet");
System.out.println("5. Print list of all commercial planes in the fleet");
System.out.println("6. Print list of all military planes in the fleet");
System.out.println("7. Print the fastest plane in the fleet");
System.out.println("0. Exit");
System.out.print("Enter your choice: ");
choice = Integer.parseInt(scanner.nextLine());
switch (choice) {
case 1 -> addPlane(planeManager, scanner);
case 2 -> removePlane(planeManager, scanner);
case 3 -> searchPlane(planeManager, scanner);
case 4 -> printAllPlanes(planeManager);
case 5 -> printCommercialPlanes(planeManager);
case 6 -> printMilitaryPlanes(planeManager);
case 7 -> printFastestPlane(planeManager);
case 0 -> System.out.println("Exiting program...");
default -> System.out.println("Invalid choice. Please try again.");
}
} while (choice != 0);
scanner.close();
}
private static void addPlane(PlaneManager planeManager, Scanner scanner) {
System.out.print("Enter the plane's ID: ");
String id = scanner.nextLine();
System.out.print("Enter the plane's manufacturer: ");
String manufacturer = scanner.nextLine();
System.out.print("Enter the plane's model: ");
String model = scanner.nextLine();
System.out.print("Enter the plane's year of manufacture: ");
int year = Integer.parseInt(scanner.nextLine());
System.out.print("Enter the plane's passenger count: ");
int passengerCount = Integer.parseInt(scanner.nextLine());
System.out.print("Enter the plane's maximum speed: ");
int maxSpeed = Integer.parseInt(scanner.nextLine());
System.out.print("Enter the plane's type (commercial/military): ");
String type = scanner.nextLine();
if (type.equals("commercial")) {
System.out.print("Enter the plane's crew members count: ");
int crewMembersCount = Integer.parseInt(scanner.nextLine());
planeManager.addPlane(new CommercialPlane(id, manufacturer, model, year, passengerCount, maxSpeed, crewMembersCount));
}
else if (type.equals("military")) {
System.out.print("Enter the plane's missile count: ");
int missileCount = Integer.parseInt(scanner.nextLine());
planeManager.addPlane(new MilitaryPlane(id, manufacturer, model, year, passengerCount, maxSpeed, missileCount));
}
}
private static void removePlane(PlaneManager planeManager, Scanner scanner) {
System.out.print("Enter the plane's ID: ");
String id = scanner.nextLine();
if (planeManager.searchPlane(id) == null) {
System.out.println("Plane not found.");
return;
}
planeManager.removePlane(id);
}
private static void searchPlane(PlaneManager planeManager, Scanner scanner) {
System.out.print("Enter the plane's ID: ");
String id = scanner.nextLine();
Plane plane = planeManager.searchPlane(id);
if (plane == null) {
System.out.println("Plane not found.");
return;
}
System.out.println(plane);
}
private static void printAllPlanes(PlaneManager planeManager) {
planeManager.printAllPlanes();
}
private static void printCommercialPlanes(PlaneManager planeManager) {
planeManager.printAllPlanes("commercial");
}
private static void printMilitaryPlanes(PlaneManager planeManager) {
planeManager.printAllPlanes("military");
}
private static void printFastestPlane(PlaneManager planeManager) {
System.out.print(planeManager.getFastestPlane());
}
}

View File

@ -3,6 +3,10 @@ package utils;
import java.util.regex.Pattern;
public class Validations {
public static boolean validateEmail(String email) {
return Pattern.matches("^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$", email);
}
public static boolean validateVehiclePlate(String plate) {
return Pattern.matches("^[A-Z]{2}-\\d{2}-\\d{2}|\\d{2}-[A-Z]{2}-\\d{2}|\\d{2}-\\d{2}-[A-Z]{2}|[A-Z]{2}-\\d{2}-[A-Z]{2}|[A-Z]{2}-[A-Z]{2}-\\d{2}|\\d{2}-[A-Z]{2}-[A-Z]{2}$", plate);
}