Posts

inputReader.js (***REVISE nice question)

Image
  /** * Input reader -- Classes Practice Problems Write an InputReader class that can read n strings/integers/floats. InputReader should have 3 methods: readStrings, readIntegers, readFloats. Each of these methods should take n as parameter and read n number of inputs, print them, one on each line, prepended with the index number of inputs taken, starting from 0, like indexes in an array. The index and the element should be space separated. For floats, the output should be rounded to 2 decimal places only. Inputs are handled by the template. You need to implement the methods readStrings, readIntegers, readFloats inside the InputReader class. Input First line contains an integer n, 0 < n <= 100. Second line contains a string which indicates the type of the array: string, integer, float. This is followed by n lines. Each line contains one element which could be string/integer/float based on the second line. Output The output should contain n lines. Each line contains...

robotMovement.js

Image
  /** * Robot Movement -- Classes Practice Problems You have recently designed a robot and you are trying to write code to make it move over a 2-D plane. Please initialize your robot to always start at the origin (0,0). Design a class which has 4 methods moveUp -- Takes one step along the +ve Y axis. moveDown -- Takes one step along the -ve Y axis. moveRight -- Takes one step along the +ve X axis. moveLeft -- Takes one step along the -ve X axis. The directions to move will be provided to you as follows up -- Move up down -- Move down right -- Move right left -- Move left Your class should have an instance variable location which contains the present location of your robot. Print the location of your robot after taking m steps. Input First line contains an integer which specifies how many steps to take which is m followed by m lines each specifying the direction to move. Ex.. up which means take 1 step in up direction. Output Two lines specifying the final location of the Robo...

rectangle.js

Image
  /** * area and perimeter of rectangle -- Classes Practice Problems Design a class which has 2 methods. One which computes the Area of the Rectangle. The other computes the Perimeter of the Rectangle. You should be able to pass the length l and width w while creating the object for the class. For all infeasible values of length l and width w, print area and perimeter as 0 Your class should be named as Rectangle. Method to get area should be named as rectangle_area. Method to get perimeter should be named as rectangle_perimeter. Input First line contains an integer for the length l Second line contains an integer for the width w Output Two lines containing integers. First line containing the Area of the Rectangle Second line containing the Perimeter of the Rectangle Example Input: 3 2 Output: 6 10 First line is 3 representing the length. Second line is 2 representing the width. Area is 3*2 which is 6 as represented in the first line of the output. Perimeter is 2*(3 + 2) whic...

movie.js

Image
  /** * Print Movie Description -- Classes Practice Problems Write a Movie class for which you can create movie objects. The objects should have the following variables: integer length_in_minutes, integer num_characters, string language. Each object should also have a run method which prints out: "This is a movie with characters and is minutes long." Input First line is a string, denoting the language of the movie Second line is an integer, denoting the number of characters Third line is an integer, denoting the length in minutes Output The output should be the return statement of run: "This is a movie with characters and is minutes long." Example Input: French 4 200 Output: This is a French movie with 4 characters and is 200 minutes long. First line is French indicating the movie's language is French Second line is 4, indicating that the movie has 4 characters Third line is 200, indicating that the movie is 200 minutes long */ let fs = require ( ...

circle.js

Image
  /** * Area and Perimeter of the Circle - Classes Practice Problems Design a Circle class which has 2 methods. One which calculates area of the circle and one which calculates circumference of the circle. Please use the pi value as 3.14. For any infeasible radius r, please return the area and circumference as 0 Your class should be named Circle. Method to get area should be named getArea. Method to get circumference should be named getCircumference. Input One line containing an integer denoting the radius. Output 2 lines containing integers. First line containing the area of the circle. Second line containing the circumference of the circle. If the output is a float number, return the ceil of it. Example Input: 5 Output: 79 32 First line in input is radius which is 5. Area is 5*5*3.14 which is ceil(78.5) = 79, which is the first line of the output. Circumference is 2*3.14*5 which is ceil(31.40) = 32, which is the second line of the output. */ let fs = require ( "fs" ...

Private (#) attributes/ properties inside a function

Image
 

All about spread operator

Image
 1) 2) 3) 4)