Showing posts from February, 2017

Task 4 - The Lucky Racer Game

Last Updated: Oct. 3, 2021 This task covers multiple topics we have studied so far. I request to not only focus on completing the functional requirements but think well about where a specific code or functionality should be implemented and implemented it there. Also think over what fields should be allowed to be read by other objects and which ones should be kept private. Create AutomaticCar class that shall contain private model, year, speed and gear attributes. Encapsulate complete state and expose the state for read/write (where it makes sense or required). As its an automatic car, so other shall not be able to update the gear attribute directly. The gear shall change automatically based on speed and other parameters (defined below). The speed range for different gears is as follows: (fromat: gear : speed-range) 0:0 1:1-100 2:101-200 3:201-300 4:301-400 5:401-500 The speed should not change when negative value is passed as argument to set method, in such cases, it should

Task 3 - Constructors and Constructor Overloading

Updated On: Sep. 22, 2021 Task Learning Objectives: Data encapsulation using get and set methods and how to protect from outside access. How to define one or more constructors in a Java class How to initialize fields at the time of object instantiation How to call a constructor from another constructor How to calculate a property  is calculated at runtime, think of it like derived fields. Task 3.1 Create a Circle class such that it shall be mandatory for the user to pass the radius when its obbject is instantiated. Encapsulate radius field i.e. expose via getter and setter methods for public access to read and update. Make sure, its value is updated only when new value is greater than 0. Define calculateArea and calculatePerimeter methods with public access modifiers. Demonstrate the implemented functionality from main method of TestCircle class. Task 3.2 Make a class Employee with attributes cnic, name and salary. Make all fields private and expose them via proper getter and setter m

Task 2 : Classes, Instance Attributes and Methods

Post Updated on: Sep. 22, 2021 Task Objectives Creating class with instance attributes and methods Accessing instance attributes from methods Calling methods from outside the object and from whithin same object Appreciating how object oriented design help to write maintainable code Planning how and where we add new requirements in object oriented design This task explains only one program, parts are made to make it easy to understand and impelement step by step, only for learning objective. Do not make different programs for each part. Part 1 Make BankAccount class that shall have  balance and name attributes of type double and String . Implement  void deposit(double amount) and void withdraw(double amount) methods inside the BankAccount class. The deposit  method shall increase the balance by passed value and withdraw  method should decrease the balance with passed amount. Make BankAccountTest class. Inside its main( String args[] ) method, create a new object of BankAccount class.

Task 01 - Java Basics

Post Updated on: Sep. 18. 2021 Task 01 Objects: Writing, compiling and running basic program in Java Using primitive data types and their literals Getting input from user of different primitive types Using if/else, loops and defining methods in Java Below given tasks are very basic in nature. They are to make you comfortable with how to write code in Java using variables, if/else and loops, printing output at console using different methods. 1.1  Initialize a variable n with some +ve integer value. Then create implement logic to print first n prime numbers on console.  1.2 Declare and initialize byte, short, int, float, long, double, boolean type variables using literals, change those values by user input and then print all of 7 variables on console. (in lab video, you have already seen, how to get input from user using Scanner class) 1.3  Get a 4 digit integer number from user input and print each digits on a separate line. 1.4  Get an integer from user that represent a year, it must