In: Computer Science
Programming Human Concentration Human contains a brain that has several thought areas. Awareness is defined by understanding (focusing) of a thought area, and Concentration is defined focusing your awareness into a thought area for a longer duration of time. Using Object-Oriented Design, program this concept to demonstrate concentration.
Design Using Object Oriented Principles ---------------------------------------
Let's first think through all the Classes to be created: 1. Human 2. Brain 3. ThoughtArea You can consider defining properties in each of these classes. Following methods should be written for this project.
You have to decide which classes to put the methods in
1. awareness() 2. focus() 3. concentration()
Design two test cases to show concentration.
Grading Criteria 1. Object Oriented Programming principles are used. 2. Coding conventions are followed. 3. Test runs are provided. 4. Class diagrams are provided.
Code:
import java.io.*;
class Brain
{
public static String awareness(String behaviour)
{
if(behaviour.equalsIgnoreCase("Aggresive"))
{
return
"High";
}
else
if(behaviour.equalsIgnoreCase("Assertive"))
{
return
"Medium";
}
else
if(behaviour.equalsIgnoreCase("Passive"))
{
return
"Low";
}
else
{
return
null;
}
}
}
/*
In the below class ThoughArea class extends the Brain class where
Brain class is
superclass and ThoughArea class is subclass ThoughArea class
gets
all the properties of the Brain class due to java inheritance
*/
class ThoughArea extends Brain
{
public static String focus(String behaviour)
{
if(behaviour.equalsIgnoreCase("Aggresive"))
{
return
"Medium";
}
else
if(behaviour.equalsIgnoreCase("Assertive"))
{
return
"Low";
}
else
if(behaviour.equalsIgnoreCase("Passive"))
{
return
"High";
}
else
{
return
null;
}
}
public static String concentration(String
behaviour)
{
if(behaviour.equalsIgnoreCase("Aggresive"))
{
return
"Low";
}
else
if(behaviour.equalsIgnoreCase("Assertive"))
{
return
"High";
}
else
if(behaviour.equalsIgnoreCase("Passive"))
{
return
"Medium";
}
else
{
return
null;
}
}
}
class Human
{
public static void main(String args[])throws
IOException
{
//This below line used to create
buffered reader to read input from the keyboard
BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));
String
name,age,height,behaviour;
System.out.print("Enter
Name:");
//This below line read input from
the keyboard in the form of string
name=br.readLine();
System.out.print("\nEnter
Age:");
age=br.readLine();
System.out.print("\nEnter
Height:");
height=br.readLine();
System.out.print("\nEnter
Behaviour:");
behaviour=br.readLine();
System.out.println("---------------------------");
System.out.println("Summary");
System.out.println("---------------------------");
System.out.println("Name:
"+name);
System.out.println("Age:
"+age);
System.out.println("Height:
"+height+"inches");
System.out.println("Behaviour:
"+behaviour);
//This below line calls the
function awareness in the ThoughArea class and print the
result
System.out.println("Awareness:
"+ThoughArea.awareness(behaviour));
//This below line calls the
function focus in the ThoughArea class and print the result
System.out.println("Focus:
"+ThoughArea.focus(behaviour));
//This below line calls the
function concentration in the ThoughArea class and print the
result
System.out.println("Concentration:
"+ThoughArea.concentration(behaviour));
}
}
Code Snippet:
Output :
Class Diagram: