Fall2006.SmallExample History

Hide minor edits - Show changes to output

Changed lines 1-2 from:
!!!Compare Java and Python
!!!Comparing Java and Python
Added lines 3-6:
Given the following task, write a program in the language of your choice (here we consider only Java and Python).

Things to consider include: How many times the user has to look up something up (e.g., search the language API), how many compiler errors; how many semantic errors; how many "headache" errors, i.e., errors that are hard to identify and/or fix (e.g., there is one such error remaining in the Java code below - see if you can find it).
Added lines 1-2:
!!!Compare Java and Python
Added lines 1-56:
'''Task:''' A meeting is scheduled to start at 3:15pm. It will end at 4pm, if the building where the meeting is held is J.C Long, or at 3:50pm otherwise.

'''Input:''' The building. (Assume error-free input.)

'''Output:''' The meeting's start and end time.

First, Python:

(:source lang=Python tabwidth=3 -trim :)
def meetingTime(building):
start = "3:15pm"
if (building == "J.C. Long"):
end = "4:00pm"
end = "3:50pm"

return start, end

building = raw_input()
print meetingTime(building)

Now, Java:

(:source lang=Java tabwidth=3 -trim :)
import java.util.Scanner;

public class MeetingTime
public static void main (String[] args)
MeetingTime obj = new MeetingTime();
Scanner sc = new Scanner(System.in);
String building = sc.next();
String time[] = obj.getMeetingTime(building);
System.out.println(time[0]+ "," + time[1]);

public String[] getMeetingTime(String building)
String start = "3:15pm";
String end;
if (building == "J.C. Long")
end = "4:00pm";
end = "3:50pm";

String answer[] = new String[2];
answer[0] = start;
answer[1] = end;
return answer;