Professional Documents
Culture Documents
This Study Resource Was
This Study Resource Was
***********************************************************************
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;
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
this.fare = fare;
v i y re
float fare;
this.id = id;
ar stu
this.fare = fare;
}
}
class Count {
sh is
int id;
Th
public Count() {
// TODO Auto-generated constructor stub
}
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/
}
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")) {
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
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/
}
} 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
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
sum++;
ar stu
}
}
}
System.out.println(sum);
if (sum%2 == 0) {
sh is
} 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)