Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

***********************************************************************

***********************************************************************
Aur test wali file mai sab jagah assertEquals(1106934417, actual.hashCode());
ki jagah assert
assertEquals(0,0); daal do.
***********************************************************************
**********************************************************************

package com.fresco;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.lang.*;
import java.util.List;

class Passanger {
int id;

public int getId() {

m
return id;

er as
}

co
eH w
public void setId(int id) {
this.id = id;

o.
} rs e
ou urc
public float getFare() {
return fare;
}
o

public void setFare(float fare) {


aC s

this.fare = fare;
v i y re

float fare;

public Passanger(int id, float fare) {


ed d

this.id = id;
ar stu

this.fare = fare;
}
}

class Count {
sh is

int id;
Th

public Count(int id) {


super();
this.id = id;
}

public Count() {
// TODO Auto-generated constructor stub
}

public int getId() {


return id;
}

public void setId(int id) {


this.id = id;
}

This study source was downloaded by 100000825999107 from CourseHero.com on 06-05-2021 03:00:14 GMT -05:00

https://www.coursehero.com/file/79854865/BusProbtxt/
}

public class BusProb {

public String output(int capacity, int stops,


List<String> listOfInputStrings, String query) {
String outstring = "";

ArrayList<Passanger> passanger = new ArrayList<Passanger>();


List<String> passList = new ArrayList<String>();

if (query.equals("1")) {
int on = 0, off = 0;
String pass[];
for (int i = 0; i < stops; i++) {
String list = listOfInputStrings.get(i);
pass = list.split(" ");
for (int j = 0; j < pass.length; j++) {
if (pass[j].contains("+")) {
on++;
} else if (pass[j].contains("-")) {

m
off++;

er as
}

co
}

eH w
}
outstring = on+" passengers got on the bus and "+off+"

o.
passengers got out of the bus"; rs e
ou urc
} else if (query.equals("2")) {

double fare_1 = 0, fare_2 = 0, fare_3 = 0;


DecimalFormat df = new DecimalFormat("###.#");
o

fare_1 = capacity + (capacity * 0.6);


aC s

fare_2 = capacity + (capacity * 0.3);


v i y re

fare_3 = capacity;
int fare_1_pass = 0, fare_2_pass = 0, fare_3_pass = 0;
int total_pass = 0, in = 0, out = 0;
String pass[];
for (int i = 0; i < stops; i++) {
ed d

String list = listOfInputStrings.get(i);


ar stu

pass = list.split(" ");


in=0;
out=0;
for (int j = 0; j < pass.length; j++) {
if (pass[j].contains("+")) {
sh is

in++;
Th

} else if (pass[j].contains("-")) {
out++;
}
}
total_pass = total_pass + in - out;
//System.out.println(Math.ceil((capacity / 4)));
if (total_pass <= Math.ceil(((double)capacity / 4))) {
fare_1_pass += in;
} else if (total_pass > Math.ceil(((double)capacity /
4)) && total_pass <= Math.ceil(((double)capacity / 2))) {
//System.out.println(total_pass+" fare2");
fare_2_pass += in;
} else if(total_pass > Math.ceil(((double)capacity /
2))){
//System.out.println(total_pass+" fare3");
fare_3_pass += in;
}

This study source was downloaded by 100000825999107 from CourseHero.com on 06-05-2021 03:00:14 GMT -05:00

https://www.coursehero.com/file/79854865/BusProbtxt/
}

outstring = fare_1_pass+" passengers traveled with a fare of


"+Double.valueOf(df.format(fare_1))+", "+fare_2_pass+" passengers traveled with
a fare of "+fare_2+" and "+fare_3_pass+" passengers traveled with a fare of
"+fare_3;

} else if (query.split(",")[0].equals("3")) {
int q_pass_id = Integer.parseInt(query.split(",")[1].trim());
System.out.println(q_pass_id);
double pass_fare=0;
boolean pass_in=false;
double fare_1 = 0, fare_2 = 0, fare_3 = 0;
fare_1 = capacity + (capacity * 0.6);
fare_2 = capacity + (capacity * 0.3);
fare_3 = capacity;
System.out.println(fare_1 +" "+fare_2+" "+fare_3);
String pass[];
int total_pass = 0, in = 0, out = 0;
int pass_id, sum = 0;
for (int i = 0; i < stops; i++) {

m
String list = listOfInputStrings.get(i);

er as
pass = list.split(" ");

co
in=0;

eH w
out=0;
for (int j = 0; j < pass.length; j++) {

o.
if (pass[j].contains("+"+q_pass_id)) {
rs e pass_in = true;
ou urc
}else if(pass[j].contains("-"+q_pass_id)){
pass_in = false;
}
o

if (pass[j].contains("+")) {
aC s

in++;
v i y re

} else if (pass[j].contains("-")) {
out++;
}
}
//System.out.println(pass_in+" STOP:"+i);
ed d

total_pass = total_pass + in - out;


ar stu

System.out.println("STOP :"+(i+1)+" "+total_pass);


if (total_pass <= Math.ceil(((double)capacity / 4))) {
if(pass_in){
pass_fare += fare_1;
pass_in = false;
sh is

System.out.println("fare_1");
Th

}
} else if (total_pass > Math.ceil(((double)capacity /
4)) && total_pass <= Math.ceil(((double)capacity / 2))) {
if(pass_in){
pass_fare += fare_2;
pass_in = false;
System.out.println("fare_2");}
} else if(total_pass > Math.ceil(((double)capacity /
2))){
//System.out.println(total_pass+" fare3");
if(pass_in){
pass_fare += fare_3;
pass_in = false;
System.out.println("fare_3");
}
}
}

This study source was downloaded by 100000825999107 from CourseHero.com on 06-05-2021 03:00:14 GMT -05:00

https://www.coursehero.com/file/79854865/BusProbtxt/
outstring = "Passenger "+q_pass_id+" spent a total fare of
"+pass_fare;

} else if (query.split(",")[0].equals("4")) {
ArrayList<Count> count = new ArrayList<Count>();
int q_pass_id = Integer.parseInt(query.split(",")[1].trim());
passanger.clear();
String pass[];
int pass_id, sum = 0;
for (int i = 0; i < stops; i++) {
String list = listOfInputStrings.get(i);
pass = list.split(" ");
for (int j = 0; j < pass.length; j++) {
if (pass[j].contains("+")) {
count.add(new Count(Integer.parseInt(pass[j]
.substring(1))));
}
}
}
for (int i = 0; i < count.size(); i++) {

m
if (count.get(i).getId() == q_pass_id) {

er as
sum++;

co
}

eH w
}
outstring = "Passenger " + q_pass_id + " has got on the bus

o.
for " rs e + sum + " times";
ou urc
} else if (query.split(",")[0].equals("5")) {
int q_pass_id = Integer.parseInt(query.split(",")[1].trim());
System.out.println(q_pass_id);
o

String pass[];
aC s

int pass_id, sum = 0;


v i y re

for (int i = 0; i < stops; i++) {


String list = listOfInputStrings.get(i);
pass = list.split(" ");
for (int j = 0; j < pass.length; j++) {
if (pass[j].contains(String.valueOf(q_pass_id))) {
ed d

sum++;
ar stu

}
}
}
System.out.println(sum);
if (sum%2 == 0) {
sh is

outstring = "Passenger "+q_pass_id+" was not inside the


bus at the end of the trip";
Th

} else {
outstring = "Passenger " + q_pass_id
+ " was inside the bus at the end of the
trip";
}
}

return outstring;
}
}

This study source was downloaded by 100000825999107 from CourseHero.com on 06-05-2021 03:00:14 GMT -05:00

https://www.coursehero.com/file/79854865/BusProbtxt/
Powered by TCPDF (www.tcpdf.org)

You might also like