Posts

Showing posts from 2017

HashMap Example Code

import java . util . HashMap ; import java . util . Map ; import java . util . Iterator ; import java . util . Set ; public class HashMapEx { public static void main ( String args []) { HashMap < Integer , String > hmap = new HashMap < Integer , String >(); // Adding to HashMap hmap . put ( 12 , "Kabir" ); hmap . put ( 2 , "Ravi" ); hmap . put ( 7 , "Luis" ); hmap . put ( 49 , "Peter" ); hmap . put ( 3 , "Aditya" ); // Iterate through HashMap Set set = hmap . entrySet (); Iterator iterator = set . iterator (); while ( iterator . hasNext ()) { Map . Entry mentry = ( Map . Entry ) iterator . next (); System . out . print ( "Key is: " + mentry . getKey () + " & Value is: " ); System . out . println ( mentry . getValue ()); } // Get a value...

Program to Create arraylists for Courses and Students using OOP concepts with getter and setter methods

Course.java public class Course { private String id; private String name; public Course() { } public Course(String id, String name) { this.id = id; this.name = name; } public void setId(String id) { this.id = id; } public String getId() { return this.id; } public void setName(String name) { this.name = name; } public String getName() { return this.name; } @Override public String toString() { return this.id; } } Student.java public class Student { private int rollNo; private String name; private Course course; private String address; private int phoneNumber; /** * Default Constructor */ public Student() { } /** * Overloaded Constructor */ public Student(int rollNo, String name, String address, int phoneNumber, Course course) { this.rollNo = rollNo; this.name = name; this.address = address; this.phoneNumber = phoneNumber; this.course = course; } /** * Setter for rol...

Linear Array using Pointer

#include <stdio.h> #include <stdlib.h> int main(int argc, char const *argv[]) { int *a; // Pointer int size; printf("Size of an array: "); scanf("%d", &size); // malloc()- it allocates the memory dynamically to a pointer variable a = malloc(sizeof(int) * size); printf("Enter %d elements of an array: "); for (int i = 0; i < size; i++) scanf("%d", &a[i]); // Behaving like an array printf("You've entered: "); for (int i = 0; i < size; i++) printf("%d ", a[i]); printf("\n"); return 0; }

Call by Value vs Call by Reference

/* Call by Value vs Call by Reference  */ #include <stdio.h> void swap(int x, int y) { int temp = x; x = y; y = temp; } void rswap(int *x, int *y) { int temp = *x; *x = *y; *y = temp; } int main(int argc, char const *argv[]) { int a, b; printf("a = "); scanf("%d", &a); printf("b = "); scanf("%d", &b); printf("a = %d, b = %d\n", a, b); rswap(&a, &b); // Call by reference printf("a = %d, b = %d\n", a, b); return 0; }

Inheritance

Shape.java package math.shapes; public class Shape { protected float side; public float perimeter() { return 0.f; } public float area() { return 0.f; } } Circle.java package math.shapes; public class Circle extends Shape { public Circle() { side = 0.f; } public Circle(float side) { this.side = side; } @Override public float perimeter() { return 2 * (float)Math.PI * side; } @Override public float area() { return (float)Math.PI * side * side; } } Rectangle.java package math.shapes; public class Rectangle extends Shape { private float side2; public Rectangle() { side = side2 = 0.f; } public Rectangle(float side, float side2) { this.side = side; this.side2 = side2; } @Override public float perimeter() { return 2 * (side + side2); } @Override public float area() { return side * side2; } } Square.java package math.shapes; public class Square extends Shape { public ...

Packages

Circle.java package shapes; public class Circle { private float radius; public Circle() { this.radius = 0.0f; } public Circle(float radius) { this.radius = radius; } public float getArea() { return (float)Math.PI * this.radius * this.radius; } public float getCircumference() { return 2 * (float)Math.PI * this.radius; } } TestCircle.java import shapes.Circle; public class TestCircle { public static void main(String[] args) { Circle circle1 = new Circle(5.f); Circle circle2 = new Circle(12.45f); System.out.println("Circumference of circle1 = " + circle1.getCircumference()); System.out.println("Area of circle1          = " + circle1.getArea()); System.out.println("Circumference of circle2 = " + circle2.getCircumference()); System.out.println("Area of circle2          = " + circle2.getArea()); } }

Complex Number Program in Java

/**  * Program to create a class for Complex Number.  * The class should contain real and imginary properties along  * add, subtract and product on complex numbers.  *  * Test your class on two complex numbers  */ class Complex { private float real; private float img; /** * Default constructor */ Complex() { this.real = this.img = .0f; } /** * Parameterized conctructor 1 */ Complex(float val) { this.real = this.img = val; } /** * Parameterized conctructor 2 */ Complex(float real, float img) { this.real = real; this.img = img; } /** * Addition */ public Complex add(Complex c) { return new Complex(this.real + c.real, this.img + c.img); } /** * Subtraction */ public Complex subtract(Complex c) { return new Complex(this.real - c.real, this.img - c.img); } /** * Multiplication * a + bi X c + di = (ac - bd) + (ad + cb)i */ public Complex product(Complex c...

Project Work-I Guidelines and Marks Distribution

Distribution of Internal Marks - Project Work-I (BSBC 506) S. No. Evaluation Criteria for Awarding Marks Max. Marks 1 File End Term Evaluation 1)   Problem Formulation a)   Drawbacks of Current System  b)   Need 2)   Objectives 3)   Feasibility Study 4)   Requirement Analysis & System Design a)   Data Flow Diagram        5 b)   Database Design          5 i.   Tables Structure ii.   ERD  5 10 5 10 2 Attendance Below < 75%                      0 [75-80)%             ...