Programming Assignment #4 (Logger and UML) Submit your assignment as a report. You need to do the following for each of the problems to get full points. Check for the BOUNDARY conditions with respect...

1 answer below »
Only the second part (putting horses in the stalls)


Programming Assignment #4 (Logger and UML) Submit your assignment as a report. You need to do the following for each of the problems to get full points. Check for the BOUNDARY conditions with respect to you inputs. Please use Loggers instead of System.out.println. 1) Program listing with line numbers. [ 7 points] 2) Create at least 3 test cases (2 positive and 1 negative) and report their output. More test cases you add better it will be. [ 3 points] 1. Symmetric points You are given a list cartesian coordinates. In that list you have some pairs that symmetric, i.e. if you have (x,y) in the list, then you will find (y,x). Write a Java program to find such pairs. List 1 = { (3,4), (4,5), (5,6), (9,1), (6,5), (8,9), (9,1), (-4,3), (5,1), (4,3) } Ans = {(3,4), (5,6)} 2. Social distance A terrible new disease, HORSEVID, has begun to spread among horses worldwide. Stable manager Jimmy is trying to take as many precautions as possible to protect his herd from infection. Stable manager Jimmy's barn is a long narrow building containing N stalls in a row (2≤N≤105). Some of these stalls are currently occupied by horses, and some are vacant. Having read about the importance of "social distancing", Stable manager Jimmy wants to maximize D, where D is the distance between the closest two occupied stalls. For example, if stalls 3 and 8 are the closest that are occupied, then D=5. Two new horses recently joined Jimmy's herd and he needs to decide to which formerly-unoccupied stalls they should be assigned. Please determine how he can place his two new horses so that the resulting value of D is still as large as possible. Stable manager Jimmy cannot move any of his existing horses; he only wants to assign stalls to the new horses. INPUT: The first line of input contains N. The next line contains a string of length N of 0s and 1s describing the sequence of stalls in the barn. 0s indicate empty stalls and 1s indicate occupied stalls. The string has at least two 0s, so there is at least enough room for two new horses. OUTPUT: Please print the largest value of D (the closest distance between two occupied stalls) that Stable manager Jimmy can achieve after adding his two new horses in an optimal fashion. SAMPLE INPUT: 14 10001001000010 SAMPLE OUTPUT: 2 In this example, Stable manager Jimmy could add horses to make the occupancy string look like 10x010010x0010, where x's indicate the new horses. In this case D=2. It is impossible to add the new horses to achieve any higher value of D. 3. UML: Read through these websites. (extra reference) https://www.visual-paradigm.com/guide/uml-unified-modeling-language/uml-class-diagram-tutorial/ (easy) https://developer.ibm.com/articles/the-class-diagram/ (informative) https://www.omg.org/spec/UML/2.5/PDF (dense) https://www.visual-paradigm.com/guide/uml-unified-modeling-language/uml-class-diagram-tutorial/ https://developer.ibm.com/articles/the-class-diagram/ https://www.omg.org/spec/UML/2.5/PDF
Answered Same DayMay 06, 2021

Answer To: Programming Assignment #4 (Logger and UML) Submit your assignment as a report. You need to do the...

Sanchi answered on May 06 2021
142 Votes
Code:
Main.java:
// Import the
// required packages.
import java.util.*;
// Define the
// Main class.
class Main {

// Define the main() method.
public static void main(String[] args) {
// Define an object to
// read the user input.
Scanner in = new Scanner(System.in);

// Declare the
// required variables.
int n;
int[] stable;
int gapStart = 0;
int gapEnd = 0;
String inputLine;

// Read and store
// the number of stalls.
n = in.nextInt();

// Allocate memory to the array
// to represent the stalls.
stable = new int[n];

// Ignore the newline character
// after the integer input.
in.nextLine();

// Read and store the
// net line of input.
inputLine = in.nextLine();
for(int i=0;i {
stable[i] = inputLine.charAt(i) - '0';
}
// Run the loop to place
// two new horses.
for(int i=0; i<2; i++)
{
// Reset the values
// of the variables.
gapStart = 0;
gapEnd = 0;
int currGapSize = 0;
int currGapStart = 0;
int currGapEnd = 0;
int maxGapSize = 0;

boolean isGap = false;

// Run the loop to
// traverse the stalls.
for(int j=0; j {
// If the previous stall was empty,
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here