
Lab2.java contains the following code:
public final class Lab2 {
/**
* This is empty by design, Lab2 cannot be instantiated
*/
private Lab2() {
// empty by design
}
/**
* Returns the sum of a consecutive set of numbers from <code> start </code> to <code> end </code>.
*
* @pre <code> start </code> and <code> end </code> are small enough to let this
* method return an int. This means the return value at most requires 4 bytes and
* no overflow would happen.
*
* @param start is an integer number
* @param end is an integer number
* @return the sum of start + (start + 1) + .... + end
*/
public static int sum(int start, int end) {
//Insert your code here and change the return statement to fit your implementation.
return 0;
}
/**
* This method creates a string using the given char
* by repeating the character <code> n </code> times.
*
* @param first is the given character by which the string is made.
* @param n is the number of characters in the final string
* @return a string made of the given character.
*
* @pre n is not negative.
*/
public static String makeString(char first, int n) {
//Insert your code here and change the return statement to fit your implementation.
return "";
}
/**
* This method gets two strings and interlace a string using the
* these two input strings. The number of words in the returned string is as much
* as the value of the third input parameter.
*
* @param first is the string that is used in the even position of the returned result [ asuming
* that the position starts from zero]
* @param second is the string that is used in the odd position of the returned result
* @param n is the number of words in the returned result.
* @return returns a string made of the first and the second input parameter.
*/
public static String interlace(String first, String second, int n) {
//Insert your code here and change the return statement to fit your implementation.
return "";
}
/**
* This method returns a substring of the given input string that is enclosed in two
* given characters.
* @param str is a string that contains at least two characters including <code> open </code> and <code> close </code>
* @param open is a character at the beginning of the string that should be returned.
* @param close is a character at the end of the string that should be returned.
* @return returns a string enclosed in two given characters of <code> open </code> and <code> close </code>.
* @pre The given str contains only one <code> open </code> and one <code> close </code> character.
*/
public static String getSubstring(String str, char open, char close) {
//Insert your code here and change the return statement to fit your implementation.
return "";
}
/**
* This method converts a decimal value into its binary representation.
* @param value is a positive integer number
* @return the binary representation of the input.
* @pre the input is a positive integer number.
*/
public static String decimalToBinary(int value) {
//Insert your code here and change the return statement to fit your implementation.
return "";
}
}
Lab2Tester.java contains the following code:
public class Lab2Tester {
// sum
@Test
public void testSum1() {
int start = 0;
int end = 5;
int sum= 0;
for (int i = start ; i <= end ; i++)
sum += i;
assertEquals("Failed at sum (" + start + ", " + end + ")", sum, Lab2.sum(start, end));
}
@Test
public void testMakeString1() {
char init = '*';
int n = 5;
String result = "";
for (int i = 0 ; i < n ; i++)
result += init;
assertEquals("Failed at makeString(" + init + ", " + n + ")", result, Lab2.makeString(init, n));
}
@Test
public void testInterlace6() {
String str1 = "Hello ";
String str2 = "World ";
String result = "Hello World Hello World Hello ";
assertEquals("Failed: interlace(\"*\",\"-\",5)", result, Lab2.interlace("Hello ","World ",5));
}
@Test
public void testGetSubstring1() {
String str1 = "x + y + z - ( y * z) / 3 * n ";
String result = " y * z";
char open = '(';
char close = ')';
assertEquals("Failed: getSubstring(\"x + y + z - ( y * z) / 3 * n \", \"(\", \")\")", result, Lab2.getSubstring("x + y + z - ( y * z) / 3 * n ", '(', ')'));
}
@Test
public void testDecimalToBinary4() {
int decimal = 23;
String binary = "10111";
assertEquals("Failed: decimalToBinary(23)", binary, Lab2.decimalToBinary(23));
}
}

Step by stepSolved in 3 steps with 1 images

- ** in Java ** Suppose we have a set of car. Each car has a number of colors, number of places, dimension and power. According to the set of cad we can have three sets: sedan, sport and pickup truck.1. Write a java program using the previous description.2. Use the flowing concepts,: heritage, polymorphism, encapsulation (get and set method)arrow_forward#include <iostream> #include <string> #include <cstdlib> using namespace std; template<class T> T func(T a) { cout<<a; return a; } template<class U> void func(U a) { cout<<a; } int main(int argc, char const *argv[]) { int a = 5; int b = func(a); return 0; } Give output for this code.arrow_forwardc++ A FastCritter moves twice as fast as a regular critter. When asked to move by n steps, it actually moves by 2 * n steps. Implement a FastCritter class derived from Critter whose move function behaves as described. Complete the following file: fastcritter_Tester.cpp #include <iostream>using namespace std; #include "critter.h" /**A FastCritter moves twice as fast as a regular critter.*/class FastCritter:public Critter{public:void move(int steps);}; . . . int main(){FastCritter speedy;speedy.move(10);cout << speedy.get_history() << endl;cout << "Expected: [move to 20]" << endl;speedy.move(-1);cout << speedy.get_history() << endl;cout << "Expected: [move to 20, move to 18]" << endl;return 0;} Use the following file: critter.h #ifndef CRITTER_H #define CRITTER_H #include <string> #include <vector> using namespace std; /** A simulated critter. */ class Critter { public: /** Constructs a critter at position 0 with blank…arrow_forward
- The C++ Vertex class represents a vertex in a graph. The class's only data member is _____ Ⓒlabel 1000 O weight O framEdges O toEdges Question 36 The C++ Graph class's fromEdges member is a(n) _________ O string Ⓒdouble O vector O unordered_map Question 37 The C++ Graph class's AddVertex() function's return type is _____ void O Edge+ Overtex) O vectorarrow_forwardJAVA Program(*MUST WORK IN HYPERGRADE*) Homework #1. Chapter 7. PC# 2. Payroll Class (page 488-489) Write a Payroll class that uses the following arrays as fields: * employeeId. An array of seven integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 * hours. An array of seven integers to hold the number of hours worked by each employee * payRate. An array of seven doubles to hold each employee’s hourly pay rate * wages. An array of seven doubles to hold each employee’s gross wages The class should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeId array. That same employee’s pay rate should be stored in element 0 of the payRate array. The class should have a method that accepts an…arrow_forwardC programming fill in the following code #include "graph.h" #include <stdio.h>#include <stdlib.h> /* initialise an empty graph *//* return pointer to initialised graph */Graph *init_graph(void){} /* release memory for graph */void free_graph(Graph *graph){} /* initialise a vertex *//* return pointer to initialised vertex */Vertex *init_vertex(int id){} /* release memory for initialised vertex */void free_vertex(Vertex *vertex){} /* initialise an edge. *//* return pointer to initialised edge. */Edge *init_edge(void){} /* release memory for initialised edge. */void free_edge(Edge *edge){} /* remove all edges from vertex with id from to vertex with id to from graph. */void remove_edge(Graph *graph, int from, int to){} /* remove all edges from vertex with specified id. */void remove_edges(Graph *graph, int id){} /* output all vertices and edges in graph. *//* each vertex in the graphs should be printed on a new line *//* each vertex should be printed in the following format:…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





