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
Many inventions have enabled us to use digital cameras. The biggest difference between traditional and digital cameras is that d
Andreyy89

1 Film Roll Vs SD card.

2 No LCD Display Vs LCD Display

3 No mega Pixels Vs Mega Pixels

4 Zero Optical zoom Vs Optical Zoom

5 No Picture Modes Vs Different Picture Modes

6 Limited Number of Pics per roll Vs unlimited number of pictures depending upon the size of a Card

7 Hassle of developing pictures Vs no hassle, simply transfer them to the pc/laptop

8 Limited features Vs multiple features

hope this helps

8 0
3 years ago
What is the difference between Notepad and WordPad?is one more adavnced?if so which one or Notepad is the Mac equivalent of Word
Kitty [74]
WordPad is defenitely more advanced.
There is no Mac equivalent.
4 0
3 years ago
In what year did alienware introduce alienfx lighting zones into their pc's?
ser-zykov [4K]
The answer to the question asked  above is 2006. 
<span>Alienware introduce alienfx lighting zones into their pc's on 2006.</span>

Hope my answer would be a great help for you.    If you have more questions feel free to ask here at Brainly.
8 0
3 years ago
A user has multiple web pages open and is using email. Which layer of the Transmission Control Protocol/Internet Protocol (TCP/I
Fudgin [204]

Answer:

This is the second question like this I've seen. They aren't the greatest.

Explanation:

The question is not good. The answer would be option a, Transport even though it doesn't make a whole lot of sense when you really go into detail.

It could also be option d, Application but I think they're going for the first.

6 0
2 years ago
In the United States there are more women than men, but women are referred to as a minority group? Why are they considered a min
ziro4ka [17]
Cause they make up half the population of the united states of america
7 0
2 years ago
Read 2 more answers
Other questions:
  • How can i put this sign in my keybord?<br><br> :::::<br> ^<br> Here is the sign
    8·1 answer
  • Which of the following is NOT a web browser?<br> Safari<br> Chrome<br> Bing<br> Firefox
    8·2 answers
  • ________ gives its approval to U.S. e-commerce websites that follow strict privacy standards, such as explaining to visitors how
    6·1 answer
  • To read visual and audio text means
    11·1 answer
  • Can you list one property of each of the following?<br> Excel<br> Word<br> Powerpoint
    7·2 answers
  • Write a public member function which replace that replaces one occurrence of a given item in the ArrayBag with another passed as
    14·1 answer
  • Which important aspect of the Roman Empire did the barbarians destroy?
    14·2 answers
  • An early attempt to force users to use less predictable passwords involved computer-supplied passwords. The passwords were eight
    10·1 answer
  • Group of programs are software ​
    6·2 answers
  • The set of coordinating colors applied to backgrounds, objects, and text in a presentation is called:
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!