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
mariarad [96]
3 years ago
9

Write a unit test for addInventory(). Call redSweater.addInventory() with parameter sweaterShipment. Print the shown error if th

e subsequent quantity is incorrect. Sample output for failed unit test given initial quantity is 10 and sweaterShipment is 50:
Beginning tests.
UNIT TEST FAILED: addInventory()
Tests complete.
Note: UNIT TEST FAILED is preceded by 3 spaces.

#include
using namespace std;

class InventoryTag {
public:
InventoryTag();
int getQuantityRemaining() const;
void addInventory(int numItems);

private:
int quantityRemaining;
};

InventoryTag::InventoryTag() {
quantityRemaining = 0;
}

int InventoryTag::getQuantityRemaining() const {
return quantityRemaining;
}

void InventoryTag::addInventory(int numItems) {
if (numItems > 10) {
quantityRemaining = quantityRemaining + numItems;
}
}

int main() {
InventoryTag redSweater;
int sweaterShipment = 0;
int sweaterInventoryBefore = 0;

sweaterInventoryBefore = redSweater.getQuantityRemaining();
sweaterShipment = 25;

cout << "Beginning tests." << endl;

// FIXME add unit test for addInventory

/* Your solution goes here */

cout << "Tests complete." << endl;

return 0;
}
Computers and Technology
2 answers:
Serhud [2]3 years ago
5 0

Answer:

kindly check explainations for code

Explanation:

Header files

#include <iostream>

using namespace std;

// define class InventoryTag

class InventoryTag

{

public:

// constructor

InventoryTag();

// declare functions

int getQuantityRemaining() const;

void addInventory(int numItems);

private:

// declare a variable

int quantityRemaining;

};

InventoryTag::InventoryTag()

{

quantityRemaining = 0;

}

// function definition

int InventoryTag::getQuantityRemaining() const

{

return quantityRemaining;

}

// function definition

void InventoryTag::addInventory(int numItems)

{

if (numItems > 10)

{

quantityRemaining = quantityRemaining + numItems;

}

}

// main function

int main()

{

// create an object for class InventoryTag

InventoryTag redSweater;

// Declare variables

int sweaterShipment = 0;

int sweaterInventoryBefore = 0;

// Call getQuantityRemaining()function

sweaterInventoryBefore =

redSweater.getQuantityRemaining();

// Assign a value to variable

sweaterShipment =25;

cout << "Beginning tests." << endl;

// FIXME add unit test for addInventory

/* Your solution goes here */

// Call addInventory() function

redSweater.addInventory(sweaterShipment);

// Check whether the result is expected result

// or not

if (redSweater.getQuantityRemaining() !=

sweaterShipment + sweaterInventoryBefore)

{

// Print error message

cout << " UNIT TEST FAILED: addInventory()"

<< endl;

}

cout << "Tests complete." << endl;

system("pause");

return 0;

}

zavuch27 [327]3 years ago
5 0

Answer:

redSweater.addInventory(sweaterShipment);

if (redSweater.getQuantityRemaining() != sweaterShipment + sweaterInventoryBefore) {

System.out.println("   UNIT TEST FAILED: addInventory()");

}

Explanation:

The if statement sets a condition for the unit test. If the condition isn't met then it prints the unit failed statement. Also, the answer above is kinda right but has lots of extra stuff in the code. Remember to have 3 spaces before the unit failed statement, 1 test will pass but the last one won't.

You might be interested in
Someone learn me more American Sign Language (ASL). Please.
sveticcg [70]

Answer:

Ok I will

Explanation:

3 0
3 years ago
How did mechanical clocks assist in completing work? How was work done previously?
lozanna [386]

Answer

Timekeeping has been a part of society since Ancient Egypt. The use of spring-powered mechanisms allowed clocks to be made smaller ... Essentially, the church bells and the mechanical clock now became the monitor of the working day.

Explanation:

4 0
3 years ago
You have spent $4,000 on liquor for your bar. Your bar sales have been $24,000. What is your cost of sales for liquor, expressed
amid [387]

Answer:

17%

Explanation:

Given parameters:

Cost price of liquor = $4000

Total sale = $24000

Unknown:

Percentage cost of sale for liquor = ?

Solution:

To find the percentage cost of sale;

       %Cost of sale of liquor = \frac{cost price of liquor}{Total cost of sale }   x 100

Input the variables;

       %Cost of sale of liquor = \frac{4000}{24000}  x 100 = 16.67% = 17%

8 0
3 years ago
Select the correct answer.
Vitek1552 [10]

Answer:

I think it's C. but not a 100%

6 0
3 years ago
Read 2 more answers
Now that the classList Array has been implemented, we need to create methods to access the list items.
natima [27]

The following code will be applied to Create the following static methods for the Student class

<u>Explanation:</u>

/* Note: Array index starts from 0 in java so ,, user ask for 1 index then the position will be i-1 , below program is based on this concept if you dont want this way just remove -1 from classList.get(i-1).getName(); ,and classList.add(i-1,student); */

/* ClassListTester.java */

public class ClassListTester

{

public static void main(String[] args)

{

//You don't need to change anything here, but feel free to add more Students!

Student alan = new Student("Alan", 11);

Student kevin = new Student("Kevin", 10);

Student annie = new Student("Annie", 12);

System.out.println(Student.printClassList());

System.out.println(Student.getLastStudent());

System.out.println(Student.getStudent(1));

Student.addStudent(2, new Student("Trevor", 12));

System.out.println(Student.printClassList());

System.out.println(Student.getClassSize());

}

}

/* Student.java */

import java.util.ArrayList;

public class Student

{

private String name;

private int grade;

//Implement classList here:

private static ArrayList<Student> classList = new ArrayList<Student>();

public Student(String name, int grade)

{

this.name = name;

this.grade = grade;

classList.add(this);

}

public String getName()

{

return this.name;

}

//Add the static methods here:

public static String printClassList()

{

String names = "";

for(Student name: classList)

{

names+= name.getName() + "\n";

}

return "Student Class List:\n" + names;

}  

public static String getLastStudent() {

// index run from 0 so last student will be size -1

return classList.get(classList.size()-1).getName();

}

public static String getStudent(int i) {

// array starts from 0 so i-1 will be the student

return classList.get(i-1).getName();

}

public static void addStudent(int i, Student student) {

// array starts from 0 so, we add at i-1 position

classList.add(i-1,student);

// remove extra student

classList.remove(classList.size()-1);

}  

public static int getClassSize() {

return classList.size();

}

}

7 0
3 years ago
Other questions:
  • You support Richman Investments, a brokerage firm that employs 20 brokers. Each broker has his own client computer, and the firm
    15·1 answer
  • A friend is having a problem with keeping a fish tank at the right temperature so the fish stay healthy. Describe how you could
    9·1 answer
  • When should you talk to an adult you trust
    12·1 answer
  • You work in the Accounting Department and have been using a network drive to post Excel workbook files to your file server as yo
    9·1 answer
  • I need help with this problem please
    9·1 answer
  • Andrew’s Complete Cameras offers its customers an interactive website to help them choose the best camera for their lifestyle. B
    5·1 answer
  • Given an char variable last that has been initialized to a lowercase letter, write a loop that displays all possible combination
    8·1 answer
  • Explain why the operating system hides certain folders ​
    5·1 answer
  • Which pair of devices have the same input motion and different outputs?
    15·1 answer
  • The _____ constraint assigns a value to an attribute when a new row is added to a table
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!