Questions
- Java Programming - Develop JUnit test for a designated program - Perform JUnit testing for...

- Java Programming

- Develop JUnit test for a designated program

- Perform JUnit testing for on method that return both successful and unsuccessful results

- Create a JUnit test class for testing the getAverageScore and the getTotalScore methods.   On class per test.

public class Student
{
  
private String name;

private double totalScore;
  
private int quizCount;
  
public Student()
{
name = "";
totalScore = 0;
quizCount = 0;
}
n the name
*/
public Student(String n)
{
name = n;
totalScore = 0;
quizCount = 0;
}

public void setName(String aName)
{

name = aName;

}

public String getName()
{
return name;
}

public void addQuiz(int score)
{
if(score >= 0 && score <= 100)
{
totalScore = totalScore + score;
quizCount = quizCount + 1;
}
else
{
System.out.println("Score must be between 0 and 100, inclusive");
  
}
}

public double getTotalScore()
{
return totalScore;
}


public double getAverageScore()
{
return totalScore / quizCount;
}


}
----------------------

import java.util.Scanner;

public class StudentTester
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String repeat = "n";
int currentScore = 0;
  
System.out.print("Enter Student's name: ");
String sName = keyboard.nextLine();
  
Student student1 = new Student(sName);
  
do
{
System.out.print("Enter quiz score: ");
currentScore = keyboard.nextInt();
  
student1.addQuiz(currentScore);

System.out.print("Do you wish to enter another score, (Enter y for Yes, n for no: " );

keyboard.nextLine();
repeat = keyboard.nextLine();
  
}while(repeat.equalsIgnoreCase("y"));
  
String studName = student1.getName();
double totalScore = student1.getTotalScore();
double avgScore = student1.getAverageScore();
  
  
  
System.out.printf("%s total quiz score is: %,2f and average quiz score is: %6.2f \n", studName, totalScore, avgScore);
  
  
Student student2 = new Student();

In: Computer Science

this is a C++ question. 1 Write a program that returns the count of the occurences...

this is a C++ question.

1 Write a program that returns the count of the occurences of 8 as a digit within an integer.The input to the program should be an integer, not a string.For example 848 yields 2 .You are expected to solve this using a recursive function (no loops)
Hint:Note that mod (%) by 10 yields the rightmost digit (787 % 10 is 7 ) while division by 10 removes the rightmost digit (787/10 is 78)

In: Computer Science

For this assignment you will write a C++ program to read a list of words and...

For this assignment you will write a C++ program to read a list of words and sort them in alphabetical order.

Requirements:

  • You must use a bubble sort OR selection sort algorithm - your choice. You do NOT need to do both.
  • You must print the sorted list of words to the console standard out (cout).
  • You must use a vector object to store the list of words and you must sort the list "in-place" (meaning, do not create a new list.)
  • When reading the data, your program must ignore blank lines and any line that begins with the # symbol.

NOTES:

  • Part of the grade will be based on comments according to the style guide.
  • You can implement a class if you want to. Writing a class is not required for this assignment.
  • Don't make any assumptions about the input data. I may grade using a completely separate list of words. (if so, the format will be the same - no more then one word per line. But assume that blank lines and comments can occur anywhere in the file.)

word_list.txt

_____________________________________________________________________________________________________________________________________below:

# Read the list of words below and write them out in alphabetical order.
# Your program should skip over the blank lines. 
goal
interesting
successful
job
experience
career

manage
responsibility
technology
purpose
beautiful
wonder
opportunity
leader
quality

knowledge
victory
nature
ability
dream
understand
future
hope

In: Computer Science

Java program written with one file not two .... Make a LandTract class with the following...

Java program written with one file not two ....

Make a LandTract class with the following fields:

• length - an int containing the tract's length
• width - an int containing the tract's width

The class should also have the following methods :

• area - returns an int representing the tract's area
• equals - takes another LandTract object as a parameter and returns a boolean saying
whether or not the two tracts have the same dimensions (This applies regardless of whether the dimensions match up. i.e., if the length of the first is the same as the width of the other and vice versa, that counts as having equal dimensions.)
• toString - returns a String with details about the LandTract object in the format:
LandTract object with length 30 and width 40
(If, for example, the LandTract object had a length of 30 and a width of 40.)

Write a separate program that asks the user to enter the dimensions for the two tracts of
land (in the order length of the first, width of the first, length of the second, width of the second). The program should print the output of two tracts' toString methods followed by a sentence stating whether or not the tracts have equal dimensions. (If the tracts have the same dimensions, print, "The two tracts have the same size." Otherwise, print, "The two tracts do not have the same size.") Print all three statements on separate lines.

****Results have to look like this****

Enter·length·of·first·land·tract:10↵
Enter·width·of·first·land·tract:55↵
Enter·length·of·second·land·tract:36↵
Enter·width·of·second·land·tract:75↵
LandTract·with·length·10,·width·55,·and·area·550↵
LandTract·with·length·36,·width·75,·and·area·2700↵
The·two·tracts·do·not·have·the·same·size.↵

In: Computer Science

Lab4: Functions, Procedures, and Testbenches in vivado Conclusion: Question4: How are statements executed inside of a...

Lab4: Functions, Procedures, and Testbenches in vivado Conclusion:

Question4: How are statements executed inside of a procedure?

Question6: How are statements executed inside of a function?

Question7: What is the difference between inertial delay and transport delay?

Question8: What is the purpose of having the use STD.textio.all; statement in the testbench file?

Question9: Why do we not have any ports declared in the entity of a testbench?

Question10: Describe what happens inside the architecture portion of a testbench design.

In: Computer Science

In Java Create an interface GainsInterest that contains two method signatures with public access modifiers for...

In Java

Create an interface GainsInterest that contains two method signatures with public access modifiers for compound daily and interestAccrued that both return BigDecimal.

Create an abstract Account class and a SavingsAccount that derives from it using best programming practices. Define an account balance that is set in the constructor of SavingAccount and passed to the constructor of the Account. SavingsAccount should implement GainsInterest, but you do not need to provide implementation for those methods beyond defining the method inside in the class and returning BigDecimal.ZERO.

In: Computer Science

1. Start a new customer order – clear the order data (give a second chance to...

1. Start a new customer order – clear the order data (give a second chance to not clear data)  This will clear all the running totals (set them to zero).

  1. Ordering Ice Cream Sundaes – should prompt the user for the number of ice cream sundaes.

  2. Ordering Ice Cream Cones – should prompt the user for the number of ice cream cones.

  3. Ordering Milkshakes – should prompt the user for the number of milkshakes.

  4. Generate the customer receipt for their order. This should be appended to any other

    orders already written to the file. The receipt output file should be named: receipt.rpt

  5. Exit the program - Make sure to exit the program gracefully through the return 0 at the

    bottom of main( ).

Write a menu driven program that will provide the user with the 6 menu options indicated above. The user should be able to make a selection, execute the code for that selection, and then return to the menu until option (6) Exit is selected. If the end-user enters an invalid menu option, print an error message and redisplay the menu, getting a new selection.

When an option from the menu is selected your program should call a function to do the selection processing. If the end-user enters a qty that is less than 0 or enters character data, print an error message and prompt the user for a new value. Keep a running total of how many of each item is ordered.

When the option to start a new order is selected, ask the user if they are sure they want to clear the order. If the user answers ‘y’ or ‘Y’ then clear the running totals for all ice cream products. Any other input should not clear the running totals.

When the end-user selects to create a receipt, write a summary of the items ordered (don't print items that have a count of zero), calculate the subtotal, tax (using 6%), and the total order to an output file named receipt.rpt (use append mode of opening the file so each order is appended to the end of the file). If the entire order is zero, do not generate a summary; simply write the line: No order was placed. Each receipt written should have a delimiter, a new line, line of “*”, and a new line. In c++

In: Computer Science

C# Create class IntegerSet. Each IntegerSet object can hold integers in the range 0-100 inclusively. The...

C#

Create class IntegerSet. Each IntegerSet object can hold integers in the range 0-100 inclusively. The set is represented by an array of bools. Array element a[i] is true if integer i is in the set. Array element a[j] is false if integer j is not in the set. The parameterless constructor initializes the array to the empty set (all false). Provide the following methods:

  1. Method Union creates a third set that the set-theoretic union of two existing sets. ie. if an element is in either set, it will be in the new set.
  2. Method Intersection creates a third set which is the set-theoretic intersection of the two existing sets. ie. if an element is in both sets, it will be in the new set
  3. Method InsertElement inserts integer i into the set
  4. Method DeleteElement deletes integer i from the set
  5. Method ToStringreturns a string containing the set as a list of numbers separated by spaces. Include only elements present in the set. Use --- to represent the empty set
  6. Method IsEqualTo determines whether two sets are equal

Write a console app to test your IntegerSet class. Instantiate several  IntegerSet objects and ensure the above functions work correctly

In: Computer Science

NEED IN JAVA ECLIPSE For this lab, you will create a program that uses method overloading...

NEED IN JAVA ECLIPSE

For this lab, you will create a program that uses method overloading and a switch statement.

Requirements:

The Patapsco River Valley Running Festival needs a program that will allow them to calculate

the cost of the entry fee for each group of entrants. Once the cost is calculated, it is then

displayed to the user.

The program also totals up the total amount of money that will be collected and displays the total

at the very end when the user states that they have no more entries.

You will use the program you wrote in Lab 3 as the starting point for this lab. All of the data

entry for each program is exactly the same. However, the program now displays the cost of the

race entered and the total cost of all of the races.

CODE FROM LAB 3:

/**
*
*/
package volunteers;

/**
*
*
* This program will create a counter which will count the number of Howard County residents attending the event versues the number of
* non- Howard County residents. The program will also tally the number of runners in each of the race lengths. Finally, the program
* will collect the age of the runner.
*/
import java.util.Scanner;
public class Volunteers {
  
   // Instantiate scanner
static Scanner input=new Scanner(System.in);
public static void main(String[] args)
{
  
// declaring and initializing variables
int total_runner=0;
int Howard_County_Residents=0;
int non_Howard_County_Residents=0;
int total_children=0;
int total_adults=0;
int total_senior=0;
int total_5k=0;
int total_10k=0;
int total_HalfMarathon=0;
int total_FullMarathon=0;
int total_fun_run=0;
int age,runChoice;
String userChoice;
while(true)
{
userChoice=takeUserInput("\n\nWould you like to add a runner? Enter 'yes' or 'no'.");
if(userChoice.equals("no"))
break;
total_runner++;
  
userChoice=takeUserInput("\n\nIs the Runner a Howard County resident? Enter 'Yes' or 'No':");
if(userChoice.equals("yes"))
Howard_County_Residents++;
else
non_Howard_County_Residents++;
  
while(true)
{
System.out.println("\n\nWhat is the runner's age?");
age=input.nextInt();
if(age>0)
break;
else
System.out.println("\n\nInvalid Entry. Age must be greater than 0. Please reenter:");
}
  
if(age<10 || age>=70)
{
if(age<10)
total_children++;
else
total_senior++;
while(true)
{
System.out.println("\nSelect the event the runner will be running in:\r\n" +
"1 - 5K\r\n" +   
"2 - 10K\r\n" +   
"3 - Half Marathon\r\n" +   
"4 - Full Marathon\n5 - 1 Mile Fun Run");
runChoice=input.nextInt();
if(runChoice>=1 && runChoice<=5)
break;
else
System.out.println("\nInvalid Entry. Please select a value from the menu. Please reenter:");
}
}
else
{
total_adults++;
while(true)
{
System.out.println("\nSelect the event the runner will be running in:\r\n" +
"1 - 5K\r\n" +
"2 - 10K\r\n" +
"3 - Half Marathon\r\n" +
"4 - Full Marathon");
runChoice=input.nextInt();
if(runChoice>=1 && runChoice<=4)
break;
else
System.out.println("\nInvalid Entry. Please select a value from the menu. Please reenter:");
}
}
if(runChoice==1)
total_5k++;
else if(runChoice==2)
total_10k++;
else if(runChoice==3)
total_HalfMarathon++;
else if(runChoice==4)
total_FullMarathon++;
else
total_fun_run++;
  
} // printing the stats
System.out.println("\nTotal Runners: "+total_runner);
System.out.println("Total Howard County Residents: "+Howard_County_Residents);
System.out.println("Total Non-Howard County Residents: "+non_Howard_County_Residents);

System.out.println("\nTotal number of children: "+total_children);
System.out.println("Total number of adults: "+total_adults);
System.out.println("Total number of seniors: "+total_senior);

System.out.println("\nTotal 5K Runners: "+total_5k);
System.out.println("Total 10K Runners: "+total_10k);
System.out.println("Total Half Marathon Runners: "+total_HalfMarathon);
System.out.println("Total Half Marathon Runners: "+total_FullMarathon);
System.out.println("Total Fun Run Participants: "+total_fun_run);
  
}
public static String takeUserInput(String s)
{
String choice;
while(true)
{
System.out.println(s);
choice=input.next();
if(choice.equals("yes") || choice.equals("no"))
break;
else
{
System.out.print("\nInvalid Entry. Only 'yes' or 'no' is acceptable. Please reenter:");
}
}
return choice;

} // End of main method
} // End of class Volunteer

This enhanced program will need to do the following calculations:

Race Event- 5K

Howard County Res Cost- $25

Non-Howard County Res Cost- $40

Race Event- 10K

Howard County Res Cost- $35

Non-Howard County Res Cost- $50

Race Event- Half Marathon

Howard County Res Cost- $65

Non-Howard County Res Cost- $85

Race Event- Full Marathon

Howard County Res Cost- $85

Non-Howard County Res Cost- $115

Race Event- Fun Run

Howard County Res Cost- $20

Non-Howard County Res Cost- $25

Non-Howard County residents who are 18 years of age or younger or 60 years of age or older get

a $5 discount on their entry fee. There are no discounts for county residents.

You should use a switch statement to implement the table, and you should not use the reserved

word "return" within the switch statement.

NOTE: There should be only ONE named method (an overloaded method is acceptable) to

determine and return the cost of the event for Howard County residents and non-Howard County

residents. Use the method parameters to distinguish between cases.

You should declare constant values for all of the costs listed in the table.

This code should all be contained within one class file.

OUTPUT SHOULD LOOK LIKE THIS:

Would you like to add a runner? Enter 'yes' or 'no'.

test

Invalid Entry. Only 'yes' or 'no' is acceptable. Please reenter:

Would you like to add a runner? Enter 'yes' or 'no'.

yes

Is the Runner a Howard County resident? Enter 'Yes' or 'No':

yes

What is the runner's age?

-2

Invalid Entry. Age must be greater than zero. Please reenter:

What is the runner's age?

32

Select the event the runner will be runnning in:

1 - 5K

2 - 10K

3 - Half Marathon

4 - Full Marathon

3

You have entered the Half Marathon race. The cost is $65.00

Would you like to add a runner? Enter 'yes' or 'no'.

yes

Is the Runner a Howard County resident? Enter 'Yes' or 'No':

no

What is the runner's age?

43

Select the event the runner will be runnning in:

1 - 5K

2 - 10K

3 - Half Marathon

4 - Full Marathon

3

You have entered the Half Marathon race. The cost is $85.00

Would you like to add a runner? Enter 'yes' or 'no'.

yes

Is the Runner a Howard County resident? Enter 'Yes' or 'No':

no

What is the runner's age?

62

Select the event the runner will be runnning in:

1 - 5K

2 - 10K

3 - Half Marathon

4 - Full Marathon

3

You have entered the Half Marathon race. The cost is $80.00

Would you like to add a runner? Enter 'yes' or 'no'.

yes

Is the Runner a Howard County resident? Enter 'Yes' or 'No':

no

What is the runner's age?

9

Select the event the runner will be runnning in:

1 - 5K

2 - 10K

3 - Half Marathon

4 - Full Marathon

5 - 1 Mile Fun Run

5

You have entered the Fun Run race. The cost is $20.00

Would you like to add a runner? Enter 'yes' or 'no'.

yes

Is the Runner a Howard County resident? Enter 'Yes' or 'No':

no

What is the runner's age?

75

Select the event the runner will be runnning in:

1 - 5K

2 - 10K

3 - Half Marathon

4 - Full Marathon

5 - 1 Mile Fun Run

2

You have entered the 10K race. The cost is $45.00

Would you like to add a runner? Enter 'yes' or 'no'.

yes

Is the Runner a Howard County resident? Enter 'Yes' or 'No':

no

What is the runner's age?

23

Select the event the runner will be runnning in:

1 - 5K

2 - 10K

3 - Half Marathon

4 - Full Marathon

4

You have entered the Full Marathon race. The cost is $115.00

Would you like to add a runner? Enter 'yes' or 'no'.

no

Total Runners: 6

Total Howard County Residents: 1

Total Non-Howard County Residents: 5

Total number of children: 1

Total number of adults: 4

Total number of seniors: 1

Total 5K Runners: 0

Total 10K Runners: 1

Total Half Marathon Runners: 3

Total Full Marathon Runners: 1

Total Fun Run Participants: 1

The total cost of all of the races entered is $410.00

In: Computer Science

This is to be done in C++. Preferably using basic functions. Write a loop that reads...

This is to be done in C++. Preferably using basic functions.

Write a loop that reads one double each time around.

Define two variables to keep track of which is the smallest and which is the largest value you have seen so far.

Each time through the loop write out the value entered. If it's the smallest so far, write the smallest so far after the number. If it is the largest so far, write the largest so far after the number.

Let the user add a unit to each double entered; that is, enter values such as 10cm, 2.5in, 5ft, or 3.33m.

Accept the four units: cm, m, in, ft.

Assume conversion factors 1m == 100cm, 1in == 2.54cm, 1ft == 12in.

Read the unit indicator into a string.

You may consider 12 m (with a space between the number and the unit) equivalent to 12m (without a space).

Reject values without units or with "illegal" representations of units, such as y, yard, meter, km, and gallons.

Keep track of the sum of values entered (as well as the smallest and the largest) and the number of values entered. When the loop ends, print the smallest, the largest, the number of values, and the sum of values. note that to keep the sum, you have to decide on a unit to use for that sum; use meters.

Keep all the values entered (converted into meters) in a vector. At the end, write out those values.

Before writing out the values from the vector, sort them (that'll make them come out in increasing order).

In: Computer Science

python- please finish the three programs, where one flips an image horizonally, then vertically, and one...

python- please finish the three programs, where one flips an image horizonally, then vertically, and one that rotates an image by 90 degrees. please don't use the functions .mirror() .flip() or .rotate() if possible. thanks

def horizontal(image):
"""Flip the specified image left to right and return the modified image"""


return img

def vertical(image):
"""Flip the specified image upside down and return the modified image"""


  
return image

def rotate_90(image):
"""Rotate the specified image 90 degrees to the right and return the modified image"""

  
return image

In: Computer Science

Create a new program, called stars.py, for (eventually) drawing a 500x500 pixel picture of the night...

Create a new program, called stars.py, for (eventually) drawing a 500x500 pixel picture of the night sky. The stars.py file will define several custom functions. You should write each function and then test it to verify it is working correctly. Make sure you match each function name precisely. Once complete submit it to D2L.

getStarPixelX()

  • 1 Input Parameter: a star string
  • Return: the x pixel coordinate of the star
  • Steps:
    1. Split star string into smaller strings
    2. grab the x coordinate and convert it into a float
    3. calculate the pixel coordinate with the formula: 250 + (250 * x)
    4. return the result

Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)

  • getStarPixelX("0.0,1.0,0.0,1,-1.5,1") → 250.0
  • getStarPixelX("0.5,-0.5,0.0,2,2.0,2") → 375.0

getStarPixelY()

  • 1 Input Parameter: a star string
  • Return: the y pixel coordinate of the star
  • Steps:
    1. Split star string into smaller strings
    2. grab the y coordinate and convert it into a float
    3. calculate the pixel coordinate with the formula: 250 - (250 * y)
    4. return the result

Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)

  • getStarPixelY("0.0,1.0,0.0,1,-1.5,1") → 0.0
  • getStarPixelY("0.5,-0.5,0.0,2,2.0,2") → 375.0

getStarSize()

  • 1 Input Parameter: a star string
  • Return: the pixel size of the star
  • Hint: The formula to convert a star's magnitude to its size is: 10.0/(magnitude + 2)

Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)

  • getStarSize("0.0,1.0,0.0,1,-1.5,1") → 20.0
  • getStarSize("0.5,-0.5,0.0,2,2.0,2") → 2.5

getStarName()

  • 1 Input Parameter: a star string
  • Return: the name of the star if it has one, else the empty string ("")
  • Hint: If a star string has 7 values, then the last value is the star's name

Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)

  • getStarName("0.0,1.0,0.0,1,-1.5,1,BOB") → "BOB"
  • getStarName("0.5,-0.5,0.0,2,2.0,2") → ""

In: Computer Science

Sources: linkedlist.cpp #include <iostream> #include "linkedlist.h" using namespace std; LinkedList* NewLinkedList() { LinkedList* llp = new...

Sources: linkedlist.cpp

#include <iostream>
#include "linkedlist.h"
using namespace std;

LinkedList* NewLinkedList()
{
LinkedList* llp = new LinkedList;

llp->head = new node;

llp->head->next = 0;

return llp;
}

void InsertFirst(LinkedList* llp, int val)
{
node* p = new node;
p->data = val;
p->next = llp->head->next;
llp->head->next = p;
}

void Print(LinkedList* llp)
{
for (node* p = llp->head->next; p != 0; p = p->next) {
cout << p->data << " ";
}
}

void InsertLast(LinkedList* llp, int val)
{

node* p;

for (p = llp->head; p->next != 0; p = p->next)
{
}

// p now points to the last node in the list

// For you to do: Create a new node, store val in that node, and link the new node after p.


}

Sources: hw1.cpp

#include <iostream>
#include "linkedlist.h"
using namespace std;

int main()
{
LinkedList* llp = NewLinkedList();

InsertFirst(llp, 10);
InsertFirst(llp, 20);
InsertFirst(llp, 30);

cout << endl;
Print(llp);
cout << endl;

InsertLast(llp, 50);
InsertLast(llp, 60);
InsertLast(llp, 70);

cout << endl;
Print(llp);
cout << endl;

return 0;
}

Header: linkedlist.h

#ifndef LINKEDLIST_H_INCLUDED
#define LINKEDLIST_H_INCLUDED

struct node {
int data;
node* next;
};

struct LinkedList {
node* head;
};

LinkedList* NewLinkedList();
void InsertFirst(LinkedList* llp, int val);
void Print(LinkedList* llp);
void InsertLast(LinkedList* llp, int val);

#endif // LINKEDLIST_H_INCLUDED

-----------------------------

Your assignment is to complete the function InsertLast in linkedlist.cpp, compile, and run. The correct output should be:

30 20 10

30 20 10 50 60 70

In: Computer Science

Question about Hard Disks 1. For Redundant Arrays of Inexpensive Disks, which of the following two...

Question about Hard Disks

1. For Redundant Arrays of Inexpensive Disks, which of the following two has more reliability? The Level 0 + 1 (Striping + Mirroring) or Level 1 + 0 (Mirroring + Striping)? Why?

2. Why does the Elevator have better performance than Shortest Seek Time First algorithm for a heavy load? (Elevator is also called the SCAN or C-SCAN)

3. Do accesses to sectors in outer tracks require less time compared to accesses sectors to inner tracks? Why or why not?

In: Computer Science

Create the program using C# A business records its daily sales totals. Enter the following weekly...

Create the program using C#

A business records its daily sales totals. Enter the following weekly sales information into an array.

1245.67

1189.55

1089.72

1456.88

2109.34

1987.55

1872.36

Once, the information has been entered into the array. Access the items in the array to find and display the following:

  • Total Sales
  • Weekly Sales Average
  • Largest Daily Sales
  • Smallest Daily Sales

In: Computer Science