1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
elena-14-01-66 [18.8K]
3 years ago
9

Create a class called Hokeemon that can be used as a template to create magical creatures called Hokeeemons. Hokeemons can be of

four types, Dwarf, Elf, Hobbit and Fairy. A dwarf lives in the Mountain, an elf lives in the Dale, a fairy lives in the Forest and a hobbit lives in the Shire. Hokeemons of the same types are always friends. Also, dwarves and elves are friends, and hobbits and fairies are friends.
Computers and Technology
1 answer:
Viefleur [7K]3 years ago
3 0

Answer:

See Explaination

Explanation:

/*****************************************Hokeemon.java********************************/

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class Hokeemon {

private String name;

private String type;

private int age;

public Hokeemon(String name, String type, int age) {

super();

this.name = name;

this.type = type;

this.age = age;

}

public Hokeemon() {

this.name = "";

this.type = "";

this.age = 0;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public String liveIn() {

if (this.type.equalsIgnoreCase("dwarf")) {

return "Mountain";

} else if (this.type.equalsIgnoreCase("elf")) {

return "Dale";

} else if (this.type.equalsIgnoreCase("fairy")) {

return "Forest";

} else {

return "Shire";

}

}

public boolean areFriends(Hokeemon other) {

if (this.type.equalsIgnoreCase(other.type)) {

return true;

} else if ((this.type.equalsIgnoreCase("dwarf") && other.type.equalsIgnoreCase("elf"))

|| (this.type.equalsIgnoreCase("elf") && other.type.equalsIgnoreCase("dwarf"))) {

return true;

} else if ((this.type.equalsIgnoreCase("hobbit") && other.type.equalsIgnoreCase("fairy"))

|| (this.type.equalsIgnoreCase("fairy") && other.type.equalsIgnoreCase("hobbit"))) {

return true;

} else {

return false;

}

}

public static Hokeemon[] getData(String file) {

Hokeemon[] hokeemons = new Hokeemon[8];

int i = 0;

try {

Scanner scan = new Scanner(new File(file));

while (scan.hasNextLine() && i < hokeemons.length) {

String line = scan.nextLine();

String[] data = line.split("\\s+");

String name = data[0];

String type = data[1];

int age = Integer.parseInt(data[2]);

hokeemons[i] = new Hokeemon(name, type, age);

i++;

}

scan.close();

} catch (FileNotFoundException e) {

System.err.println(e);

}

return hokeemons;

}

public static String getBio(Hokeemon[] hokeemons) {

String s = "";

for (Hokeemon hokeemon : hokeemons) {

s += "I am " + hokeemon.getName() + ": Type " + hokeemon.getType() + ": Age=" + hokeemon.getAge()

+ ", I live in " + hokeemon.liveIn() + "\n";

s += "My friends are: ";

for (Hokeemon hokeemon2 : hokeemons) {

if (hokeemon.areFriends(hokeemon2) && !hokeemon.equals(hokeemon2)) {

s += (hokeemon2.getName() + " ");

}

}

s += "\n";

}

return s;

}

atOverride

public String toString() {

return "Name " + name + ": Type " + type + ": Age=" + age + "\n";

}

}

/*******************************HokeemonMain.java**************************/

import java.util.Arrays;

public class HokeemonMain {

public static void main(String[] args) {

Hokeemon[] hokeemons = Hokeemon.getData("data.txt");

System.out.println(Arrays.toString(hokeemons));

System.out.println(Hokeemon.getBio(hokeemons));

}

}

/**********************************data.txt********************/

Noddy Dwarf 4

Legolas Elf 77

Minerva Fairy 33

Samwise Hobbit 24

Merry Hobbit 29

Warhammer Dwarf 87

Ernedyll Elf 19

Frodo Hobbit 18

You might be interested in
How many answer or point do I answer/need to sent message?
Grace [21]

I'm a little confused about the question, but if you're asking how many points you need to ask a question, the minimum is 10.


4 0
2 years ago
What animal is perry the platypus ​
valkas [14]

Answer: Agent P or simply Perry

Explanation:

4 0
3 years ago
Read 2 more answers
What is SEO?<br> Training Live Online Instructor-Led Learning, https://www.peoplentech.com.bd/<br> ,
evablogger [386]

Answer:Search engine optimization (SEO) is the process of optimizing your online content so that a search engine likes to show it as a top result for searches of a certain keyword. ... When it comes to SEO, there's you, the search engine, and the searcher.

Explanation:

4 0
2 years ago
Ms. Lawson, a primary school teacher, told her students that a photograph of the president is in the public domain. What does sh
dezoksy [38]

Answer:

He belongs to the nation

7 0
2 years ago
The internet is an accurate and reliable source of information and an investigator should take the information at face value. tr
AVprozaik [17]
False

Not everything is true, face value is not always reliable
7 0
2 years ago
Other questions:
  • Which of the following is likely the cause of the bass from a sound system rattling the windows on your car?
    11·1 answer
  • By placing the chorale melody in the highest voice and using a simple harmonization, bach made it easier for congregation member
    5·1 answer
  • I Just Realized................
    7·2 answers
  • Choose the word that best completes this sentence. ____________ should cover every part of the worksite.
    10·2 answers
  • Which of the following is NOT an argument used to determine how a shot is fired from an A. object the shot itself being instanti
    12·1 answer
  • Which feature of a blog allows an author to interact and get feedback from his or her readers? link pingback commenting TweetMem
    9·1 answer
  • Write a program that dose the following:
    9·1 answer
  • FREE 25 POINTS
    5·2 answers
  • Which of these is an example of collective voice?
    8·2 answers
  • How do you remove management from your chrome book [administrator]
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!