-
Notifications
You must be signed in to change notification settings - Fork 0
Core work8 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SL-TX
wants to merge
26
commits into
master
Choose a base branch
from
core-work8
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Core work8 #20
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
756c3d0
part 1
SL-TX 6263c3f
part 2
SL-TX 1217fb2
part 3
SL-TX 0b0bb92
part 4
SL-TX 435a9ad
fixes
SL-TX a62f95a
part 1
SL-TX 5c4cad7
part 1
SL-TX ce60d2e
part 2
SL-TX bb6115b
part 1
SL-TX 9bddef7
part 2 part
SL-TX 435aac6
part 2
SL-TX 71ced12
Merge remote-tracking branch 'origin/core-work6' into core-work6
SL-TX 10d32af
part 2
SL-TX 6cfafe8
part 2
SL-TX a32ea86
part 1
SL-TX 09124de
part 2&3
SL-TX b8f8eec
Init
SL-TX f0db4ba
Part1
SL-TX 654279a
Merge remote-tracking branch 'origin/core-work8' into core-work8
SL-TX acb6b07
Part2
SL-TX d8f8e8e
Part3
SL-TX 75bb54d
Rename all Ru text to Eng text
SL-TX 7df9c16
Translate via yandex translate all variables
SL-TX e67e2b7
reduce types for driver
SL-TX fbae104
reduce types for driver
SL-TX be1e08b
all fixes
SL-TX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,219 @@ | ||
| package ru.skypro; | ||
|
|
||
| import ru.skypro.exceptions.WrongRightsException; | ||
| import ru.skypro.products.Recept; | ||
| import ru.skypro.products.Product; | ||
| import ru.skypro.transport.*; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import static ru.skypro.Utils.addToSet; | ||
| import static ru.skypro.Utils.remFromSet; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args){ | ||
| Set<Transport> cars = new HashSet<>(); | ||
| Set<Sponsor> sponsors = new HashSet<>(); | ||
| Set<Driver> drivers = new HashSet<>(); | ||
| var car1 = new Car("ad1","asd",2.2,CarBody.CROSSOVER); | ||
| var car2 = new Car("as2","a6sd",2.2,CarBody.CROSSOVER); | ||
| var car3 = new Bus("as3","a7sd",2.2, BusType.SMALL); | ||
| var car4 = new Truck("ag4","8asd",2.2,TruckBody.N2); | ||
|
|
||
| addToSet(cars,car1); | ||
| addToSet(cars,car2); | ||
| addToSet(cars,car3); | ||
| addToSet(cars,car4); | ||
|
|
||
| var sponsor1 = new Sponsor("asdf1", 1234); | ||
| var sponsor2 = new Sponsor("asdf2", 12345); | ||
| var sponsor3 = new Sponsor("asdf3", 123465); | ||
| var sponsor4 = new Sponsor("asdf4", 1234567); | ||
|
|
||
| addToSet(sponsors,sponsor1); | ||
| addToSet(sponsors,sponsor2); | ||
| addToSet(sponsors,sponsor3); | ||
| addToSet(sponsors,sponsor4); | ||
|
|
||
| Driver driver1 = null; | ||
| Driver driver2 = null; | ||
| Driver driver3 = null; | ||
| Driver driver4 = null; | ||
|
|
||
| try { | ||
| driver1 = new DriverB("asd1", true, 2, car1); | ||
| driver2 = new DriverB("asd2", true, 2, car2); | ||
| driver3 = new DriverD("asd3", true, 2, car3); | ||
| driver4 = new DriverC("asd4", true, 2, car4); | ||
|
|
||
| addToSet(drivers,driver1); | ||
| addToSet(drivers,driver2); | ||
| addToSet(drivers,driver3); | ||
| addToSet(drivers,driver4); | ||
| } | ||
| catch (WrongRightsException e){ | ||
| System.out.println(e); | ||
| } | ||
| Set<Mechanic> setMechanic = new HashSet<>(); | ||
| Mechanic mech1 = new Mechanic("a","b","asd",List.of("Car")); | ||
| Mechanic mech2 = new Mechanic("c","d","dsa",List.of("Bus","Truck")); | ||
|
|
||
| addToSet(setMechanic,mech1); | ||
| addToSet(setMechanic,mech2); | ||
|
|
||
| car1.addMechanic(mech1); | ||
| car2.addMechanic(mech1); | ||
| car3.addMechanic(mech1); | ||
| car3.addMechanic(mech2); | ||
| car4.addMechanic(mech2); | ||
| car1.addDrivers(driver1); | ||
| car2.addDrivers(driver2); | ||
| car3.addDrivers(driver3); | ||
| car4.addDrivers(driver4); | ||
| car1.addSponsor(sponsor1); | ||
| car2.addSponsor(sponsor2); | ||
| car3.addSponsor(sponsor1); | ||
| car4.addSponsor(sponsor2); | ||
| car1.addSponsor(sponsor3); | ||
| car2.addSponsor(sponsor4); | ||
| // var texhStantion = new TechStantion<>(); | ||
| // for (Transport car: cars) { | ||
| // System.out.println( | ||
| // "Для машины: " +car.toString()+"\n"+ | ||
| // "Водитель: " + car.getDriver().toString()+"\n"+ | ||
| // "Спонсоры: " + car.getSponsorsList().toString()+"\n"+ | ||
| // "Механики: " + car.getMechanicList().toString() | ||
| // ); | ||
| // texhStantion.addToQueue(car); | ||
| // } | ||
| // texhStantion.doTechOsmotr(); | ||
| // texhStantion.doTechOsmotr(); | ||
| // texhStantion.doTechOsmotr(); | ||
| // texhStantion.doTechOsmotr(); | ||
| // texhStantion.doTechOsmotr(); | ||
|
|
||
| Set<Product> setOfProducts = new HashSet<>(); | ||
| Product banana = new Product("Банан", 120,10); | ||
| Product orange = new Product("Апельсин", 240,10); | ||
| try { | ||
| Product test = new Product("Тест", 240,null); | ||
| } catch (RuntimeException e){ | ||
| System.out.println(e); | ||
| } | ||
| try { | ||
| addToSet(setOfProducts,banana); | ||
| addToSet(setOfProducts,orange); | ||
| addToSet(setOfProducts,banana); | ||
| } catch (RuntimeException e){ | ||
| System.out.println(e); | ||
| } | ||
| try { | ||
| remFromSet(setOfProducts,banana); | ||
| remFromSet(setOfProducts,banana); | ||
| } catch (RuntimeException e){ | ||
| System.out.println(e); | ||
| } | ||
| System.out.println(List.of(setOfProducts.toArray())); | ||
| addToSet(setOfProducts,banana); | ||
| Set<Recept> SpisokReceptov = new HashSet<>(); | ||
| Recept recept1 = new Recept(setOfProducts,"Рецепт 1"); | ||
| Recept recept2 = new Recept(setOfProducts,"Рецепт 2"); | ||
| try { | ||
| addToSet(SpisokReceptov, recept1); | ||
| addToSet(SpisokReceptov, recept2); | ||
| addToSet(SpisokReceptov, recept1); | ||
| } catch (RuntimeException e){ | ||
| System.out.println(e); | ||
| } | ||
| System.out.println(List.of(SpisokReceptov.toArray())); | ||
| Set<Integer> manyIntVals = new HashSet<>(); | ||
| for (int i=0;i<20;i++){ | ||
| manyIntVals.add((int) Math.round(Math.random()*1000)); | ||
| } | ||
| System.out.println(List.of(manyIntVals.toArray())); | ||
| manyIntVals.removeIf(i -> i % 2 == 1); | ||
| System.out.println(List.of(manyIntVals.toArray())); | ||
|
|
||
| for (var element:sponsors) { | ||
| System.out.println(element); | ||
| } | ||
| for (var element:cars) { | ||
| System.out.println(element); | ||
| } | ||
| for (var element:drivers) { | ||
| System.out.println(element); | ||
| } | ||
| for (var element:setMechanic) { | ||
| System.out.println(element); | ||
| } | ||
| //part 2 | ||
| Set<String> uniqueQuestion = new HashSet<>(); | ||
| do { | ||
| Random r = new Random(); | ||
| int int1 = r.nextInt(7)+2; | ||
| int int2 = r.nextInt(7)+2; | ||
| if (!uniqueQuestion.contains(int2 + "*" + int1)) { | ||
| uniqueQuestion.add(int1 + "*" + int2); | ||
| } | ||
|
|
||
| } while (uniqueQuestion.size()<=14);//numRows - 1 | ||
| for (var element:uniqueQuestion) { | ||
| System.out.println(element); | ||
| } | ||
| //part 3 | ||
|
|
||
| Passport passport1 = new Passport("1234","1234","1234","1234","12.12.12"); | ||
| Passport passport2 = new Passport("4321","4321","4321","4321","01.12.12"); | ||
| HashMap<String,Passport> passportHashMap = new HashMap<>(); | ||
| passportHashMap.put(passport1.getNumPassport(),passport1); | ||
| passportHashMap.put(passport2.getNumPassport(),passport2); | ||
| passportHashMap.put(passport1.getNumPassport(),passport1); | ||
| Passport passport3 = new Passport("1234","1234","4321","1234","12.01.12"); | ||
| savePassport(passportHashMap,passport3); | ||
| System.out.println(getPassport(passportHashMap,"1234")); | ||
|
|
||
| } | ||
|
|
||
| public static void savePassport(Map<String, Passport> refMap, Passport passport){ | ||
| if (refMap.containsKey(passport.getNumPassport())){ | ||
| refMap.remove(passport.getNumPassport()); | ||
| refMap.put(passport.getNumPassport(), passport); | ||
| } else | ||
| refMap.put(passport.getNumPassport(), passport); | ||
| } | ||
|
|
||
| public static Passport getPassport(Map<String,Passport> refMap, String key){ | ||
| return refMap.getOrDefault(key, null); | ||
| } | ||
|
|
||
|
|
||
| private static void addInSomeQueue(List<Queue<String>> q1, String val){ | ||
| Queue<String> minindex; | ||
| int coun = 99; | ||
| boolean addded = false; | ||
| minindex=q1.get(0); | ||
| for (var qqq: q1 | ||
| ) { | ||
| System.out.println(qqq.size()); | ||
| if (qqq.size()==5) { continue;} | ||
| if (coun >= qqq.size()) { | ||
| coun = qqq.size(); | ||
| minindex = qqq; | ||
| addded = true; | ||
| } | ||
| } | ||
| if (!addded){ | ||
| System.out.println("полное заполнение всех очередей"); | ||
| q1.add(new ArrayDeque<>(5)); | ||
| minindex = q1.get(q1.size()-1); | ||
| } | ||
| minindex.offer(val); | ||
| // System.out.println(q1.get(0).size()); | ||
| // System.out.println(q1.get(1).size()); | ||
| } | ||
|
|
||
| private static void removeFromSomeQueue(List<Queue<String>> q1){ | ||
| int num = (int) Math.round(Math.random()* (q1.size()-1)); | ||
| q1.get(num).poll(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package ru.skypro; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Mechanic { | ||
| private final String firstName; | ||
| private final String lastName; | ||
| private final String companyName; | ||
| private final List<String> listCarTypes; | ||
|
|
||
| public Mechanic(String firstName, String lastName, String companyName, List<String> listCarTypes) { | ||
| this.firstName = firstName; | ||
| this.lastName = lastName; | ||
| this.companyName = companyName; | ||
| this.listCarTypes = listCarTypes; | ||
| } | ||
|
|
||
| public String getFirstName() { | ||
| return firstName; | ||
| } | ||
|
|
||
| public String getLastName() { | ||
| return lastName; | ||
| } | ||
|
|
||
| public String getCompanyName() { | ||
| return companyName; | ||
| } | ||
|
|
||
| public List<String> getListCarTypes() { | ||
| return listCarTypes; | ||
| } | ||
|
|
||
| private void carryOutMaintenance(){ | ||
|
|
||
| } | ||
| private void repairCar(){ | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Mechanic{" + | ||
| "firstName='" + firstName + '\'' + | ||
| ", lastName='" + lastName + '\'' + | ||
| ", companyName='" + companyName + '\'' + | ||
| ", listCarTypes=" + listCarTypes + | ||
| '}'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package ru.skypro; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Passport { | ||
| private final String numPassport; | ||
| private final String lastName; | ||
| private final String firstName; | ||
| private final String secondName; | ||
| private final String birthDate; | ||
|
|
||
| public Passport(String numPassport, String lastName, String firstName, String secondName, String birthDate) { | ||
| this.numPassport = numPassport; | ||
| this.lastName = lastName; | ||
| this.firstName = firstName; | ||
| this.secondName = secondName; | ||
| this.birthDate = birthDate; | ||
| } | ||
|
|
||
| public String getNumPassport() { | ||
| return numPassport; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Passport{" + | ||
| "НомерПаспорта='" + numPassport + '\'' + | ||
| ", Фамилия='" + lastName + '\'' + | ||
| ", Имя='" + firstName + '\'' + | ||
| ", Отчество='" + secondName + '\'' + | ||
| ", ДатаРождения='" + birthDate + '\'' + | ||
| '}'; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (!(o instanceof Passport passport)) return false; | ||
| return Objects.equals(numPassport, passport.numPassport); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(numPassport); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package ru.skypro; | ||
|
|
||
| public class Sponsor { | ||
| private final String name; | ||
| private final Integer sumSupport; | ||
|
|
||
| public Sponsor(String name, Integer sumSupport) { | ||
| this.name = name; | ||
| this.sumSupport = sumSupport; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| private void sponsirovatZaezd(){} | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Sponsor{" + | ||
| "name='" + name + '\'' + | ||
| ", sumSupport=" + sumSupport + | ||
| '}'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package ru.skypro; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| public final class Utils { | ||
|
|
||
| static <T> void addToSet(Set<T> set, T val){ | ||
| if (!set.add(val)){ | ||
| throw new RuntimeException("необходимо выбросить исключение"); | ||
| } | ||
| } | ||
|
|
||
| static <T> void remFromSet(Set<T> set, T val){ | ||
| if(!set.remove(val)){ | ||
| throw new RuntimeException("Ошибка удаления товара"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package ru.skypro.exceptions; | ||
|
|
||
| public class DiagnosticFailException extends Exception{ | ||
| public DiagnosticFailException() { | ||
| super("программа должна выбросить ошибку."); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package ru.skypro.exceptions; | ||
|
|
||
| public class WrongRightsException extends Exception{ | ||
|
|
||
| public WrongRightsException() { | ||
| super("Необходимо указать тип прав!"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нет проверки на зеркальный пример