CoreJava - Basics – Assignment - 1

 

Core Java Basics – Assignment - 1

 

Assignment 1: Create a class called "Book" with the following attributes: title (String), author (String), year (int), and price (double). Creates an instance of the Book class, sets its attributes, and prints them out.

Assignment 2: Create a class called "BankAccount" with attributes: accountNumber (String) and balance (double). Include a method called "deposit" that takes a parameter for the amount to be deposited and updates the balance accordingly. Include a method called "withdraw" that takes a parameter for the amount to be withdrawn and updates the balance if sufficient funds are available. Write a main method that creates an instance of the BankAccount class, performs a deposit and a withdrawal, and prints the resulting balance.

Assignment 3: Create a class called "Person" with the following attributes: name (String), age (int), and address (String) and prints them out.

Assignment 4: Create a class called "Calculator" with a method called "add" that takes two integers as parameters and returns their sum. Write a main method that creates an instance of the Calculator class, calls the add method with two numbers, and prints the result.

Assignment 5: Create a Java class called "Calculator" with a method called "add" that takes two integers as parameters and returns their sum. Create an object of the Calculator class and use the "add" method to calculate the sum of two numbers. Print out the result.

Assignment 6: Write a Java class called "Car" with the following attributes: make, model, and year. Create an object of the Car class and set values for its attributes. Finally, print out the values of the car's make, model, and year.

Assignment 7: Create a class called "Rectangle" with attributes width and height. Write a method called "calculateArea" that calculates and returns the area of the rectangle. Create an instance of the Rectangle class with width 5 and height 10, and print out its area.

Assignment 8: Create a class called "Student" with attributes name, grade, and studentID. Write a method called "displayInfo" that prints out the student's information. Create an instance of the Student class and call the displayInfo method.

Assignment 9: Create a class called "BankAccount" with attributes accountNumber and balance. Write methods called "deposit" and "withdraw" that modify the balance accordingly. Create an instance of the BankAccount class with an initial balance of 1000. Deposit 500 into the account and then withdraw 200. Print out the final balance.

Assignment 10: Create a class called "Car" with attributes make, model, and year. Write a method called "startEngine" that prints out "The car is starting." Write a method called "stopEngine" that prints out "The car is stopping." Create an instance of the Car class and call the startEngine and stopEngine methods.


Comments

Popular posts from this blog

FrontEnd - FAQs - Part 1

CoreJava - ClassesObjectsMethods - Assignment

Java Script - FAQs