-
Notifications
You must be signed in to change notification settings - Fork 20.8k
Closed
Description
Our code is -
package com.fresco;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class Passanger {
int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public float getFare() {
return fare;
}
public void setFare(float fare) {
this.fare = fare;
}
float fare;
public Passanger(int id, float fare) {
this.id = id;
this.fare = fare;
}
}
public class BusProb {
@SuppressWarnings("unused")
public String output(int capacity, int stops, List<String> listOfInputStrings, String query) {
String outstring = ""; // Write your code here
ArrayList<String> Query = new ArrayList<String>(Arrays.asList(query.split(",")));
// System.out.println(Query.get(0));
if (Query.get(0).equalsIgnoreCase("1")) {
int in = 0, out = 0;
// System.out.println(Integer.parseInt("-1001"));
for (int i = 0; i < listOfInputStrings.size(); i++) {
String[] words = listOfInputStrings.get(i).split(" ");
for (int j = 0; j < words.length; j++) {
// System.out.println(words[j]);
if (words[j].contains("+")) {
in++;
}
if (words[j].contains("-")) {
out++;
}
}
}
// System.out.println(in);
// System.out.println(out);
outstring = in + " passengers got on the bus and " + out + " passengers got out of the bus";
} else if (Query.get(0).equalsIgnoreCase("2")) {
String s = "";
double highFare, midFare, lowFare;
int h_fare = 0, m_fare = 0, l_fare = 0, in = 0, out = 0, occupied = 0;
highFare = capacity + (capacity * 0.6);
s = String.format("%.1f", highFare);
highFare = Double.parseDouble(s);
// System.out.println(highFare);
midFare = capacity + (capacity * 0.3);
s = String.format("%.1f", midFare);
midFare = Double.parseDouble(s);
// System.out.println(midFare);
lowFare = capacity;
s = String.format("%.1f", lowFare);
lowFare = Double.parseDouble(s);
// System.out.println(lowFare);
for (int i = 0; i < listOfInputStrings.size(); i++) {
in = 0;
out = 0;
String[] words = listOfInputStrings.get(i).split(" ");
for (int j = 0; j < words.length; j++) {
// System.out.println(words[j]);
if (words[j].contains("+")) {
in++;
}
if (words[j].contains("-")) {
out++;
}
}
occupied += (in - out);
// System.out.println(in + " "+ out + " " + occupied);
if (occupied <= Math.round((double) capacity / 4)) {
h_fare += in;
} else if (occupied > Math.round((double) capacity / 4)
&& occupied <= Math.round((double) capacity / 2)) {
m_fare += in;
} else if (occupied > Math.round((double) capacity / 2)) {
l_fare += in;
}
}
// System.out.println(lowFare + " " + l_fare + "\n" + midFare + " " + m_fare +
// "\n" + highFare + " " + h_fare + "\n");
// System.out.println(Math.round((double)10/4));
outstring = h_fare + " passengers traveled with a fare of " + highFare + ", " + m_fare
+ " passengers traveled with a fare of " + midFare + " and " + l_fare
+ " passengers traveled with a fare of " + lowFare;
// System.out.println(outstring);
// outstring = "6 passengers traveled with a fare of 28.8, 13 passengers
// traveled with a fare of 23.4 and 10 passengers traveled with a fare of 18.0";
} else if (Query.get(0).equalsIgnoreCase("3")) {
String s = "";
double highFare, midFare, lowFare, fare = 0;
String s1 = "+" + Query.get(1).substring(1, Query.get(1).length());
String s2 = "-" + Query.get(1).substring(1, Query.get(1).length());
int h_fare = 0, m_fare = 0, l_fare = 0, in = 0, out = 0, occupied = 0, count;
highFare = capacity + (capacity * 0.6);
s = String.format("%.1f", highFare);
highFare = Double.parseDouble(s);
// System.out.println(highFare);
midFare = capacity + (capacity * 0.3);
s = String.format("%.1f", midFare);
midFare = Double.parseDouble(s);
// System.out.println(midFare);
lowFare = capacity;
s = String.format("%.1f", lowFare);
lowFare = Double.parseDouble(s);
// System.out.println(lowFare);
for (int i = 0; i < listOfInputStrings.size(); i++) {
in = 0;
out = 0;
count = 0;
String[] words = listOfInputStrings.get(i).split(" ");
for (int j = 0; j < words.length; j++) {
// System.out.println(words[j]);
if (words[j].contains("+")) {
in++;
}
if (words[j].contains("-")) {
out++;
}
if (words[j].contains(s1)) {
count = 1;
}
}
occupied += (in - out);
// System.out.println(in + " "+ out + " " + occupied);
if (occupied <= Math.round((double) capacity / 4)) {
if (count == 1) {
fare += highFare;
}
} else if (occupied > Math.round((double) capacity / 4)
&& occupied <= Math.round((double) capacity / 2)) {
if (count == 1) {
fare += midFare;
}
} else if (occupied > Math.round((double) capacity / 2)) {
if (count == 1) {
fare += lowFare;
}
}
}
// System.out.println(fare);
outstring = "Passenger" + Query.get(1) + " spent a total fare of " + fare;
System.out.println(outstring);
} else if (Query.get(0).equalsIgnoreCase("4")) {
int count = 0;
String s = Query.get(1).substring(1, Query.get(1).length());
for (int i = 0; i < listOfInputStrings.size(); i++) {
String[] words = listOfInputStrings.get(i).split(" ");
// System.out.println(words.length);
for (int j = 0; j < words.length; j++) {
// System.out.println(words[j]);
// System.out.println(words[j].contains(s1));
if (words[j].contains(s)) {
count++;
}
}
}
if (count % 2 == 1) {
count = count / 2 + 1;
} else if (count % 2 == 0) {
count /= 2;
}
outstring = "Passenger " + s + " has got on the bus for " + count + " times";
// System.out.println(outstring);
} else if (Query.get(0).equalsIgnoreCase("5")) {
int count = 0;
String s = Query.get(1).substring(1, Query.get(1).length());
for (int i = 0; i < listOfInputStrings.size(); i++) {
String[] words = listOfInputStrings.get(i).split(" ");
// System.out.println(words.length);
for (int j = 0; j < words.length; j++) {
// System.out.println(words[j]);
// System.out.println(words[j].contains(s1));
if (words[j].contains(s)) {
count++;
}
}
}
if (count % 2 == 1) {
outstring = "Passenger " + s + " was inside the bus at the end of the trip";
} else if (count % 2 == 0) {
outstring = "Passenger " + s + " was not inside the bus at the end of the trip";
}
// System.out.println(count);
// System.out.println(outstring);
}
return outstring;
}
}
Getting error is
Results :
Failed tests: testOutput12(com.fresco.BusProbTest): expected:<-1911513968> but was:<-185797987>
testOutput13(com.fresco.BusProbTest): expected:<-1911513968> but was:<-185797987>
testOutput11(com.fresco.BusProbTest): expected:<-1911513968> but was:<-185797987>
testOutput14(com.fresco.BusProbTest): expected:<-1911513968> but was:<-185797987>
testOutput15(com.fresco.BusProbTest): expected:<-1911513968> but was:<-185797987>
testOutput16(com.fresco.BusProbTest): expected:<-1911513968> but was:<-185797987>
testOutput17(com.fresco.BusProbTest): expected:<-1911513968> but was:<-185797987>
testOutput18(com.fresco.BusProbTest): expected:<-1911513968> but was:<-185797987>
Tests run: 8, Failures: 8, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
Test case which checking code is as below which are un editable -
package com.fresco;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class BusProbTest {
BusProb bp;
ALPresent alp;
public BusProbTest() {
}
@Before
public void setUp() {
bp=new BusProb();
alp=new ALPresent();
}
int capacity;
int stops;
List<String> listOfInputs=new ArrayList<>();
@Test
public void testOutput11() throws IOException {
if(alp.isALPresent())
{
capacity=8;
stops=5;
listOfInputs.add("+1001 +1002 +1003 +1004 +1005 +1015");
listOfInputs.add("-1001 -1003 -1005 +1006 +1007 -1015");
listOfInputs.add("+1008 -1004 -1002 +1009 -1006 +1001");
listOfInputs.add("-1008 +1010 -1009 +1005 -1007");
listOfInputs.add("+1011 -1010 -1005");
String query="1";
String actual=bp.output(capacity, stops, listOfInputs, query);
assertEquals(1106934417, actual.hashCode());
}
else
{
assertEquals(-1911513968, -185797987);
}
}
@Test
public void testOutput12() throws IOException {
if(alp.isALPresent())
{
capacity=18;
stops=8;
listOfInputs.add("+12412 +5465 +5241 +52425 +21032 +21315");
listOfInputs.add("+5645 +56412 +41524 -12412 -21032 -21315");
listOfInputs.add("+56456 +46423 +12412 -5645 -52425 -5241 -5465");
listOfInputs.add("+1543 +1873 +28466 -12412 -56456 -41524");
listOfInputs.add("+35456 +36874 +4654 +12412 -1543");
listOfInputs.add("+4879 +4131 +532 +562 -28466 -12412");
listOfInputs.add("+65446 +10412 +12412 +68723 -532");
listOfInputs.add("+7545 +8651 -4131 -562");
String query="2";
String actual=bp.output(capacity, stops, listOfInputs, query);
assertEquals(-1020571650, actual.hashCode());
}
else
{
assertEquals(-1911513968, -185797987);
}
}
@Test
public void testOutput13() throws IOException {
if(alp.isALPresent())
{
capacity=30;
stops=12;
listOfInputs.add("+100 +101 +102 +103 +104 +105 +106 +107 +108 +109");
listOfInputs.add("+110 +111 +112 +113 +114 +115 +116 +117 +118 +119 -104 -107");
listOfInputs.add("+120 +121 +122 +123 +124 +125 -101 -111 -115 -112 -102");
listOfInputs.add("+126 +127 +128 +129 +130 +131 +132 +133 -120 -110");
listOfInputs.add("+134 +135 +136 +137 +138 -100 -103");
listOfInputs.add("+101 +104 +139 +140 -105 -106 -108 -109");
listOfInputs.add("-113 -114 -116 -117 -118 -119 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137");
listOfInputs.add("+141 +142");
listOfInputs.add("+143 +144 +121 +122 +123 +124 +125 +126 -101 -139 -138 -104");
listOfInputs.add("+145 +146 +147 +148 +149 -143 -144 -124 -125 -126");
listOfInputs.add("+150 +151 +152 +153 +154 +155 +101 +125 +124 +104 -123 -145 -146");
listOfInputs.add("+156 -101 -147 -148 -149 -150 -154");
String query="2";
String actual=bp.output(capacity, stops, listOfInputs, query);
assertEquals(98797057, actual.hashCode());
}
else
{
assertEquals(-1911513968, -185797987);
}
}
@Test
public void testOutput14() throws IOException {
if(alp.isALPresent())
{
capacity=8;
stops=5;
listOfInputs.add("+1001 +1002 +1003 +1004 +1005 +1015");
listOfInputs.add("-1001 -1003 -1005 +1006 +1007 -1015");
listOfInputs.add("+1008 -1004 -1002 +1009 -1006 +1001");
listOfInputs.add("-1008 +1010 -1009 +1005 -1007");
listOfInputs.add("+1011 -1010 -1005");
String query="5, 1001";
String actual=bp.output(capacity, stops, listOfInputs, query);
assertEquals(542502334, actual.hashCode());
}
else
{
assertEquals(-1911513968, -185797987);
}
}
@Test
public void testOutput15() throws IOException {
if(alp.isALPresent())
{
capacity=18;
stops=8;
listOfInputs.add("+12412 +5465 +5241 +52425 +21032 +21315");
listOfInputs.add("+5645 +56412 +41524 -12412 -21032 -21315");
listOfInputs.add("+56456 +46423 +12412 -5645 -52425 -5241 -5465");
listOfInputs.add("+1543 +1873 +28466 -12412 -56456 -41524");
listOfInputs.add("+35456 +36874 +4654 +12412 -1543");
listOfInputs.add("+4879 +4131 +532 +562 -28466 -12412");
listOfInputs.add("+65446 +10412 +12412 +68723 -532");
listOfInputs.add("+7545 +8651 -4131 -562");
String query="5, 28466";
String actual=bp.output(capacity, stops, listOfInputs, query);
assertEquals(503829939, actual.hashCode());
}
else
{
assertEquals(-1911513968, -185797987);
}
}
@Test
public void testOutput16() throws IOException {
if(alp.isALPresent())
{
capacity=30;
stops=12;
listOfInputs.add("+100 +101 +102 +103 +104 +105 +106 +107 +108 +109");
listOfInputs.add("+110 +111 +112 +113 +114 +115 +116 +117 +118 +119 -104 -107");
listOfInputs.add("+120 +121 +122 +123 +124 +125 -101 -111 -115 -112 -102");
listOfInputs.add("+126 +127 +128 +129 +130 +131 +132 +133 -120 -110");
listOfInputs.add("+134 +135 +136 +137 +138 -100 -103");
listOfInputs.add("+101 +104 +139 +140 -105 -106 -108 -109");
listOfInputs.add("-113 -114 -116 -117 -118 -119 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137");
listOfInputs.add("+141 +142");
listOfInputs.add("+143 +144 +121 +122 +123 +124 +125 +126 -101 -139 -138 -104");
listOfInputs.add("+145 +146 +147 +148 +149 -143 -144 -124 -125 -126");
listOfInputs.add("+150 +151 +152 +153 +154 +155 +101 +125 +124 +104 -123 -145 -146");
listOfInputs.add("+156 -101 -147 -148 -149 -150 -154");
String query="3, 101";
String actual=bp.output(capacity, stops, listOfInputs, query);
assertEquals(1609639898, actual.hashCode());
}
else
{
assertEquals(-1911513968, -185797987);
}
}
@Test
public void testOutput17() throws IOException {
if(alp.isALPresent())
{
capacity=18;
stops=8;
listOfInputs.add("+12412 +5465 +5241 +52425 +21032 +21315");
listOfInputs.add("+5645 +56412 +41524 -12412 -21032 -21315");
listOfInputs.add("+56456 +46423 +12412 -5645 -52425 -5241 -5465");
listOfInputs.add("+1543 +1873 +28466 -12412 -56456 -41524");
listOfInputs.add("+35456 +36874 +4654 +12412 -1543");
listOfInputs.add("+4879 +4131 +532 +562 -28466 -12412");
listOfInputs.add("+65446 +10412 +12412 +68723 -532");
listOfInputs.add("+7545 +8651 -4131 -562");
String query="3, 12412";
String actual=bp.output(capacity, stops, listOfInputs, query);
assertEquals(1325126904, actual.hashCode());
}
else
{
assertEquals(-1911513968, -185797987);
}
}
@Test
public void testOutput18() throws IOException {
if(alp.isALPresent())
{
capacity=30;
stops=12;
listOfInputs.add("+100 +101 +102 +103 +104 +105 +106 +107 +108 +109");
listOfInputs.add("+110 +111 +112 +113 +114 +115 +116 +117 +118 +119 -104 -107");
listOfInputs.add("+120 +121 +122 +123 +124 +125 -101 -111 -115 -112 -102");
listOfInputs.add("+126 +127 +128 +129 +130 +131 +132 +133 -120 -110");
listOfInputs.add("+134 +135 +136 +137 +138 -100 -103");
listOfInputs.add("+101 +104 +139 +140 -105 -106 -108 -109");
listOfInputs.add("-113 -114 -116 -117 -118 -119 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137");
listOfInputs.add("+141 +142");
listOfInputs.add("+143 +144 +121 +122 +123 +124 +125 +126 -101 -139 -138 -104");
listOfInputs.add("+145 +146 +147 +148 +149 -143 -144 -124 -125 -126");
listOfInputs.add("+150 +151 +152 +153 +154 +155 +101 +125 +124 +104 -123 -145 -146");
listOfInputs.add("+156 -101 -147 -148 -149 -150 -154");
String query="4, 104";
String actual=bp.output(capacity, stops, listOfInputs, query);
assertEquals(1910926845, actual.hashCode());
}
else
{
assertEquals(-1911513968, -185797987);
}
}
}
Metadata
Metadata
Assignees
Labels
No labels