Questions
I need to make changes to code following the steps below. The code that needs to...

I need to make changes to code following the steps below. The code that needs to be modified is below the steps. Thank you.

1. Refactor Base Weapon class:

a.            Remove the Weapon abstract class and create a new Interface class named WeaponInterface.

b.            Add a public method fireWeapon() that returns void and takes no arguments.

c.             Add a public method fireWeapon() that returns void and takes a power argument as an integer type.

d.            Add a public method activate() that returns void and takes an argument as an boolean type.

2. Refactor the specialization Weapon Classes:

a.            Refactor the Bomb class so that it implements the WeaponInterface class.

b.            Refactor the Gun class so that that it implements the WeaponInterface class.

3. Refactor the Game Class:

a.            Remove all existing game logic in main().

b.            Create a private helper method fireWeapon() that takes a WeaponInterface as an argument as a weapon. For the passed in weapon activate the weapon then fire the weapon.

c.             Create an array of type WeaponInterface that can hold 2 weapons.

d.            Initialize the first array element with a Bomb.

e.            Initialize the second array element with a Gun.

f.             Loop over the weapons array and call displayArea() for each weapon.

------

// Weapon.java

public abstract class Weapon {
   public void fireWeapon(int power)
   {
       System.out.println("Class Name :"+this.getClass().getSimpleName());
       System.out.println("Mathod Name :"+new Throwable().getStackTrace()[0].getMethodName());
       System.out.println("Power :"+power);
   }
   public abstract void activate(boolean enable);
}

______________________

// Bomb.java

public class Bomb extends Weapon {
   @Override
   public void fireWeapon(int power)
   {
       System.out.println("Class Name :"+this.getClass().getSimpleName());
       System.out.println("Mathod Name :"+new Throwable().getStackTrace()[0].getMethodName());
       System.out.println("Power :"+power);
   }
   public void fireWeapon()
   {
       System.out.println("Class Name :"+this.getClass().getSimpleName());
       System.out.println("Mathod Name :"+new Throwable().getStackTrace()[0].getMethodName());
       super.fireWeapon(67);
   }
   @Override
   public void activate(boolean enable) {
       System.out.println("Class Name :"+this.getClass().getSimpleName());
       System.out.println("Mathod Name :"+new Throwable().getStackTrace()[0].getMethodName());
       System.out.println("Enable :"+enable);
   }
}

_____________________________

// Gun.java

public class Gun extends Weapon {
   @Override
   public void fireWeapon(int power)
   {
       System.out.println("Class Name :"+this.getClass().getSimpleName());
       System.out.println("Mathod Name :"+new Throwable().getStackTrace()[0].getMethodName());
       System.out.println("Power :"+power);
   }
   public void fireWeapon()
   {
       System.out.println("Class Name :"+this.getClass().getSimpleName());
       System.out.println("Mathod Name :"+new Throwable().getStackTrace()[0].getMethodName());
       super.fireWeapon(98);
   }
   @Override
   public void activate(boolean enable) {
       System.out.println("Class Name :"+this.getClass().getSimpleName());
       System.out.println("Mathod Name :"+new Throwable().getStackTrace()[0].getMethodName());
       System.out.println("Enable :"+enable);
   }
}

_____________________________

// Game.java

public class Game {
   public static void main(String args[]) {
       Bomb b = new Bomb();
       Gun g = new Gun();
       b.fireWeapon(45);
       g.fireWeapon(60);
   }

}

In: Computer Science

Explain how to use the C# shortcut arithmetic operators -=, *=, and /=.

Explain how to use the C# shortcut arithmetic operators -=, *=, and /=.

In: Computer Science

C++ Please Fill in for the functions for the code below. The functions will be implemented...

C++ Please

Fill in for the functions for the code below. The functions will be implemented using vectors. Additional public helper functions or private members/functions can be used. The List class will be instantiated via a pointer and called similar to the code below:

---the code can be general (can be tested with any int main() test function)---

Stack *ptr = new Stack();

ptr->push(value);

int pop1 = ptr->pop();

int pop2 = ptr->pop();

bool isEmpty = ptr->empty();

class Stack{

    public:

// Default Constructor

Stack() {// ... }

// Push integer n onto top of stack

void push(int n) {// ... }

// Pop element on top of stack

int pop() {// ... }

// Get the top element but do not pop it (peek at top of stack)

int top() {// ... }

// Return whether the stack is empty or not

bool empty() {// ... }

};

In: Computer Science

Create java class with name MyClass1 Instructions for MyClass1 For this portion of the assignment you...

Create java class with name MyClass1

Instructions for MyClass1

For this portion of the assignment you will need to create a java class of your own to model some objects in the real world or your own imagination. your classes should have at least three instances variables, accessor and mutator methods for each of those instance variables, one constructor method of any type, as well as an overridden toString method that will display every field value as part of a String. Use meaningful identifiers for the name of  class.

Demonstrate that your class work appropriately by creating instances of each in the MainClass class which contains a main method

In: Computer Science

Write the equations for carry-out bits for a 4-bit carry lookahead adder. Draw its diagram and...

Write the equations for carry-out bits for a 4-bit carry lookahead adder. Draw its diagram and label all the inputs and the outputs. Compare the delays of the 4-bit ripple-carry and 4-bit carry lookahead adders.

In: Computer Science

Write a C program that counts the number of odd numbers with using function count() within...

Write a C program that counts the number of odd numbers with using function count() within the set. The set has only one negative number which determines the end of set.

In: Computer Science

(previous program) Prompt the user for the filename. Create a new file object sensehat_data_file which opens...

(previous program) Prompt the user for the filename. Create a new file object sensehat_data_file which opens the file in write mode. Write a loop which will read in 20 values for temperature and humidity from the SenseHat. Sleep 0.5 seconds between each reading taken from the SenseHat Write out the temperature and humidity to the file sensehat_data_file, separated by a comma. Close the file.)

ONLY ANWSER problem below

Then Open the file in read only mode. Use a loop to read in the data from the file until all lines have been read. Print out the count for the number of the line read in. Print out the temperature and humidity.

Print in Python .

In: Computer Science

6. There are 3 types of positioning commands in CSS: static, relative, and absolute. Explain how...

6. There are 3 types of positioning commands in CSS: static, relative, and absolute. Explain how each type behaves with regard to: (a) (2 pts) whether or not offsets can be specified (b) (2 pts) where offset values are measured from

In: Computer Science

Write a Java application for a gas station to calculate the total payment for customer. Your...

Write a Java application for a gas station to calculate the total payment for customer.

Your program should display a menu and get customer’s input: ****************************

Welcome to XYZ gas station! Select type of gas (enter R, P, S) Regular - R. plus - P. Super -S: ****************************

Enter the amount of gas in gallons:

In your code, define regular price: $2.45, plus: $2.65, super $2.95 as constant.

Use 7% as sale tax.

Calculate gas subtotal = sale price * gas amount Tax=subtotal * sale tax. Total payment = subtotal + Tax Output nicely to customer the total amount payment:

######################################################

Your payment for (Regular/plus/Super) is $###.

######################################################

Requirements:

Use switch statement for type of gas (case ‘R’, case ‘P’, case ‘S’ , etc)

Use while loop to display the menu. If user inputs anything other than R,P,S, display the menu again.

Use for loop statement to draw lines(**********… and ##############...)

In: Computer Science

Implement a function that returns the maximum number in a given unsorted linked list. For example,...

Implement a function that returns the maximum number in a given unsorted linked list.
For example, there is a linked list 3->5->1->10->9. The printMax() function in max.c should return the maximum number in the linked list, namely 10 in the example.

1. Implement max.c with the completed printMax() function.
2. Provide an explanation for your solution

#include <stdio.h>

typedef struct node {
int value;
struct node *next;
} node;

int printMax(node *first) {
// Your implementation
return 0;
}

int main(void) {
node nodes[5]; //enough to run our tests
int i,array[5] = {3,5,1,10,9};
for(i=0; i < sizeof(nodes)/sizeof(node)-1; i++) {
nodes[i].next = &nodes[i+1];
nodes[i].value = array[i];
}
nodes[i].value = array[4];
nodes[i].next = NULL;
printf("The maximum number is %d\n", printMax(&nodes[0]));
return 0;
}


In: Computer Science

For this assignment, you will be analyzing the Java™ code in the linked Week 3 Analyze...

For this assignment, you will be analyzing the Java™ code in the linked Week 3 Analyze Assignment Zip File, and predicting the results. You will also examine both the code and the output for inconsistencies and clarity. This Java™ code includes examples of for, while, and do-while loops.

Carefully read through the code line by line, then answer the following questions in a Microsoft® Word document:

  1. What is the output of the program as it is written?
  2. What improvement(s) could be made to this code to make the output clearer or more accurate, or to make the code easier to maintain?

Note: You do not have to make the improvements in the Java™ program, although you certainly may. For this assignment, simply describe the things you see that would need to be improved to elevate the code and output to a more professional level. For the code, consider variable names and hardcoding. For the output, consider formatting/punctuation, repetition, accuracy of information, and wording.

/**************************************************************************************
* Program: PRG/420 Week 3
* Purpose: Week 3 Analyze Assignment
* Programmer: Iam A. Student   
* Class: PRG/420   
* Creation Date: 10/22/17
******************************************************************************************
* Program Summary: For, while, and do-while loops
*
* This program demonstrates the syntax for the for, while, and do-while loops. It also
* contains comments that explain why a programmer would use a for loop over a while or do-while
* loop.
*
* Notice the increment operator (i++) and also notice the copious use of println() statements.
* Using System.out.println() is an excellent way to debug your code--especially if your loop code
* is giving unexpected results.
*****************************************************************************************/


package PRG420Week3_AnalyzeAssignment;

public class PRG420Week3_AnalyzeAssignment {

public static void main(String[] args) {
  
// for loops are a good choice when you have a specific number of values
// you want to iterate over and apply some calculation to.
System.out.println("FOR LOOP - Here are the taxes on all 10 prices:");
  
double taxRate = 0.08;
for (int price=1; price<=10; price++) {
System.out.println("The 8% tax on " + price + " dollar(s) is " + "$" + (price * taxRate));
}
System.out.println(""); // Leave a blank space
  
// while loops are a good choice when you're looking through a pile of values
// and want to execute some logic while some condition is true.
// while loops MAY OR MAY NOT EVER EXECUTE, depending on the counter value.
int dollars=1;
System.out.println("WHILE LOOP - Here are the taxes on prices less than $5:");
while (dollars < 5) {
System.out.println("The 8% tax on " + dollars + " dollar(s) is $" + (dollars * taxRate));
dollars++;
}
System.out.println(""); // Leave a blank space
  
// do-while loops are also a good choice when you're looking through a pile of values
// and want to execute some logic while some condition is true.
// do while loops ALWAYS EXECUTE AT LEAST ONCE, no matter what the counter value.
// For example, in the code below, we want to print out the tax only on those
// amounts smaller than $1. But because we're using the do-while loop, the code
// will execute the body of the loop once before it even checks the condition! So
// we will get an INCORRECT PRINTOUT.
dollars=1;
  
System.out.println("DO-WHILE LOOP - Here are the taxes on prices less than $1:");
  
do {
System.out.println("The 8% tax on " + dollars + " dollar(s) is $" + (dollars * 0.08));
dollars++;
} while (dollars < 1);
}
}

In: Computer Science

Assignment (C language) We will simulate the status of 8 LEDs that are connected to a...

Assignment (C language)

We will simulate the status of 8 LEDs that are connected to a microcontroller. Assume that the state of each LED (ON or OFF) is determined by each of the bits (1 or 0) in an 8-bit register (high-speed memory).

  1. Declare a char variable called led_reg and initialize it to 0.
    Assume that the least-significant bit (lsb) controls LED#0 and the most-significant bit (msb) controls LED#7.
  2. In the main function, build and present a menu to the user and enclose it in a loop that ends when the Quit option is chosen. Use if-else or switch-case statements to implement the operations described:

    Menu:
    0. Turn ON LED#4
    1. Turn OFF LED#4
    2. Add 1 to the LED Register
    3. Turn ON all the even numbered LEDs
    4. Turn OFF all the even numbered LEDs
    5. Toggle the state of LED#3.
    6. Shift the values of the LED Register right by 1
    7. Quit
  3. Create a function called: printBinary() with the following properties:

    • one input argument of type char
    • returns nothing
    • prints the binary representation (in 8-bits) of the char input value.
  4. Use the printBinary() function to display the value of the LED register before the menu.

HINTS:

  • Each operation can be performed with a single expression (line of code).
  • Append 0b or 0x to numerical constants to denote binary or hexadecimal values in source code, respectively.
    101010102 = 0b10101010
    FF16 = 0xFF

In: Computer Science

Use counting sort, sort the following numbers: 4, 2, 5, 4, 2, 3, 0, 2, 4,...

Use counting sort, sort the following numbers: 4, 2, 5, 4, 2, 3, 0, 2, 4, 3

In: Computer Science

Objective: Write this program in the C programming language Loops with input, strings, arrays, and output....

Objective:

Write this program in the C programming language

Loops with input, strings, arrays, and output.

Assignment:

It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory.

You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more than 100 characters per book title title. Use malloc to allocate the strings in the array.

So, it will be a menu:

  1. Enter book information
  2. List all books and prices
  3. List total value of inventory

In: Computer Science

How do you implement an AVL tree for strings in Java?

How do you implement an AVL tree for strings in Java?

In: Computer Science