A person is walking/running a total distance of 9000 ft. First, she walks for 700 ft at a speed of 4 ft/sec and then runs 900 ft at a speed of 10 ft/sec. This walk/run cycle is repeated till she gets to the destination. I need help with an if/else if statement to determine if they are walking or running for the remaining distance.
public static void main(String[] args) {
Scanner k = new Scanner(System.in);
double speed_walk;
double speed_run;
double length_of_walk;
double length_of_run;
double total_destination;
double time_to_walk;
double time_to_run;
double total_time_run_walk;
double length_each_walk_run;
double total_walk_run_seg;
double time_all_seg;
double completed_segs;
double remaining_distance;
double time_last_seg;
double total_time_destination;
double total_hours;
double total_mins;
double total_sec;
System.out.print("Enter the total destination in feet: ");
total_destination = k.nextDouble();
System.out.print("Enter the length of walking in feet: ");
length_of_walk = k.nextDouble();
System.out.print("Enter the walking speed in ft/sec: ");
speed_walk = k.nextDouble();
System.out.print("Enter the length of running in feet: ");
length_of_run = k.nextDouble();
System.out.print("Enter the running speed in ft/sec: ");
speed_run = k.nextDouble();
time_to_walk = length_of_walk / speed_walk;
time_to_run = length_of_run / speed_run;
total_time_run_walk = time_to_walk+ time_to_run;
length_each_walk_run = length_of_walk + length_of_run;
total_walk_run_seg = total_destination / length_each_walk_run;
completed_segs =(int)(total_walk_run_seg);
time_all_seg = completed_segs*(total_time_run_walk);
remaining_distance = (total_walk_run_seg - 5) * length_each_walk_run;
time_last_seg = (remaining_distance - length_of_walk) / 10;
total_time_destination = time_all_seg + time_to_walk
+ time_last_seg;
System.out.println("Time it takes to walk= " + time_to_walk);
System.out.println("Time it takes to run= " + time_to_run);
System.out.println("Total time for each walk + run segment= " + total_time_run_walk );
System.out.println("Length of each walk + run segment= " + length_each_walk_run);
System.out.println("Total number of walk + run segments needed for the entire destination= " + total_walk_run_seg);
System.out.println("Time it take for all complete segments= " + time_all_seg );
System.out.println("Remaining distance to destination= " + remaining_distance);
System.out.println("Time it take for the last ft of running to destination= " + time_last_seg );
System.out.println("Total time to destination= " + total_time_destination);
}
}
Aucun commentaire:
Enregistrer un commentaire