Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I ran this code for each test. Test 1, and test 2 work but not test 3 because I have to modify this method. Specification:

I ran this code for each test. Test 1, and test 2 work but not test 3 because I have to modify this method.

Specification: LetterInventorysubtract(LetterInventory other) "Constructs and returns a new LetterInventory object that represents the result of subtracting the other inventory from this inventory (i.e., subtracting the counts in the other inventory from this objects counts). If any resulting count would be negative, your method should return null. The two LetterInventoryobjects being subtracted (this and other) should not be changed by this method

public LetterInventory subtract(LetterInventory other) {

LetterInventory inventory2 = new LetterInventory(this.toString() );

for (int i = 0; i < count.length; i++) {

inventory2.count[i] = inventory2.count[i] - other.count[i];

if (inventory2.count[i] < 0) {

return null;

}

}

return inventory2;

}

}

console output :

Testing these two strings:

i1: "aaggghhhh"

i2: "ggg"

constructing i1 and i2

constructing and testing i1.add(i2)

inventory = [aagggggghhhh]

toString, size, isEmpty, and count all passed

constructing and testing i2.add(i1)

inventory = [aagggggghhhh]

toString, size, isEmpty, and count all passed

constructing and testing i1.subtract(i2)

inventory = [aahhhh]

size failed

correct size = 6

your size = 9

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

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

What are the role of supervisors ?

Answered: 1 week ago

Question

How could assessment be used in an employee development program?

Answered: 1 week ago