Landing : Athabascau University

Assignment 2 reflections

  • Public
By Osamah Sadeq August 28, 2022 - 7:03pm

 

Problem 1 reflection  

In this program, we were supposed to create a program for animals that makes a sound based on the animal that it is. A java program that will display 4 animals to choose from. Once the user chooses one animal, it should display, "I am an animal", and then the name of the animal as selected, then the sound of it. Once the user chooses an animal from the list, "pig", "sheep", "duck", "cow", it should make a sound based on the animal that it is. For example, if the user selects a cow, then a display shows "I am an animal", "I am a cow", "mooo". If the user selects a choice that is not in the program, then it will display "Please Enter Correct Choice!". I started the code by importing the util package to use a scanner class. And the Animal class, where the default constructor was defined, as well as a method called sound(). For the rest of the classes, a default constructor was also defined with a statement printed to the output. Overall, I liked working on this problem, it was easy.  

 

 

Problem 2 reflection  

In this program, we were supposed to create a program that will display a book with attributes, such as the title, ISBN number, author, editor, publisher, and year of publication. The program will display without entering anything into the output. The program will display 3 books with their attributes. I started the program with the class name, then private attributes, then followed by 6 public getters, as well as 6 public setters. After that, the main method got involved. After that create the 3-book information and print their info to the output. I spent a good time on this problem getting real info about the 3 books, such as title, ISBN number, author, editor, publisher, and year of publication. This problem was easy and fair enough. It was fun collecting the information about the 3 books.  

 

 

Problem 3 reflection 

In this program, we are creating an Elevator that can be moved between floors in an N-Storey building. The program will display an elevator system. Once the user runs the program; a display of an elevator system will run. The elevator will be on floor 1 until number 6 is pressed, once number 6 is pressed, the elevator will start going up until it reaches floor 6, and it will say "Elevator is currently at floor 6". After that, number 4 is pressed, and the elevator will be going down starting from floor 6 until floor 4. Once the elevator reaches floor 4, it will display "Elevator is currently at floor 4". If no one enters any number, it will display " Elevator is waiting on floor 4". If the user enters a number that is not in the system, it will say "Apologies, Please Note That This Is An Invalid Floor Number. There are Only 20 Floors in This Building" or "Please select a valid floor number." Lastly, the elevator will return to the first floor. I started this program by the name of the class, then declared a private variable. As well as a parameter constructor. I used an if statement in my code which is used to say when the floor number is less than the current floor, then display a message that the elevator is at the current floor. And the other way around when the floor number is greater or equal to the floor number. I also used null, because I wanted to make the elevator object null to show the elevator’s finalized method. I liked working on this problem.  

 

 

Problem 4 reflection 

In this program, we are creating an inheritance hierarchy of Rodent: mouse, gerbil, hamster, guinea pig. We must display 4 animals; each animal must have 4 behaviours in the display. For example, a mouse can eat worms, a mouse can run, a mouse can sleep, a mouse can groom. I started the code with a parent rodent class. Also, in a child class of rodents, this statement was used for every animal. Followed by the main method, as well as a mouse object and test method rodent[0] = new Mouse();. The program overall was easy, but it took me a bit of time.  

 

 

Problem 5 reflections.  

In this program, we are creating a point class to hold x and y values for a point. And create methods show(), add() and subtract() to display the Point x and y values, and add and subtract point coordinates. A display sill shows up with length and width values. These values will be calculated for squares and circles. For example, if the length of something is 10 and the width of it is 10, once we convert it to a square, it will show the calculations. Same thing with circles. I have started the code by creating a point class with variables and methods. As well as a shape class with a method. Also, creating a circle class with points pnt and radius. Followed by creating a triangle class, then calculating the side of the triangle. The same thing happened when we calculated the area and rectangle. Finally, I added the main method plus the “MyShapeDemo” class. This problem took a lot of my time, it was a bit challenging for me as I had lots of errors, and I had to do some research to be able to fix those errors. 

Comments

These comments are moderated. Your comment will not be visible unless accepted by the content owner.

Only simple HTML formatting is allowed and any hyperlinks will be stripped away. If you need to include a URL then please simply type it so that users can copy and paste it if needed.

(Required)

(Required)