Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help creating a UML diagram and Java code. If I am using a guitar for the real world entity, how can I complete

I need help creating a UML diagram and Java code. If I am using a guitar for the real world entity, how can I complete the following.

Part 1: Model a real world entity. You need to include identity, at least 3 attributes, and at least 3 methods.

Part 2: Create a UML diagram for your object in Part 1. Be sure that you have at least one constructor to your diagram in addition to the attributes and methods.

Part 3: Create the Java class for your object from your UML diagram in Part 2. The class should compile but you do not need to create a main to demonstrate that the class is runnable.

Here is an example of a UML diagram and the code that was created for it.

image text in transcribed

class Sprite { String name; /ame of the sprite. double xPos; //coordinates on the screen. double yPos; int powerLevel; //value 0 - 100 indicating power, 100 is highest.

public Sprite(String theName){ name = theName; xPos = 0; yPos = 0; powerLevel = 100; }

public Sprite(String theName, double x, double y, int power){ name = theName; xPos = x; yPos = y; powerLevel = power; }

public void powerUp(int amt){ powerLevel += amt; //add to the powerlevel if (powerLevel > 100) //100 is highest value possible. powerLevel = 100; } }//end class Sprite

public class TestSpriteSolution{ public static void main(String[] args){ //create a Sprite with name Basil powerLevel 100 and //at position 0,0 by using the constructor that receives a string. Sprite s1 = new Sprite("Basil");

//create a Sprite with name Navi, powerLevel 25 and //at position 50,75 by using the construct that takes //four argurments. Sprite s2 = new Sprite("Navi", 50, 75, 25);

//Display a message indicating which Sprite has more power. Assume they do /ever have equal power. if (s1.powerLevel > s2.powerLevel) System.out.println("Basil has more power than Navi"); else System.out.println("Navi has more power than Basil");

//Add 50 power to Navi by using the powerUp method. s2.powerUp(50);

//Change Basil to position 0,50 s1.yPos = 50;

//Display how far apart on the x-axis the two Sprites are. //Recall relative distance can be computed using Math.abs(parameter) method. System.out.println("The x-distance between sprites is " + Math.abs(s1.xPos - s2.xPos));

}//end main

}//end class TestSpriteSolution

Sprite name: String Warmup 01/27/2017 Pos double Pos double power Level: int Sprite (theName: String) sprite(theName: String, x: double, y: ouble, power: int powerUp(amt: int) void Sprite is a class that models a video game character. xPos and yPos represent the x and y position on the screen. power Level is a value between 0 and 100, inclusive, indicating power. o is none, 100 is full power. Default Pos and yPos is 0,0 unless otherwise specified. Sprite (theName String) will initialize name to theName, xPos to 0, yPos to 0, and powerLevel to 100. Sprite(theName: String, x: double, y: double, power: int) will initialize initialize name to the Name, xPos to x, yPos to y, and powerLevel to power. power Up (amt int) wi add amt to powerLevel

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

Explain the difference between systematic and random error.

Answered: 1 week ago

Question

Bookean expression for a 5 - input XOR gate?

Answered: 1 week ago