Object Oriented App Development
virtual_world final
Virtual World/.classpath
Virtual World/.project
Virtual World org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature
Virtual World/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.8
Virtual World/bin/VirtualWorldPack/Main.class
package VirtualWorldPack; public synchronized class Main { public void Main(); public static void main(String[]); }
Virtual World/bin/VirtualWorldPack/MyClone.class
package VirtualWorldPack; public synchronized class MyClone { private String firstName; private String lastName; public void MyClone(); public void MyClone(String, String); public void introduction(); public void setFirstName(String); public void setLastName(String); public String getFirstName(); public String getLastName(); }
Virtual World/bin/VirtualWorldPack/MyComputer.class
package VirtualWorldPack; public synchronized class MyComputer { private String Mark; private String OpSystem; public void MyComputer(); public void MyComputer(String, String); public void introduce(); public void setMark(String); public void setOpSystem(String); public String getMark(); public String getOpSystem(); }
Virtual World/bin/VirtualWorldPack/ShoutBox.class
package VirtualWorldPack; public synchronized class ShoutBox { java.util.ArrayList list; public void ShoutBox(); public void shoutOutCannedMessage(); public void shoutOutRandomMessage(); }
Virtual World/src/VirtualWorldPack/Main.java
Virtual World/src/VirtualWorldPack/Main.java
package
VirtualWorldPack
;
public
class
Main
{
public
static
void
main
(
String
[]
argv
){
//Creat a new object from MyClone class
MyClone
human
=
new
MyClone
();
//Creat a new object from MyComputer class
MyComputer
laptop
=
new
MyComputer
();
//Creat a new object from ShoutBox class
ShoutBox
genmess
=
new
ShoutBox
();
//call the setter method to store the first name
human
.
setFirstName
(
"Jack"
);
//call the setter method to store the last name
human
.
setLastName
(
"Decaprio"
);
//call the method introduction() to display the name and greeting
human
.
introduction
();
//call the setter method to store the mark
laptop
.
setMark
(
"Lenovo"
);
//call the setter method to store the operating system
laptop
.
setOpSystem
(
"Windows 8"
);
//call the introduce method to print the mark and system
laptop
.
introduce
();
//calling the method to display the canned message
genmess
.
shoutOutCannedMessage
();
//calling the method to display the random message
genmess
.
shoutOutRandomMessage
();
}
}
Virtual World/src/VirtualWorldPack/MyClone.java
Virtual World/src/VirtualWorldPack/MyClone.java
package
VirtualWorldPack
;
public
class
MyClone
{
private
String
firstName
;
private
String
lastName
;
/*The first constractor
* to initialize
* the first name
* and the last name with null */
public
MyClone
(){
this
.
firstName
=
null
;
this
.
lastName
=
null
;
}
/*The second constractor
* with two parameter to
* initialize the firt
* name and the last name */
public
MyClone
(
String
firstname
,
String
lastname
){
this
.
firstName
=
firstname
;
this
.
lastName
=
lastname
;
}
/* method will introduce
* you to the virtual world
* by displaying a greeting,
* your full
name, and anything else
you would want to say.
* */
public
void
introduction
(){
System
.
out
.
println
(
"***************************Welcome To My Virtual World Java Application**************************"
);
System
.
out
.
println
(
"My first name : "
+
getFirstName
());
System
.
out
.
println
(
"My last name : "
+
getLastName
());
}
//method to set the first name of the object
public
void
setFirstName
(
String
firstname
){
this
.
firstName
=
firstname
;
}
//method to set the last name of the object
public
void
setLastName
(
String
lastname
){
this
.
lastName
=
lastname
;
}
//method to get the first nameof the object
public
String
getFirstName
(){
return
this
.
firstName
;
}
//method to get the last name of the object
public
String
getLastName
(){
return
this
.
lastName
;
}
}
Virtual World/src/VirtualWorldPack/MyComputer.java
Virtual World/src/VirtualWorldPack/MyComputer.java
package
VirtualWorldPack
;
public
class
MyComputer
{
private
String
Mark
;
private
String
OpSystem
;
/*The first constractor to
* initialize the two
* string variable with
* null*/
public
MyComputer
(){
this
.
Mark
=
null
;
this
.
OpSystem
=
null
;
}
/*The second constractor with
* two prametre
* to store the information
* on the two private
* variable
* */
public
MyComputer
(
String
mark
,
String
system
){
this
.
Mark
=
mark
;
this
.
OpSystem
=
system
;
}
/*The introduce() method
* to print the mark and
* the oprating system
* of my laptop
* */
public
void
introduce
(){
System
.
out
.
println
(
"My computer mark : "
+
getMark
());
System
.
out
.
println
(
"My computer operating system : "
+
getOpSystem
());
}
//setter method to store the mark on the variable
public
void
setMark
(
String
mark
){
this
.
Mark
=
mark
;
}
//setter method to store the operating system on the variable
public
void
setOpSystem
(
String
system
){
this
.
OpSystem
=
system
;
}
//getter method to output the mark on the window
public
String
getMark
(){
return
this
.
Mark
;
}
//getter method to output the operating system on the window
public
String
getOpSystem
(){
return
this
.
OpSystem
;
}
}
Virtual World/src/VirtualWorldPack/ShoutBox.java
Virtual World/src/VirtualWorldPack/ShoutBox.java
package
VirtualWorldPack
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Scanner
;
import
java
.
util
.
Random
;
public
class
ShoutBox
{
ArrayList
<
String
>
list
=
new
ArrayList
<>
()
;
/*this method display all
* canned messages and
* allow the user
* to select one
*/
public
void
shoutOutCannedMessage
(){
System
.
out
.
println
(
" "
);
System
.
out
.
println
(
"***************List of canned message***************"
);
list
.
add
(
0
,
"1-Hello World."
);
list
.
add
(
1
,
"2-I am studying."
);
list
.
add
(
2
,
"3-I am at work."
);
list
.
add
(
3
,
"4-I am fine."
);
list
.
add
(
4
,
"5-I love java."
);
list
.
add
(
5
,
"6-I am on my bed."
);
list
.
add
(
6
,
"7-I am eating."
);
list
.
add
(
7
,
"8-I use my laptop."
);
list
.
add
(
8
,
"9-I am in the kitchen."
);
list
.
add
(
9
,
"10-I am reading."
);
int
size
=
list
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
System
.
out
.
println
(
list
.
get
(
i
));
System
.
out
.
println
(
"---------------------------"
);
}
int
selectedMess
;
Scanner
scanner
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"==> Please select one canned message by enter the index number : "
);
System
.
out
.
print
(
" "
);
selectedMess
=
scanner
.
nextInt
();
System
.
out
.
println
(
list
.
get
(
selectedMess
-
1
));
}
/*The shoutOutRandomMessage() method will
* use a random number generator that selects
* one word from each data structure to form a
random message. Random messages will be in the
following form: Subject - Verb - Adjective - Object – Adverb
*/
public
void
shoutOutRandomMessage
(){
String
[]
subject
=
{
" He's"
,
" I'm"
,
" She"
};
String
[]
verb
=
{
" eating"
,
" catching"
,
" studying"
,
" caughing"
};
String
[]
adjective
=
{
" funny"
,
" hard"
,
" good"
,
" polite"
};
String
[]
object
=
{
" course"
,
" homework"
,
" books"
,
" dog"
};
String
[]
adverb
=
{
" quickly. "
,
" everywhere. "
,
" accordingly. "
,
" awfully. "
};
Random
r
=
new
Random
();
//intialize a Random
int
selectedElement
=
r
.
nextInt
(
subject
.
length
);
for
(
int
i
=
1
;
i
<=
1
;
i
++
)
{
String
randomSentence
=
subject
[
selectedElement
]
+
verb
[
selectedElement
]
+
adjective
[
selectedElement
]
+
object
[
selectedElement
]
+
adverb
[
selectedElement
];
System
.
out
.
println
(
" "
);
System
.
out
.
println
(
"ShoutOut: "
+
randomSentence
);
}
}
}