12. Write a Java program which will demonstrate a concept of cohesion and coupling of the various modules in the program.

 -------------------------Coupling---------------------------

import java.lang.*;
import java.util.*;

class Box	{

	public int vol;
	Box( int l , int b , int h) 
	{
		this.vol = l*b*h;
	}
}

class Volume	{

	public static void main(String args[])
	{
		Box b = new Box(5,5,5);
		System.out.println("VOLUME : " + b.vol);
	}
} 
 
 -------------------------Cohesion---------------------------
import java.util.*;
import java.lang.*;

class Name {

	String name;
	public String getName(String name)
	{
		this.name = name;
		return name;
	}
}

class Age {

	int age;
	public int getAge(int age)
	{
		this.age = age;
		return age;
	}
}

class Number	{

	int num;
	public int getNum(int num)
	{
		this.num = num;
		return num;
	}
}

public class Student {
	 
	 public static void main(String args[])
	 {
	 	Name n = new Name();
	 	System.out.println("NAME   : " + n.getName("Shreyas"));
	 	Age a = new Age();
	 	System.out.println("Age    : " + a.getAge(20));
	 	Number n1 = new Number();
	 	System.out.println("NUMBER : "+ n1.getNum(5));
	 }
 }
 	
 	

 

Comments

Popular posts from this blog

2. Beginning with an empty binary search tree, Construct binary search tree by inserting the values in the order given. After constructing a binary tree -i.Insert new nodeii.Find number of nodes in longest path iii.Minimum data value found inthe tree iv.Change a tree so that the roles of the left and right pointers are swapped at every node v.Search a value

1. A book consists of chapters, chapters consist of sections and sections consist of subsections. Construct a tree and print the nodes. Find the time and space requirements of your method.

6. Implement all the functions of a dictionary (ADT) using hashing.Data: Set of (key, value) pairs, Keys are mapped to values, Keys must be comparable, Keys must be uniqueStandard Operations: Insert(key, value), Find(key), Delete(key)