├── README.md ├── average_calculator └── main.dart ├── card_game └── main.dart ├── converter_tool └── main.dart ├── distance_calculator └── main.dart ├── draw_line └── main.dart ├── duplicated_name └── main.dart ├── factors_of_numbers └── main.dart ├── fast_writer_game └── main.dart ├── goot_fox_corn └── main.dart ├── grad_calculator └── main.dart ├── guess_game └── main.dart ├── guess_generator └── main.dart ├── guess_number_with_higher_or_lower └── main.dart ├── how_many_days_you_live └── main.dart ├── insertion_sort └── main.dart ├── joke_game └── main.dart ├── logical_gate └── main.dart ├── love_game └── main.dart ├── rectangle_area_and_circumference └── main.dart ├── rock_paper_scissors └── main.dart ├── rock_paper_scissors_guess └── main.dart ├── say_hello └── main.dart ├── shap_draw └── main.dart ├── square_shap └── main.dart ├── stack └── stack.dart ├── star_art └── main.dart ├── sum └── main.dart ├── timer_guess └── main.dart ├── translator_game └── main.dart ├── triangle_star └── main.dart ├── vote_determiner └── main.dart └── words_count └── main.dart /README.md: -------------------------------------------------------------------------------- 1 | # dart_challenge 2 | challenges in dart programming language 3 | give our repo star to add more challenges in dart 4 | {Target is 500 challenge} 5 | #My social media accounts 6 | Gmail : hossamibrahim18@gmail.com 7 | Facebook : https://www.facebook.com/profile.php?id=100047228409786 8 | Ask fm : https://ask.fm/hossamibrahim2001?utm_source=copy_link&utm_medium=android -------------------------------------------------------------------------------- /average_calculator/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | find average of 3 numbers that user enter 3 | */ 4 | 5 | import 'dart:io'; 6 | 7 | final Average average = Average(); 8 | main() { 9 | average.averageCalculator(); 10 | } 11 | 12 | class Average { 13 | int number1, number2, number3, sumOfNumbers; 14 | double result; 15 | void averageCalculator() { 16 | try { 17 | stdout.write('Enter first number: '); 18 | number1 = int.parse(stdin.readLineSync()); 19 | stdout.write('Enter second number: '); 20 | number2 = int.parse(stdin.readLineSync()); 21 | stdout.write('Enter third number: '); 22 | number3 = int.parse(stdin.readLineSync()); 23 | sumOfNumbers = number1 + number2 + number3; 24 | result = sumOfNumbers / 3; 25 | print('average is $result'); 26 | } catch (e) {} 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /card_game/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program that will generate a 3 | random playing card e.g. ‘9 Hearts’, 4 | ‘Queen Spades’ when the return key is 5 | pressed. 6 | Rather than generate a random number 7 | from 1 to 52. Create two random numbers – one for the suit and one for the 8 | card. 9 | 10 | Extension 11 | Make a loop structure so playing cards can keep being generated 12 | */ 13 | import 'dart:io'; 14 | import 'dart:math'; 15 | 16 | final LoopToCreateCards loopToCreateCards = LoopToCreateCards(); 17 | main() { 18 | stdout.write('20 card\n'); 19 | loopToCreateCards.loopToCreateCards(); 20 | } 21 | 22 | class LoopToCreateCards { 23 | static List cardName = [ 24 | 'Heart', //0 25 | 'Circle', //1 26 | 'Certain', //2 27 | ]; 28 | void loopToCreateCards() { 29 | for (int i = 0; i <= 52; i++) { 30 | int random = Random().nextInt(52); 31 | int randomIndex = Random().nextInt(cardName.length); 32 | print('$random ${cardName[randomIndex]}'); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /converter_tool/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | make a converter app that can convert between Celsius and Fahrenheit and still 3 | */ 4 | 5 | import 'dart:io'; 6 | 7 | final Controller _controller = Controller(); 8 | 9 | main() => _controller.controller(); 10 | 11 | class Controller { 12 | String userInput; 13 | double userDegree; 14 | void controller() { 15 | print( 16 | 'Enter a for convert Fahrenheit and Celsius\nEnter b for convert Celsius and Fahrenheit'); 17 | userInput = stdin.readLineSync(); 18 | userInput == 'a' ? print(FToCByAInput()) : print(CToFByAInput()); 19 | } 20 | 21 | // ignore: missing_return 22 | double FToCByAInput() { 23 | print('Enter degree'); 24 | try { 25 | userDegree = double.parse(stdin.readLineSync()); 26 | return (userDegree * 1.8) + 32; 27 | } catch (e) {} 28 | } 29 | 30 | // ignore: missing_return 31 | double CToFByAInput() { 32 | print('Enter degree'); 33 | try { 34 | userDegree = double.parse(stdin.readLineSync()); 35 | return (userDegree - 32) / 1.8; 36 | } catch (e) {} 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /distance_calculator/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Challenge 4 3 | Write a program that will work out the 4 | distance travelled if the user enters in the 5 | speed and the time. 6 | Extension 7 | Get the program to tell you the speed you would have to travel 8 | at in order to go a distance within a certain time entered by the 9 | user. 10 | */ 11 | 12 | import 'dart:io'; 13 | 14 | main() { 15 | final Switcher _switcher = Switcher(); 16 | _switcher.switcher(); 17 | } 18 | 19 | class Switcher { 20 | final TakeUserSpeedAndTime _takeUserSpeedAndTime = TakeUserSpeedAndTime(); 21 | final DistanceCalculator _distanceCalculator = DistanceCalculator(); 22 | final SpeedRequiredCalculator _speedRequiredCalculator = 23 | SpeedRequiredCalculator(); 24 | void switcher() { 25 | try { 26 | stdout.write(''' 27 | if you want to know distance write d, 28 | if you want to know how to reach distace by increase spead write s 29 | '''); 30 | 31 | String determiner = stdin.readLineSync(); 32 | switch (determiner) { 33 | case 'd': 34 | { 35 | String distanceValue = _distanceCalculator.distaceCalculator( 36 | _takeUserSpeedAndTime.takeUserSpeed(), 37 | _takeUserSpeedAndTime.takeUserTime(), 38 | ); 39 | print(distanceValue); 40 | } 41 | break; 42 | 43 | case 's': 44 | { 45 | String distanceValue = 46 | _speedRequiredCalculator.speedRequiredCalculator( 47 | _takeUserSpeedAndTime.takeUserDistance(), 48 | _takeUserSpeedAndTime.takeUserTime(), 49 | ); 50 | print(distanceValue); 51 | } 52 | break; 53 | } 54 | } catch (e) { 55 | print('please rerun app and enter d or s only and in small leters'); 56 | } 57 | } 58 | } 59 | 60 | class TakeUserSpeedAndTime { 61 | double takeUserSpeed() { 62 | try { 63 | stdout.write('Enter speed: '); 64 | return double.parse(stdin.readLineSync()); 65 | } catch (e) { 66 | print('please re run app and enter numbers '); 67 | return null; 68 | } 69 | } 70 | 71 | double takeUserTime() { 72 | try { 73 | stdout.write('Enter time: '); 74 | return double.parse(stdin.readLineSync()); 75 | } catch (e) { 76 | print('please re run app and enter numbers '); 77 | return null; 78 | } 79 | } 80 | 81 | double takeUserDistance() { 82 | try { 83 | stdout.write('Enter distance: '); 84 | return double.parse(stdin.readLineSync()); 85 | } catch (e) { 86 | print('please re run app and enter numbers '); 87 | return null; 88 | } 89 | } 90 | } 91 | 92 | class SpeedRequiredCalculator { 93 | String speedRequiredCalculator(double distance, double time) { 94 | return 'speed is ${distance / time}'; 95 | } 96 | } 97 | 98 | class DistanceCalculator { 99 | String distaceCalculator(double speed, double time) { 100 | return 'speed is ${speed * time}'; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /draw_line/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program that uses only two output statements, cout << "#" and cout << "\n", to produce a line 3 | of five hash symbols: 4 | ##### 5 | */ 6 | import 'dart:io'; 7 | 8 | main() { 9 | for (int index = 1; index <= 5; index++) { 10 | stdout.write('#'); 11 | } 12 | stdout.write('\n'); 13 | } 14 | -------------------------------------------------------------------------------- /duplicated_name/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program that will store names into an array. 3 | As a new name is entered it will be added to the end of the array. 4 | The user can keep adding names until they enter the dummy 5 | value ‘exit’ 6 | Once this has been done the program will display any duplicate 7 | names. 8 | E.g. 9 | Bill 10 | Mary 11 | Anisha 12 | Mary 13 | exit 14 | Mary is a duplicate. 15 | */ 16 | import 'dart:io'; 17 | 18 | final DuplicateDeterminer _determiner = DuplicateDeterminer(); 19 | 20 | main() => _determiner.duplicate(); 21 | 22 | class DuplicateDeterminer { 23 | static List arrayOfNames = [ 24 | 'ibrahim', 25 | 'hossam', 26 | 'mohammed', 27 | 'ahmed', 28 | 'hossam', 29 | ]; 30 | List arrayOfduplicatedNames = arrayOfNames.toSet().toList(); 31 | 32 | void duplicate() { 33 | for (int i = 0; i < arrayOfNames.length; i++) { 34 | arrayOfduplicatedNames.add(''); 35 | if (arrayOfNames[i] != arrayOfduplicatedNames[i]) { 36 | print('${arrayOfNames[i]} is duplicated'); 37 | } else if (arrayOfNames[i] == arrayOfduplicatedNames[i]) { 38 | stdout.write(''); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /factors_of_numbers/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program that will display all the factors of a number, entered by the user, that are bigger than 1. 3 | (e.g. the factors of the number 12 are 6,4,3 and 2 because they divide into 12 exactly). 4 | Extension 5 | Tell the user if the number they 6 | entered is a prime number 7 | */ 8 | 9 | import 'dart:io'; 10 | 11 | final FactorsAndPrime factorsAndPrime = FactorsAndPrime(); 12 | 13 | main() { 14 | factorsAndPrime.factors(); 15 | } 16 | 17 | class FactorsAndPrime { 18 | int userInputNumber, index; 19 | List indexArray = []; 20 | void factors() { 21 | stdout.write('Enter number to check it: '); 22 | userInputNumber = int.parse(stdin.readLineSync()); 23 | for (index = 1; index <= userInputNumber; index++) { 24 | if (userInputNumber % index == 0) { 25 | print('factors of $userInputNumber is $index'); 26 | indexArray.add(index); 27 | } 28 | } 29 | prime(); 30 | } 31 | 32 | void prime() { 33 | indexArray.length == 2 34 | ? stdout.write('it is prime') 35 | : stdout.write('not a prime number'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /fast_writer_game/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Extend the program in Challenge 5 to make agame for 3 | seeing how quick people are at typing the alphabet. 4 | */ 5 | 6 | import 'dart:io'; 7 | 8 | main() { 9 | final Determiner determiner = Determiner(); 10 | determiner.determiner(); 11 | } 12 | 13 | class ActionInUserInput { 14 | String alpahbet; 15 | bool timefinsh = false; 16 | void actionInUserInput() { 17 | Future.delayed( 18 | Duration(seconds: 10), 19 | () { 20 | print('time finshed'); 21 | timefinsh = true; 22 | }, 23 | ); 24 | stdout.write('Enter from a to d: '); 25 | alpahbet = stdin.readLineSync(); 26 | if ((alpahbet == 'abcd' || alpahbet == 'ABCD') && timefinsh == false) { 27 | print('you are winner'); 28 | } else if ((alpahbet != 'abcd' || alpahbet != 'ABCD') || 29 | timefinsh == true) { 30 | print('you are losser'); 31 | } 32 | } 33 | } 34 | 35 | class Determiner { 36 | final ActionInUserInput actionInUserInput = ActionInUserInput(); 37 | String startPermisn; 38 | void determiner() { 39 | stdout.write('Enter y: '); 40 | startPermisn = stdin.readLineSync(); 41 | switch (startPermisn) { 42 | case 'y': 43 | { 44 | actionInUserInput.actionInUserInput(); 45 | } 46 | break; 47 | default: 48 | { 49 | print('please enter y'); 50 | } 51 | break; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /goot_fox_corn/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | try to simulate it as a game to user 3 | The fox, the goose, and the sack of corn. The boat can carry one item at a time. The fox cannot 4 | be left on the same shore as the goose, and the goose cannot be left on the same shore as the sack of corn 5 | 6 | */ 7 | import 'dart:io'; 8 | 9 | ///solution in sudo code 10 | ///1.send goot 11 | ///2.send fox and 12 | ///3.take goot to another side 13 | ///4.send corn 14 | ///5.send goot againimport 'dart:io'; 15 | 16 | main() { 17 | final Story story = Story(); 18 | story.storyCore(); 19 | } 20 | 21 | class Story { 22 | String userInput; 23 | String outputToUser = 'Enter send or return {goot , corn or fox}: '; 24 | String storyInString = 25 | 'The fox, the goose, and the sack of corn. The boat can carry one item at a time. The fox cannot be left on the same shore as the goose, and the goose cannot be left on the same shore as the sack of corn'; 26 | String sendGoot = 'send goot'; 27 | String sendFox = 'send fox'; 28 | String returnGoot = 'return goot'; 29 | String sendCorn = 'send corn'; 30 | void storyCore() { 31 | print(storyInString); 32 | stdout.write(outputToUser); 33 | userInput = stdin.readLineSync(); 34 | if (userInput == sendGoot) { 35 | stdout.write(outputToUser); 36 | userInput = stdin.readLineSync(); 37 | if (userInput == sendFox) { 38 | stdout.write(outputToUser); 39 | userInput = stdin.readLineSync(); 40 | if (userInput == returnGoot) { 41 | stdout.write(outputToUser); 42 | userInput = stdin.readLineSync(); 43 | if (userInput == sendCorn) { 44 | stdout.write(outputToUser); 45 | userInput = stdin.readLineSync(); 46 | if (userInput == sendGoot) { 47 | print('you win'); 48 | } else { 49 | printYouloss(); 50 | } 51 | } else { 52 | printYouloss(); 53 | } 54 | } else { 55 | printYouloss(); 56 | } 57 | } else { 58 | printYouloss(); 59 | } 60 | } else { 61 | printYouloss(); 62 | } 63 | } 64 | 65 | void printYouloss() { 66 | print('you loss'); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /grad_calculator/main.dart: -------------------------------------------------------------------------------- 1 | /*Write a function that will convert a UMS score into a grade. The 2 | function will return ‘A’—> ‘U’. 3 | The function will require a parameter to do its job: the mark 4 | The formula for AS level is >=80% —>‘A’, >=70%—>‘B’, >=60%—>‘C’ 5 | etc. 6 | Assume the maximum module mark is 100 7 | Having written the function we want to use it three times. 8 | Write a program with the function that allows the user to enter 9 | two module AS scores and displays the grade. It then adds the two 10 | results together and displays the students overall grade. E.g. 11 | Enter Module 1 result: 78 12 | Enter Module 1 result: 67 13 | Result 14 | Module 1 : B 15 | Module 2: C 16 | AS Level : B 17 | */ 18 | 19 | import 'dart:io'; 20 | 21 | main() { 22 | final UserInputForNormalCounter userInputForNormalCounter = 23 | UserInputForNormalCounter(); 24 | 25 | userInputForNormalCounter.userInputForNormalCounter(); 26 | } 27 | 28 | class UserInputForNormalCounter { 29 | final NormalGradeCounter normalGradeCounter = NormalGradeCounter(); 30 | 31 | void userInputForNormalCounter() { 32 | stdout.write('Enter grade1: '); 33 | int gradeFromUser = int.parse(stdin.readLineSync()); 34 | 35 | stdout.write('Enter 2: '); 36 | int gradeFromUser2 = int.parse(stdin.readLineSync()); 37 | 38 | normalGradeCounter.normalgradeCounterLogic( 39 | gradeFromUser: gradeFromUser, 40 | gradeFromUser2: gradeFromUser2, 41 | ); 42 | } 43 | } 44 | 45 | class NormalGradeCounter { 46 | int a = 80, b = 70, c = 60, d = 50, finalGrade = 100; 47 | void normalgradeCounterLogic({int gradeFromUser, gradeFromUser2}) { 48 | if (gradeFromUser >= a && gradeFromUser <= finalGrade) { 49 | print('Model1: A level'); 50 | } else if (gradeFromUser >= b && gradeFromUser < a) { 51 | print('Model1: b level'); 52 | } else if (gradeFromUser >= c && gradeFromUser < b) { 53 | print('Model1: c level'); 54 | } else if (gradeFromUser >= d && gradeFromUser < c) { 55 | print('Model1: d level'); 56 | } else { 57 | print('Model1: f level'); 58 | } 59 | 60 | if (gradeFromUser2 >= a && gradeFromUser2 <= finalGrade) { 61 | print('Model2: A level'); 62 | } else if (gradeFromUser2 >= b && gradeFromUser2 <= a) { 63 | print('Model2: b level'); 64 | } else if (gradeFromUser2 >= c && gradeFromUser2 < b) { 65 | print('Model2: c level'); 66 | } else if (gradeFromUser2 >= d && gradeFromUser2 < c) { 67 | print('Model2: d level'); 68 | } else { 69 | print('Model2: f level'); 70 | } 71 | 72 | if (((gradeFromUser + gradeFromUser2) / 2) >= a && 73 | ((gradeFromUser + gradeFromUser2) / 2) <= finalGrade) { 74 | print('AS: A level'); 75 | } else if (((gradeFromUser + gradeFromUser2) / 2) >= b && 76 | ((gradeFromUser + gradeFromUser2) / 2) < a) { 77 | print('AS: b level'); 78 | } else if (((gradeFromUser + gradeFromUser2) / 2) >= c && 79 | ((gradeFromUser + gradeFromUser2) / 2) < b) { 80 | print('AS: c level'); 81 | } else if (((gradeFromUser + gradeFromUser2) / 2) >= d && 82 | ((gradeFromUser + gradeFromUser2) / 2) < c) { 83 | print('AS: d level'); 84 | } else { 85 | print('AS: f level'); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /guess_game/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | by using do while loop create a simple game that can create a number then 3 | take user guess and compare among them and tell user your input is too height or 4 | to low 5 | e.g. 6 | enter your guess 7 | 20 8 | to low 9 | 30 10 | to height 11 | 25 12 | yes 13 | */ 14 | 15 | import 'dart:io'; 16 | import 'dart:math'; 17 | 18 | final GuessGameViewModel guess = GuessGameViewModel(); 19 | 20 | main() => guess.guess(); 21 | 22 | class GuessGameViewModel { 23 | Random _random = Random(); 24 | int _computerGuess, _userGuessValue; 25 | void guess() { 26 | print('Enter your guess'); 27 | _computerGuess = _random.nextInt(40); 28 | do { 29 | try { 30 | _userGuessValue = int.parse(stdin.readLineSync()); 31 | _userGuessValue == _computerGuess 32 | ? print('yes you are right') 33 | // ignore: unnecessary_statements 34 | : (_userGuessValue > _computerGuess 35 | ? print('too height') 36 | : print('too low')); 37 | } catch (e) { 38 | print(e.toString()); 39 | } 40 | } while (_userGuessValue != _computerGuess); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /guess_generator/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Challenge 13 3 | Write a program for a game where the computer generates a 4 | random starting number between 1--5. and try to gess correct number 5 | */ 6 | import 'dart:io'; 7 | import 'dart:math'; 8 | 9 | Game gameLogic = Game(); 10 | main() { 11 | gameLogic.gamelogic(); 12 | } 13 | 14 | class Game { 15 | Random random = Random(); 16 | int userInput; 17 | void gamelogic() { 18 | int randomvalue = random.nextInt(4) + 1; 19 | try { 20 | stdout.write('Enter number between 1 to 5: '); 21 | userInput = int.parse(stdin.readLineSync()); 22 | if (userInput > 0 || userInput < 6) { 23 | userInput == randomvalue 24 | ? print('You are Winner') 25 | : print('you are losser correct one is $randomvalue'); 26 | } else { 27 | print('Enter number'); 28 | } 29 | } catch (e) {} 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /guess_number_with_higher_or_lower/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program for a Higher / Lower guessing game 3 | The computer randomly generates a sequence of up to 10 numbers between 1 and 13. The player each after seeing each number 4 | in turn has to decide whether the next number is higher or lower. 5 | If you can remember Brucie’s ‘Play your cards right’ it’s basically 6 | that. If you get 10 guesses right you win the game. 7 | Starting number : 12 8 | Higher(H) or lower(L)? L 9 | Next number 8 10 | Higher(H) or lower(L)? L 11 | Next number 11 12 | You lose 13 | 14 | Extensions 15 | Give the players two lives 16 | Make sure only H or L can 17 | be entered 18 | */ 19 | 20 | import 'dart:io'; 21 | import 'dart:math'; 22 | 23 | final CoreOfGame coreOfGame = CoreOfGame(); 24 | main() { 25 | coreOfGame.game(); 26 | } 27 | 28 | class CoreOfGame { 29 | int userInput; 30 | Random _random = Random(); 31 | int randomValue; 32 | bool isWinner = false; 33 | void game() { 34 | randomValue = _random.nextInt(9) + 1; 35 | print(randomValue); 36 | do { 37 | stdout.write('Enter number from 1 to 10:'); 38 | userInput = int.parse(stdin.readLineSync()); 39 | if (userInput == randomValue) { 40 | isWinner = true; 41 | 42 | print('your are winner'); 43 | } else if (userInput >= randomValue) { 44 | isWinner = false; 45 | print('your input bigger than random nuber'); 46 | } else if (userInput <= randomValue) { 47 | isWinner = false; 48 | print('your input lower than random number'); 49 | } 50 | } while (userInput != randomValue); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /how_many_days_you_live/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program to work out how many days you have lived for. 3 | */ 4 | 5 | import 'dart:io'; 6 | 7 | main() { 8 | final DiffrenceOfAge diffrenceOfAge = DiffrenceOfAge(); 9 | print(diffrenceOfAge.diffrence()); 10 | } 11 | 12 | class DiffrenceOfAge { 13 | var now = DateTime.now(); 14 | final UserDate _userDate = UserDate(); 15 | String diffrence() { 16 | try { 17 | int diffrenceInDay = (now.day - _userDate.userDateDays()); 18 | int diffrenceInMonth = (now.month - _userDate.userDateMonthe()) * 30; 19 | int diffrenceInYears = (now.year - _userDate.userDateYear()) * 365; 20 | return 'difference in day is ${diffrenceInDay + diffrenceInMonth + diffrenceInYears}'; 21 | } catch (e) { 22 | return 'please enter your age in in math not in alphabet'; 23 | } 24 | } 25 | } 26 | 27 | class UserDate { 28 | int userDateDays() { 29 | try { 30 | stdout.write('Enter day that you birth in: '); 31 | int dayFromUserAge = int.parse(stdin.readLineSync()); 32 | return dayFromUserAge; 33 | } catch (e) { 34 | return null; 35 | } 36 | } 37 | 38 | int userDateMonthe() { 39 | try { 40 | stdout.write('Enter month that you birth in: '); 41 | int monthFromUserAge = int.parse(stdin.readLineSync()); 42 | return monthFromUserAge; 43 | } catch (e) { 44 | return null; 45 | } 46 | } 47 | 48 | int userDateYear() { 49 | try { 50 | stdout.write('Enter year that you birth in: '); 51 | int yearFromUserAge = int.parse(stdin.readLineSync()); 52 | return yearFromUserAge; 53 | } catch (e) { 54 | return null; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /insertion_sort/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | insertion sort algorithem 3 | [54, 23, 48, 61, 14, 31, 77, 98, 79, 100, 21] 4 | */ 5 | import 'dart:io'; 6 | 7 | final Insertion insertion = Insertion(); 8 | 9 | main() => insertion.insertionSort(); 10 | 11 | class Insertion { 12 | List array = [54, 23, 48, 61, 14, 31, 77, 98, 79, 100, 21]; 13 | int key, j, i; 14 | void insertionSort() { 15 | for (j = 1; j < array.length; j++) { 16 | key = array[j]; 17 | i = j - 1; 18 | while (i >= 0 && array[i] > key) { 19 | array[i + 1] = array[i]; 20 | i = i - 1; 21 | array[i + 1] = key; 22 | } 23 | } 24 | stdout.write(array); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /joke_game/main.dart: -------------------------------------------------------------------------------- 1 | /// Write a program that will display a joke Don’t display the punchline until the reader hits the enter key. 2 | /// Extension display the punchline in a different colour 3 | 4 | /// algorithem 5 | /// 1.create list form jocks 6 | /// 2.create random number 7 | /// 3.take user input 8 | /// 4.if user hit enter print joks by random[using index] 9 | import 'dart:io'; 10 | import 'dart:math'; 11 | 12 | main() { 13 | TakeUserInput takeUserInput = TakeUserInput(); 14 | JockerDetermener jockerDetermener = JockerDetermener(); 15 | String inputFromUser = takeUserInput.takeUserInput(); 16 | jockerDetermener.determenation(inputFromUser); 17 | } 18 | 19 | class TakeUserInput { 20 | String takeUserInput() { 21 | stdout.write('Enter y: '); 22 | String input = stdin.readLineSync(); 23 | return input; 24 | } 25 | } 26 | 27 | class ListOfJocks { 28 | List listOfJocks = [ 29 | '0', 30 | '1', 31 | '2', 32 | '3', 33 | '4', 34 | '5', 35 | '6', 36 | '8', 37 | '9', 38 | '10', 39 | '11', 40 | '12', 41 | '13', 42 | '14', 43 | '15', 44 | '16', 45 | '17', 46 | '18', 47 | '19', 48 | '20' 49 | ]; 50 | } 51 | 52 | class JockerDetermener { 53 | ListOfJocks _listOfJocks = ListOfJocks(); 54 | ColorsState _colorsState = ColorsState(); 55 | CreatRanomNumber _creatRanomNumber = CreatRanomNumber(); 56 | void determenation(String takeUserInput) { 57 | if (takeUserInput == 'y') { 58 | print( 59 | '${_listOfJocks.listOfJocks[_creatRanomNumber.randomNumbervalue.toInt()]} and color is ${_colorsState.listOfColor[_creatRanomNumber.randomNumbervalueToColor.toInt()]}'); 60 | } else { 61 | print('you shoud press y then enter to see a jock'); 62 | } 63 | } 64 | } 65 | 66 | class ColorsState { 67 | List listOfColor = [ 68 | 'red', 69 | 'blue', 70 | 'purple', 71 | 'green', 72 | ]; 73 | } 74 | 75 | class CreatRanomNumber { 76 | static ListOfJocks _listOfJocks = ListOfJocks(); 77 | static ColorsState _colorsState = ColorsState(); 78 | static Random _randomNumber = Random(); 79 | int randomNumbervalue = 80 | _randomNumber.nextInt(_listOfJocks.listOfJocks.length); 81 | int randomNumbervalueToColor = 82 | _randomNumber.nextInt(_colorsState.listOfColor.length); 83 | } 84 | -------------------------------------------------------------------------------- /logical_gate/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program that will give the 3 | students the answer to logic gate 4 | questions e.g. 5 | Enter logic gate : OR 6 | Enter first input : 1 7 | Enter second input :0 8 | Result = 1 9 | */ 10 | import 'dart:io'; 11 | 12 | final LogicGate logicGate = LogicGate(); 13 | main() { 14 | logicGate.logicGate(); 15 | } 16 | 17 | class LogicGate { 18 | String userInput; 19 | OR _or = OR(); 20 | void logicGate() { 21 | stdout.write('Enter Name Of Gate: '); 22 | userInput = stdin.readLineSync(); 23 | switch (userInput) { 24 | case 'OR': 25 | { 26 | _or.orChecker(); 27 | } 28 | break; 29 | case 'AND': 30 | { 31 | _or.orChecker(); 32 | } 33 | break; 34 | default: 35 | { 36 | print('we have or & $userInput well come soon'); 37 | } 38 | break; 39 | } 40 | } 41 | } 42 | 43 | class OR { 44 | int orOne; 45 | int orTwo; 46 | void orChecker() { 47 | try { 48 | stdout.write('Enter First number: '); 49 | orOne = int.parse(stdin.readLineSync()); 50 | stdout.write('Enter Second number: '); 51 | orTwo = int.parse(stdin.readLineSync()); 52 | if ((orOne == 1 || orOne == 0) && (orTwo == 1 || orTwo == 0)) { 53 | orLogic(); 54 | } else { 55 | stdout.write('1,0 only are available'); 56 | } 57 | } catch (e) { 58 | stdout.write('1,0 only are available'); 59 | } 60 | } 61 | 62 | orLogic() { 63 | orOne + orTwo >= 1 ? print(1) : print(0); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /love_game/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | create app that tell how much i love things 3 | e.g. 4 | Enter name of something: 5 | my wife 6 | your love to your wife is 30% 7 | */ 8 | 9 | import 'dart:io'; 10 | import 'dart:math'; 11 | 12 | final RandomGenerator randomGenerator = RandomGenerator(); 13 | main() => randomGenerator.randomLove(); 14 | 15 | class RandomGenerator { 16 | String userInput; 17 | Random random = Random(); 18 | int randomValue; 19 | void randomLove() { 20 | stdout.write('Enter name of something: '); 21 | userInput = stdin.readLineSync(); 22 | randomValue = random.nextInt(100); 23 | if (randomValue >= 80 && randomValue <= 100) { 24 | messegeToUser(userInput, randomValue, 'too height'); 25 | } else if (randomValue >= 50 && randomValue < 80) { 26 | messegeToUser(userInput, randomValue, 'height'); 27 | } else if (randomValue >= 30 && randomValue < 50) { 28 | messegeToUser(userInput, randomValue, 'low'); 29 | } else if (randomValue >= 10 && randomValue < 30) { 30 | messegeToUser(userInput, randomValue, 'too low'); 31 | } else if (randomValue >= 0 && randomValue < 10) { 32 | messegeToUser(userInput, randomValue, 'very bad'); 33 | } 34 | } 35 | 36 | void messegeToUser(String userInputValue, randomValueValue, valueOfLove) { 37 | print( 38 | 'your love to $userInputValue is $randomValueValue%\nthis mean your love is $valueOfLove'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /rectangle_area_and_circumference/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program to work out the areas and circumference of a rectangle. 3 | Collect the width and height of the rectangle from the keyboard 4 | Calculate the area 5 | display the result. 6 | 7 | Extension 8 | See what happens when you 9 | don't type in numbers! - Try 10 | to explain what has happened and why 11 | */ 12 | 13 | import 'dart:io'; 14 | 15 | main() { 16 | final TakeUserInputToHeitght takeUserInputToHeitght = 17 | TakeUserInputToHeitght(); 18 | final TakeUserInputToWidth takeUserInputToWidth = TakeUserInputToWidth(); 19 | final RectangleCalculator rectangleArea = RectangleCalculator( 20 | height: takeUserInputToHeitght.takeUserInput(), 21 | width: takeUserInputToWidth.takeUserInput(), 22 | ); 23 | 24 | print(rectangleArea.rectangelCalculator()); 25 | } 26 | 27 | class TakeUserInputToHeitght { 28 | int takeUserInput() { 29 | stdout.write('enter height: '); 30 | String height = stdin.readLineSync(); 31 | try { 32 | int heightValueInInteger = int.parse(height); 33 | return heightValueInInteger; 34 | } catch (e) { 35 | print('please enter number'); 36 | return null; 37 | } 38 | } 39 | } 40 | 41 | class TakeUserInputToWidth { 42 | int takeUserInput() { 43 | stdout.write('enter width: '); 44 | String width = stdin.readLineSync(); 45 | try { 46 | int widthValueInInteger = int.parse(width); 47 | return widthValueInInteger; 48 | } catch (e) { 49 | print('please enter number'); 50 | return null; 51 | } 52 | } 53 | } 54 | 55 | class RectangleCalculator { 56 | int height; 57 | int width; 58 | RectangleCalculator({this.height, this.width}); 59 | String rectangelCalculator() { 60 | try { 61 | int area = height * width; 62 | int circumference = (2 * height) + (2 * width); 63 | return ''' 64 | Rectangle area is $area, 65 | Rectangle circumference is $circumference, 66 | '''; 67 | } catch (e) { 68 | return 'please rerun app again'; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /rock_paper_scissors/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'dart:math'; 3 | 4 | main() { 5 | GameViewModel game = GameViewModel(); 6 | game.computerGuess(); 7 | } 8 | 9 | abstract class Options { 10 | List options = ['r', 'p', 's']; 11 | Random random = Random(); 12 | } 13 | 14 | class GameViewModel extends Options { 15 | String userInput; 16 | void computerGuess() { 17 | do { 18 | print('enter your guess'); 19 | String computer = options[random.nextInt(options.length)]; 20 | userInput = stdin.readLineSync(); 21 | if (computer == userInput) { 22 | print('you are right'); 23 | } else { 24 | print('computer guess is $computer'); 25 | } 26 | } while (userInput != 'exit'); 27 | print('game end'); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /rock_paper_scissors_guess/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Make a game of rock, paper scissors against the computer. 3 | Extension 4 | Make sure the user enters a valid entry. 5 | */ 6 | import 'dart:io'; 7 | import 'dart:math'; 8 | 9 | final GameCore gameCore = GameCore(); 10 | main() { 11 | gameCore.core(); 12 | } 13 | 14 | class GameCore { 15 | static List options = [ 16 | 'rock', //0 17 | 'paper', //1 18 | 'scissors', //2 19 | ]; 20 | static int random = Random().nextInt(2); 21 | String optionInActoin = '${options[random]}'; 22 | String userInput; 23 | void core() { 24 | stdout.write('Enter rock or paper or scissors: '); 25 | userInput = stdin.readLineSync(); 26 | if (userInput == 'rock' || 27 | userInput == 'paper' || 28 | userInput == 'scissors') { 29 | if (userInput == optionInActoin) { 30 | stdout.write('your are winner 🎉'); 31 | } else { 32 | stdout.write('yor are losser'); 33 | } 34 | } else { 35 | print('please enter rock & paper & scissors'); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /say_hello/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | /// write a programm that take user name and say wellcome + user name 4 | 5 | final TakeUserName takeUserName = TakeUserName(); 6 | main() { 7 | takeUserName.takeUserName(); 8 | } 9 | 10 | class TakeUserName { 11 | void takeUserName() { 12 | stdout.write('Enter your name: '); 13 | String username = stdin.readLineSync(); 14 | print('hello, ' + username); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /shap_draw/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program that uses only two output statements, cout << "#" and cout << "\n", to produce a 3 | pattern of hash symbols shaped like half of a perfect 5 × 5 square (or a right triangle): 4 | ##### 5 | #### 6 | ### 7 | ## 8 | # 9 | */ 10 | import 'dart:io'; 11 | 12 | main() { 13 | rectangleDraw(); 14 | } 15 | void rectangleDraw() { 16 | for (int row = 0; row < 5; row++) { 17 | for (int hash = 0; hash < 5- row; hash++) { 18 | stdout.write('#'); 19 | } 20 | stdout.write('\n'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /square_shap/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program that uses only two output statements, cout << "#" and cout << "\n", to produce a 3 | pattern of hash symbols shaped like a perfect 5x5 square: 4 | ##### 5 | ##### 6 | ##### 7 | ##### 8 | ##### 9 | */ 10 | 11 | import 'dart:io'; 12 | 13 | main() { 14 | for (int row = 0; row < 5; row++) { 15 | for (int index = 0; index < 5; index++) { 16 | stdout.write('#'); 17 | } 18 | 19 | stdout.write('\n'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /stack/stack.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | class Stack { 4 | final ListQueue _stack = ListQueue(); 5 | bool get isEmptyStack => _stack.isEmpty; 6 | bool get isNotEptyStack => _stack.isNotEmpty; 7 | ListQueue get stackValue => _stack; 8 | 9 | void push(T element) { 10 | _stack.addLast(element); 11 | } 12 | 13 | T pop() { 14 | T item = _stack.last; 15 | _stack.removeLast(); 16 | return item; 17 | } 18 | 19 | T top() { 20 | return _stack.last; 21 | } 22 | 23 | int size() { 24 | return _stack.length; 25 | } 26 | } 27 | 28 | main() { 29 | Stack stack = Stack(); 30 | stack.push('h'); 31 | stack.push('o'); 32 | stack.push('o'); 33 | stack.pop(); 34 | stack.push('s'); 35 | stack.push('s'); 36 | stack.push('a'); 37 | stack.push('m'); 38 | print(stack.size().toString()); 39 | print(stack.stackValue); 40 | } 41 | -------------------------------------------------------------------------------- /star_art/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a procedure(sub) drawstars that will draw a sequence of 3 | spaces followed by a sequence of stars. It should accept two parameters—the number of spaces and the number of stars. 4 | E.g 5 | Drawstars(3,5) would produce 6 | _ _ _ * * * * * ( _ indicates a space!) 7 | Use your procedure to draw 8 | * 9 | * * * 10 | * * * 11 | * 12 | * * * 13 | * * * * * * * 14 | * * * 15 | * * 16 | * * * * 17 | 18 | */ 19 | 20 | import 'dart:io'; 21 | 22 | main() { 23 | final DrawCustomShap drawCustomShap = DrawCustomShap(); 24 | drawCustomShap.customShap(); 25 | } 26 | 27 | class DrawCustomShap { 28 | final DrawStars draw = DrawStars(); 29 | void customShap() { 30 | draw.stars(spacesValue: 3, starsValue: 1); 31 | draw.stars(spacesValue: 2, starsValue: 3); 32 | draw.stars(spacesValue: 2, starsValue: 3); 33 | draw.stars(spacesValue: 3, starsValue: 1); 34 | draw.stars(spacesValue: 2, starsValue: 3); 35 | draw.stars(spacesValue: 0, starsValue: 7); 36 | draw.stars(spacesValue: 2, starsValue: 2); 37 | draw.stars(spacesValue: 1, starsValue: 4); 38 | } 39 | } 40 | 41 | class DrawStars { 42 | stars({int spacesValue, starsValue}) { 43 | for (int spaces = 0; spaces < spacesValue; spaces++) { 44 | stdout.write(' '); 45 | } 46 | for (int stars = 0; stars < starsValue; stars++) { 47 | stdout.write(' *'); 48 | } 49 | stdout.write('\n'); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /sum/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | creat app that take user input and sum from 1 to user input 3 | */ 4 | import 'dart:io'; 5 | 6 | main(){ 7 | final RunSum _runSum = RunSum(); 8 | _runSum.run(); 9 | } 10 | 11 | class RunSum{ 12 | String stringInput; 13 | double doubleInput; 14 | SumNumbers _sum = SumNumbers(); 15 | void run(){ 16 | stringInput = stdin.readLineSync(); 17 | doubleInput = double.parse(stringInput); 18 | print(_sum.sumIt(doubleInput)); 19 | } 20 | } 21 | 22 | class SumNumbers{ 23 | double sumIt(double userInput){ 24 | return userInput * ( userInput + 1 )/2; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /timer_guess/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Challenge 6 3 | 4 | Make a game for seeing how good people are at 5 | guessing when 10 seconds have elapsed. 6 | 7 | Algorithm 8 | Tell them to hit enter key when ready 9 | Get the first time in seconds 10 | Get them to hit the enter key when they think time has elapsed 11 | Get the second time in seconds 12 | Subtract first time from the second time 13 | Tell them how close to 10 the answer was. 14 | 15 | Extension 16 | Sometimes this solution doesn't 17 | work. Can you work out why it 18 | doesn’t work? Can you fix it? 19 | 20 | Prior Knowledge Needed 21 | How to create variables 22 | How to input data into a variable 23 | How to display variables 24 | How to use system functions. 25 | How to use system variables 26 | */ 27 | 28 | import 'dart:io'; 29 | 30 | main() { 31 | final Switcher switcher = Switcher(); 32 | switcher.switcher(); 33 | } 34 | 35 | class Switcher { 36 | String userInput; 37 | final TimerByFuture timerByFuture = TimerByFuture(); 38 | void switcher() { 39 | try { 40 | stdout.write('Enter y to start: '); 41 | userInput = stdin.readLineSync(); 42 | } catch (e) { 43 | print('please enter y only and re run app again'); 44 | } 45 | switch (userInput) { 46 | case 'y': 47 | { 48 | timerByFuture.timer(); 49 | } 50 | break; 51 | default: 52 | { 53 | print('rerun app again and enter y'); 54 | } 55 | break; 56 | } 57 | } 58 | } 59 | 60 | class TimerByFuture { 61 | int _timeInSeconds = 10; 62 | void timer() { 63 | Future.delayed(Duration(seconds: _timeInSeconds), () { 64 | print('time finshed'); 65 | }); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /translator_game/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | make a translation app that translate all user input by convert all 3 | c letters to a letter 4 | */ 5 | import 'dart:io'; 6 | 7 | final Translator translator = Translator(); 8 | main() => translator.translate(); 9 | 10 | class Translator { 11 | String userInput; 12 | void translate() { 13 | stdout.write('Enter sentence to translate: '); 14 | userInput = stdin.readLineSync(); 15 | userInput.split('').forEach((character) { 16 | if (character == 'o') { 17 | character = 'c'; 18 | } 19 | stdout.write(character); 20 | }); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /triangle_star/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program that uses only two output statements, cout << "#" and cout << "\n", to produce a 3 | pattern of hash symbols shaped like a sideways triangle: 4 | * 5 | * * 6 | * * * 7 | * * * * 8 | * * * * * 9 | */ 10 | import 'dart:io'; 11 | 12 | main() { 13 | final MirrorTriangle mirrorTriangle = MirrorTriangle(); 14 | mirrorTriangle.mirrorTriangle(); 15 | } 16 | 17 | class MirrorTriangle { 18 | int numberOfSpaces; 19 | int number = 10; 20 | void mirrorTriangle() { 21 | numberOfSpaces = 2 * number - 2; 22 | for (int row = 0; row < number; row++) { 23 | for (int spaceController = 0; 24 | spaceController < numberOfSpaces; 25 | spaceController++) { 26 | stdout.write(' '); 27 | numberOfSpaces = numberOfSpaces - 2; 28 | for (int column = 0; column <= row; column++) { 29 | stdout.write('#'); 30 | } 31 | stdout.write('\n'); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vote_determiner/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program that will accept someone’s date of birth and 3 | work out whether they can vote (i.e. Are they 18?) 4 | */ 5 | 6 | import 'dart:io'; 7 | 8 | main() { 9 | final VoteDeterminer voteDeterminer = VoteDeterminer(); 10 | voteDeterminer.voteDeterminer(); 11 | } 12 | 13 | class VoteDeterminer { 14 | int age; 15 | void voteDeterminer() { 16 | stdout.write('Enter yor age: '); 17 | age = int.parse(stdin.readLineSync()); 18 | if (age >= 18) { 19 | print('You can to Vote'); 20 | } else { 21 | print('you are small'); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /words_count/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program to count the number of words in a sentence. 3 | The user enters a sentence. 4 | The program responds with the number of words in the sentence. 5 | */ 6 | import 'dart:io'; 7 | 8 | main() { 9 | final WordCounter wordCounter = WordCounter(); 10 | wordCounter.counter(); 11 | } 12 | 13 | class WordCounter { 14 | String userInput; 15 | List arrayOfStrings = []; 16 | 17 | void counter() { 18 | print('Enter "y" to exit'); 19 | do { 20 | stdout.write('Enter word to count it:'); 21 | userInput = stdin.readLineSync(); 22 | arrayOfStrings.add(userInput); 23 | } while (userInput != 'y'); 24 | print(arrayOfStrings.length - 1); 25 | } 26 | } 27 | --------------------------------------------------------------------------------