Hogwarts Zits: Console App

Building this console app was so challenging to me, especially, since I am just a beginner, who knows little or nothing about Darts or how to build a Console App. I watched lots of videos on YouTube about Darts for beginners to understand what I was meant to do and also reached out to my friend who is also learning with me so we could share ideas together on how to go about, it wasn't an easy feat but I was glad that at the end I was able to get my desired result.

The Assignment

Build Hogwarts Zitz: A console app that prompts user to insert:

  • Name

  • Age

  • Favourite color

  • One Unique trait

  • Print these values to the user and tell them what Harry Potter's house they belong to.

  • Write an article detailing your steps

Procedure:

  1. I imported dart:io by typing, import dart:io which is a library that allows you to work with files, directories, sockets, processes, HTTP servers and clients, and more. Many operations related to input and output are asynchronous and are handled using [Future]s or [Stream]s, both of which are defined in the dart:async library.

  2. Inside the void main, I started with my code where I listed out the colors I'm using and I wrapped them in a List. The code should look like this; List<String> houseColor = ['green', 'red', 'blue', 'Yellow'];

  3. Then I inputted stdout.write(kindly, enter your name here/n'); The stdout means standard output and it organizes the line of code in the console, it is from the dart.io file.

  4. To make this work, the stdin.readLineSync is used. Stdin means standard input and it works hand in hand with readLineSync to return a string. Hence, the code should look like this; String name = (stdin.readLineSync()!);

  5. I used same method in inputting that of age. But , instead of stdin.readLineSync, I use; int age = int.parse(stdin.readLineSync()!); int.parse is used to convert the string and it passes into an integer.

  6. I continued the same process I used in inputting name, for both inputting favorite color and unique trait because both are string values.

  7. After inputting name, age, color and unique trait, I used colors to assign the SWITCH and CASE statements to the different houses of Hogswart which are; Ravenclaw, Slytherin, Hufflepuff, Gryffindor .

  8. At the end i use print ('Your name is $name; You are $age years; Your favorite color is $color; Your unique trait is $trait'); to print out the user values for name, age, favorite color and unique trait.

  9. I also added the default print('invalid house') incase someone puts a color that is not among the four colors used when writing this code it will come back as an invalid house.

Below is the code


Import  'dart: io';
Void main ( ) {

// Asking the user to input their name

 List<String> houseColor = [ 'green', 'red', 'blue', 'yellow'];
ardour write ( 'kindly, enter your name here/n');
String name =stdin.readLineSync()!;

// Asking for their age 

stdout.write(' how old are you?/n');
int age = int.parse(stdin.readLineSync()!);

// Asking for their favourite color

 stdout.write(' what is your favourite color /n');
String color =stdin.readLineSync()!;

// Asking for their unique trait 

stdout.write(' what is your unique trait /n');
String trait =stdin.readLineSync()!;

// Assigning the switch and case statement to each of the house 

switch (color) {
case 'green' :
print('you are in Ravenclaw house');
break;

case 'red' :
print('you are in Slytherin house'); 
break;

case 'blue' :
print ('you are in Hufflepuff house');

case 'yellow' :
print ('you are in Gryffindor');

default:
print ('invalid house');
}
print('Your name is $name; You are $age years; Your favourite color is $color; Your unique trait is $trait');

}
1
Subscribe to my newsletter

Read articles from Achu Ijeoma Cynthia directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Achu Ijeoma Cynthia
Achu Ijeoma Cynthia

Hello, and welcome to my blog! I'm Ijeoma Achu, a passionate and dedicated mobile app developer with expertise in Dart, Git and Github, Flutter, and Firebase. What sets me apart is not just my technical skills, but also my unique journey into the world of technology. I began my professional journey in the field of dental technology, where precision and attention to detail were paramount. While I enjoyed the challenges it presented, my curiosity for technology and innovation led me to explore new horizons. Driven by a deep-seated passion for mobile app development, I embarked on a transformative career transition to pursue my true calling.