Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 15

// Create a class Person that has properties name and age.

Create an instance of
this class and print out its properties.

// class Person{
// constructor(name, age){
// this.name = name;
// this.age = age;
// }
// }

// let person1 = new Person("Prashant", 22)


// console.log(person1)

// Create a class Rectangle that has properties width and height. Add a method
getArea() that calculates the area of the rectangle. Create an instance of this
class and call the getArea() method.

// class Rectangle{
// constructor(width,height){
// this.wid = width;
// this.hgt = height;
// }

// getValues(){
// console.log("the area of rectangle is : " + this.wid * this.hgt)
// }
// }

// const area = new Rectangle(12,12)


// area.getValues();

//Create a class Animal that has properties name and species. Add a method speak()
that prints out a message saying "The {name} is a {species} and says {sound}".
Create an instance of this class and call the speak() method.

// class Animal{
// constructor(animal_name, animal_species,sound){
// this.name = animal_name;
// this.species = animal_species;
// this.sound = sound
// }

// speak(){
// console.log("The " + this.name + " is a " + this.species + " and it " +
this.sound)
// }
// }

// const dog = new Animal("dog", "husky", "barks")


// dog.speak()

//Create a class Employee that has properties name, position, and salary. Add a
method raiseSalary(percent) that increases the salary by the given percentage.
Create an instance of this class and call the raiseSalary() method with a
percentage of your choice.

// class Employee{
// constructor(name, position, salary){
// this.name = name;
// this.position = position;
// this.salary = salary;
// }

// raiseSalary(percent){
// this.salary = (this.salary * percent/100)
// console.log("The salary is raised by :" + this.salary)
// }
// }

// const employee1 = new Employee('Prashant Deshpande','Software Developer', 50000)

// employee1.raiseSalary(7);

//Create a class Car that has properties make, model, and year. Add a method
getAge() that calculates the age of the car based on the current year. Create an
instance of this class and call the getAge() method.

// class Car {
// constructor(make, modal, year){
// this.company = make;
// this.modal = modal;
// this.year = year
// }

// getAge(){
// const currentYear = new Date().getFullYear();
// const carAge = currentYear - this.year;
// return ` car is ${carAge} year old`
// }
// }

// const car1 = new Car("Ford","Mustang",2014)


// console.log(car1.getAge());

// const car2 = new Car ("bmw","Buggati Chiron", 2000)


// console.log(car2.getAge())

// calculate your age

// class Myage {
// constructor(birthYear,name){
// this.age = birthYear;
// this.name = name;
// }
// getAge(){
// const currentYear = new Date().getFullYear();
// return currentYear - this.age;
// // console.log(this.name + " is " + this.age + " year old")
// }
// }

// const age = new Myage(2002, "Prashant")


// console.log(age.getAge())
//Create a class BankAccount that has properties balance and interestRate. Add a
method deposit(amount) that adds the given amount to the balance. Add a method
withdraw(amount) that subtracts the given amount from the balance. Create an
instance of this class and call the deposit() and withdraw() methods with amounts
of your choice.

// class BankAccount{
// constructor(bal, interestRate){
// this.balance = bal;
// this.interest = interestRate;
// }

// deposite(amount){
// this.balance = this.balance - (this.balance * amount/100);
// }

// withdraw(amt){
// console.log(this.balance)

// }

// }

// const customer = new BankAccount(25000)


// customer.deposite(5);
// customer.withdraw();

//Create a class Book that has properties title, author, and isbn. Add a method
getInfo() that prints out a message saying "The book {title} by {author} has an
ISBN of {isbn}". Create an instance of this class and call the getInfo() method.

// class Book{
// constructor(title, author, price){
// this.title = title;
// this.author = author;
// this.price = price;
// }

// getInfo(){
// console.log("The Book " + this.title + " by " + this.author + " has
price over " + "$" + this.price)
// }
// }

// const book1 = new Book("The Book of Vishanti", "Agamotto",1000)


// console.log(book1.getInfo())

//Create a class Shape that has properties color and type. Add a method draw() that
prints out a message saying "Drawing a {color} {type}". Create a subclass Circle
that has a property radius. Override the draw() method in the Circle class to print
out a message saying "Drawing a {color} circle with a radius of {radius}". Create
an instance of the Circle class and call the draw() method.

// class Shape{
// constructor(color, type){
// this.color = color;
// this.type = type;
// }

// draw(){
// console.log("Drawing a " + this.color + " " + this.type)
// }
// }

// class Circle extends Shape{


// constructor(color,radius){
// super(color)
// this.radius = radius;
// }
// draw(){
// console.log(`drawing a ${this.color} circle with a radius of $
{this.radius}`)
// }

// }

// const circle = new Circle('pruple', 5)


// circle.draw();

//Create a class Player that has properties name, score, and level. Add a method
increaseScore(points) that increases the score by the given number of points. Add a
method increaseLevel() that increases the level by 1. Create an instance of this
class and call the increaseScore() and increaseLevel() methods with values of your
choice.

// class Player{
// constructor(name, score, level){
// this.name = name;
// this.score = score;
// this.level = level;
// }

// increseScore(points){
// this.score += points;
// }

// increaseLevel(){
// this.level++;

// }
// }

// const Russell = new Player("Andre Russell", 100, 1)


// console.log(Russell.score,Russell.level)

// Russell.increaseScore(50);
// console.log(Russell.score)

// Russell.increaseLevel();
// console.log(Russell.level)

//Create a class Movie that has properties title, director, year, and rating. Add a
method getRating() that returns the rating of the movie as a string ("PG", "PG-13",
"R", etc.). Create an instance of this class and call the getRating() method.
// class Movie{
// constructor(title, director, year, rating){
// this.title = title;
// this.director = director;
// this.year = year;
// this.rating = rating;
// }
// getRating(){
// console.log(`The Movie ${this.title} is created by ${this.director} in
the year of ${this.year} it has ${this.rating} rating`)
// }
// }

// const avengers = new Movie("Spider-Man:No Way Home", "Kevin-Feige",2021,"pg-13")


// avengers.getRating();

//
-----------------------------------------------------------------------------------
----

// // 1.create a class that will show the difference between constructor methods
and the instance method in the class.
// class Demo{

// name:string;
// age:number;
// id:number;

// //constructor method
// constructor(name:string,age:number,id:number){
// this.name = name;
// this.age = age;
// this.id = id;
// }

// // instance method
// setDetails(n:string,a:number,id:number){
// this.name = n;
// this.age = a;
// this.id = id;
// }

// getDetails(){
// console.log(this.name + " " + this.age + " " + this.id)
// }
// }

// const newObj = new Demo("Prashant",21,3000)


// // using constructor method
// newObj.getDetails()

// // using instance method


// newObj.setDetails("Tony",40,1)
// newObj.getDetails();
// // 2.Create a BankAccount class with accountNumber, accountHolder, and balance
properties. Add methods deposit and withdraw to the class that update the account
balance accordingly.

// class BankAccount{
// accountNumber:number;
// accountHolder:string;
// balance:number;

// constructor(ac:number,ah:string,bal:number){
// this.accountNumber = ac;
// this.accountHolder = ah;
// this.balance = bal;
// }

// deposit(amount:number){
// this.balance += amount;
// console.log(`Deposited ${amount} Your New Balance is ${this.balance}`)
// }

// withdraw(amount:number){
// if(this.balance >= amount){
// this.balance -= amount;
// console.log(`Withdrawan ${amount} Your New Balance is $
{this.balance}`)
// } else {
// console.log("Insufficient Balance")
// }
// }
// }

// const myAccount = new BankAccount(123654677,"Tony Stark",0)


// myAccount.deposit(1000); // Balance deposited
// myAccount.withdraw(1000); // Balance withdrawn
// myAccount.withdraw(100); // Insufficient Balance

// //3.Create a Vehicle class with make, model, and year properties. Add a method
start to the class that logs a message indicating that the vehicle has started.

// class Vehicle{
// make:string;
// model:string;
// year:number;
// constructor(company:string,id:string,year:number){
// this.make = company;
// this.model = id;
// this.year = year;
// }

// startEngine(){
// console.log(`${this.model} made by ${this.make} in the year of $
{this.year} one of the best racing car`)
// }
// }

// const car = new Vehicle("Bugatti Automobiles S.A.S.","Buggati Chiron",1999)


// car.startEngine();
// //4.Create a Student class with name, age, gender, and grades properties. Add a
method getAverageGrade to the class that returns the average of the student's
grades.

// class Student{
// name:string;
// age:number;
// gender:string;
// grades:number[]

// constructor(name:string,age:number,gender:string,grades:number[]){
// this.name = name;
// this.age = age;
// this.gender = gender;
// this.grades = grades;
// }

// getAverageGrades(){
// let total = this.grades.reduce((sum,grade)=> sum + grade,0)
// let average = total/this.grades.length;
// console.log(Math.floor(average))
// }
// }

// const student = new Student("Prashant",21,"Male",[90,95,82,79,85])


// student.getAverageGrades();

// //5.Create a Book class with title, author, and price properties. Add a method
discount to the class that applies a discount to the book's price.

// class Book{

// title:string;
// price:number;
// constructor(title:string, price:number, ){
// this.title = title;
// this.price = price
// }

// discount(percentage:number){
// let discountAmt = (this.price * percentage)/ 100;
// this.price -= discountAmt;
// console.log("The discount is " + discountAmt)
// }
// }

// const newBook = new Book("The Big F", 1000)


// newBook.discount(50) // 500

// // 6.create class define two properties extend the class and use parent
properties in child class
// class Parent{
// name:string;
// role:string;
// constructor(name:string,role:string){
// this.name = name;
// this.role = role;
// }
// }
// class Child extends Parent{
// age:number;
// id:number;
// constructor(_name:string,_role:string,age:number,id:number){
// super(_name,_role)
// this.age = age;
// this.id = id;
// }
// }

// const childObj = new Child("Prashant","Developer",21,3000)


// console.log(childObj)

// // 7.create a class define person properties like name,age,role etc create a


method can call it.
// class Person{
// name:string;
// age:number;
// gender:string;
// role:string;

// constructor(name:string,age:number,gender:string,role:string){
// this.name = name;
// this.age = age;
// this.gender = gender;
// this.role = role;
// }
// getDetails(){
// console.log(`my name is ${this.name} my age is ${this.age} and I am an $
{this.role}`)
// }
// }

// const newPerson = new Person("Tony",21,"Male","Avenger")


// newPerson.getDetails();

// // 8.Create a class called BankAccount with properties balance and owner. Add
methods deposit and withdraw that update the balance accordingly.
// class BankAccount{

// accountNumber:number;
// accountHolder:string;
// balance:number;

// constructor(ac:number,ah:string,bal:number){
// this.accountNumber = ac;
// this.accountHolder = ah;
// this.balance = bal;

// }

// deposit(amount:number){
// this.balance += amount;
// console.log(`Deposited ${amount} New Balance is ${this.balance}`)
// }

// withdraw(amount:number){
// if(this.balance >= amount){
// this.balance -= amount;
// console.log(`withdrawn ${amount} New Balance is ${this.balance}`)
// }else{
// console.log("Insufficient Balance")
// }

// }
// }

// const myAccount = new BankAccount(1235432345,"Tony Stark",0);

// myAccount.deposit(5000);
// myAccount.withdraw(500) // Balance deposited
// // myAccount.withdraw(1000); // Balance withdrawn
// // myAccount.withdraw(100); // Insufficient Balance

// // 9.create an bank class and add the account holders details and get the all
details for creating new bank account.
// class Bank{
// bankname:string;
// branch:string;
// accountType:string;
// accountnumber:number;
// accountHolder:string;
// constructor(bn:string,brc:string,at:string,ac:number,user:string){
// this.bankname = bn
// this.branch = brc;
// this.accountType = at;
// this.accountnumber = ac;
// this.accountHolder = user;

// }
// getDetails(){
// console.log(`Bank Name : ${this.bankname}`)
// console.log(`Account Holder: ${this.accountHolder}`)
// console.log(`Account Number: ${this.accountnumber}`)
// console.log(`Account Type : ${this.accountType}`)
// console.log(`Branch : ${this.branch}`)

// }
// }

// const openAccount = new Bank("State Bank of


India","Udgir","Savings",123456789,"Tony Stark")
// openAccount.getDetails();

// // 10. Create a class Person that has properties name and age. Create an
instance of this class and print out its properties.

// class Sample{
// readonly name:string;
// private id:number;
// protected loacation :string;
// constructor(name:string,id:number,loc:string){
// this.name = name;
// this.id = id;
// this.loacation = loc;
// }

// getDetails(){
// console.log(`My name is ${this.name} My id is ${this.id} I live in $
{this.loacation}`)
// }
// }
// class Demo extends Sample{
// getDetails1(){
// console.log(this.loacation)
// }
// }
// const newObj = new Sample("Prashant",10,"Udgir")
// newObj.getDetails();
// newObj.name = "tony"
// newObj.id = 12;
// newObj.getDetails1()

//---------------------------------------------------------------------------------
------------------------

//1. Create a class called car with properties make, model, and year and add them
in a start() method.
//Create a class called SportsCar that inherits from Car and adds a property
horsepower.
//Override the start method to include the car's horsepower in the message.

// class Car {
// make:string;
// model:string;
// year:number;
// constructor(company:string,id:string,year:number){
// this.make = company;
// this.model = id;
// this.year = year;
// }
// start(){
// console.log(`${this.model} made by ${this.make} in the year of $
{this.year} one of the best racing car`)
// }

// }
// class SportsCar extends Car{
// horsePower:number;
// constructor(hp:number,comp:string,id:string,yr:number){
// super(comp,id,yr)
// this.horsePower = hp;
// }
// //overriding start()method to add horsePower property in it

// start(){
// console.log(`${this.model} made by ${this.make} in the year of $
{this.year} and have ${this.horsePower} the best racing car`)
// }
// }

// const newCar = new SportsCar(100,"Porsche","Porsche 911",2023);


// newCar.start();

/* 2.Create a class called Book with properties title, author, and pages. Add a
method read that logs a message to the console
indicating that the book has been read. */

// class Book{
// title:string;
// author:string;
// pages:number;
// constructor(title:string,author:string,pages:number){
// this.title= title;
// this.author = author;
// this.pages = pages;
// }
// read(){
// console.log(`${this.title} ${this.author} ${this.pages}`)
// }
// }

// const newBook = new Book("Angular","Google",5000)


// newBook.read();

//continue question with 3rd


/* 3.Create a subclass called EBook that inherits from Book and adds a property
format.
Override the read method to include the format of the ebook in the message. */

// class Book{
// title:string;
// author:string;
// pages:number;
// constructor(title:string,author:string,pages:number){
// this.title = title;
// this.author = author;
// this.pages = pages;
// }
// read(){
// console.log(`${this.title} ${this.author} ${this.pages}`)
// }

// }
// class Ebook extends Book{
// format:string;
// constructor(t:string,a:string,p:number,format:string){
// super(t,a,p)
// this.format = format;
// }
// //overridden method
// read(){
// console.log(`${this.title} ${this.author} ${this.pages} ${this.format}`)
// }
// }

// const book1 = new Ebook("JavaScript","Brendan Eich",10000,"PDF")


// book1.read();

/*4.Create a class called Shape with properties x and y.


Add a method draw that logs a message to the console indicating that the shape has
been drawn. */

// class Shape{
// x:number;
// y:number;
// constructor(x:number,y:number){
// this.x = x;
// this.y = y;
// }
// draw(){
// console.log(`${this.x} ${this.y} Shpae has been drawn`)
// }
// }

// const shape = new Shape(13,23)


// shape.draw();

//continue questions with 5th-->


/*5.Create a subclass called Circle that inherits from Shape and adds a property
radius.
Override the draw method to include the radius of the circle in the message.*/

// class Shape{
// x:number;
// y:number;
// constructor(x:number,y:number){
// this.x = x;
// this.y = y;
// }
// draw(){
// console.log(`${this.x} ${this.y} Shape has been drawn`)
// }
// }
// class Circle extends Shape{
// radius:number;
// constructor(x:number,y:number,r:number){
// super(x,y)
// this.radius = r;
// }
// // overriding the draw method
// draw(){
// console.log(`${this.x} ${this.y} ${this.radius} Circle has been drawn`)

// }
// }
// const circle = new Circle(13,23,12)
// circle.draw();

/*6.Create a class called Person with properties name and age.


Add a method speak that logs a message to the console indicating that the person
is speaking. */

// class Person{
// name:string;
// age:number;
// constructor(n:string,a:number){
// this.name = n;
// this.age = a;
// }
// speak(){
// console.log(`My name is ${this.name} My age is ${this.age}`)
// }
// }
// const person1 = new Person("Tony",21)
// person1.speak();

//continue questions with 6th-->


/*7Create a subclass called Teacher that inherits from Person and adds a property
subject.
Override the speak method to include the subject that the teacher is speaking
about. */

// class Person{
// name:string;
// age:number;
// constructor(n:string,a:number){
// this.name = n;
// this.age = a
// }
// speak(){
// console.log(`My name is ${this.name} My age is ${this.age}`)
// }
// }
// class Teacher extends Person{
// subject:string;
// constructor(n:string,a:number,sub:string){
// super(n,a);
// this.subject = sub;
// }
// speak(){
// console.log(`I am a Teacher My name is ${this.name} My age is $
{this.age} My subject is ${this.subject}`)
// }
// }

// const newTeacher = new Teacher("Tony",28,"Artificial-Intelligence");


// newTeacher.speak();

/*8.Create a class called Todo with properties description, dueDate, and completed.

Add methods markCompleted and markIncomplete that update the completed property
accordingly. */

// class Todo{
// description:string;
// dueDate:string;
// completed:boolean;
// constructor(des:string,date:string){
// this.description = des;
// this.dueDate = date;
// this.completed = false;
// }
// markCompleted(){
// this.completed = true;
// console.log(`Congratulations!`)
// }
// markUncomplete(){
// this.completed = false;
// console.log(`Dont Give Up, Try your best...`)
// }
// }

// const todoList = new Todo("complete Typescript","10/03/23")


// todoList.markCompleted();
// todoList.markUncomplete();

//continue questions with 8th-->


/*9.Create a subclass called PriorityTodo that inherits from Todo and adds a
property priority.
Override the markCompleted method to also log a message indicating the priority
level.*/

// class Todo{
// description:string;
// dueDate:string;
// completed:boolean;
// constructor(des:string,date:string){
// this.description = des;
// this.dueDate = date;
// this.completed = false;
// }
// markCompleted(){
// this.completed = true;
// console.log(`Congratulations!`)
// }
// markUncomplete(){
// this.completed = false;
// console.log(`Dont Give Up, Try your best...`)
// }
// }
// class PriorityTodo extends Todo{
// priority:string;
// constructor(des:string,date:string,pr:string){
// super(des,date);
// this.priority = pr;
// }
// markCompleted(){
// super.markCompleted()
// console.log(`Marked '${this.description}' (${this.priority} priority) as
completed.`)
// }
// }

// const priorityWork = new PriorityTodo("Complete TypeScript Practice","10-03-


23","High")
// priorityWork.markCompleted();

You might also like