Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Mark Kaichou
Greenhorn
+ Follow
2
Posts
1
Threads
0
Cows
since Feb 13, 2012
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
Ranch Hand Scavenger Hunt
Number Posts (2/100)
Number Threads Started (1/100)
Number Cows Received (0/5)
Number Likes Received (0/10)
Number Likes Granted (0/20)
Set bumper stickers in profile (0/3)
Report a post to the moderators (0/1)
Edit a wiki page (0/1)
Create a post with an image (0/2)
Greenhorn Scavenger Hunt
First Post
Number Posts (2/10)
Number Threads Started (1/10)
Number Likes Received (0/3)
Number Likes Granted (0/3)
Set bumper stickers in profile (0/1)
Set signature in profile
Search for a post/thread (0/3)
Set a watch on a thread
Save thread as a bookmark
Create a post with an image (0/1)
Recent posts by Mark Kaichou
Int cannot be dereferenced
Ahhhhh, I see, silly me, thanks for the prompt reply guys!
show more
12 years ago
Beginning Java
Int cannot be dereferenced
I've been spending hours and hours trying to figure what have I done wrong to no avail, I've spent a load of time online trying to figure it out but I still can't!!!
Error's at line 154 :/
/ ** * @(#)Triathlon Timing.java * * * @author * @version 1.00 2012/1/17 */ import java.util.*; import java.text.*; public class Triathlon { static char choice=' '; static Scanner input = new Scanner(System.in).useDelimiter("\r\n"); static String[] name = new String[10]; static int[] runMinutes = new int[10]; static int[] runHours = new int[10]; static int[] runSeconds = new int[10]; static int[] swimHours = new int[10]; static int[] swimMinutes = new int[10]; static int[] swimSeconds = new int[10]; static int[] cycleHours = new int[10]; static int[] cycleMinutes = new int[10]; static int[] cycleSeconds = new int[10]; static int[] totalSwimSeconds = new int[10]; static int[] totalCycleSeconds = new int[10]; static int[] totalRunSeconds = new int[10]; static int[] totalSeconds = new int[10]; static int[] totalTiming = new int[10]; static int[] totalTimingHours = new int[10]; static int[] totalTimingMinutes = new int[10]; static int[] totalTimingSeconds = new int[10]; static int i = 0; public static void main(String[] args) throws Exception { int participants = 0; int remainder; do { System.out.println("**********Triathlon Timing**********"); System.out.println("1) Enter Participants Timing"); System.out.println("2) Display all participant's timing"); System.out.println("3) Display the Winner"); System.out.println("4) Exit Program"); System.out.println("************************************"); //Prompt and read inputs System.out.print("Please select your choice <1-4>: "); choice=(char) System.in.read(); System.in.read(); // dummy read: reads CR System.in.read(); // dummy read: reads LF switch(choice) { case '1': System.out.print("Enter Number of Participants <Max 10>: "); participants = input.nextInt(); for (i=0; i<participants; i++) { System.out.print("Enter Participant's name: "); name[i]=input.next(); System.out.println("Enter Timing for Swimming: "); System.out.print("Enter Number of Hours: "); swimHours[i]=input.nextInt(); do { System.out.print("Enter Number of Minutes: "); swimMinutes[i]=input.nextInt(); if(swimMinutes[i]>59) { System.out.println("Minutes cannot be more than 59, please Reenter"); } }while(swimMinutes[i]>59); do { System.out.print("Enter Number of Seconds: "); swimSeconds[i]=input.nextInt(); if(swimSeconds[i]>59) { System.out.println("Seconds cannot be more than 59, please reenter"); } }while(swimSeconds[i]>59); System.out.println("Enter timing for Bike: "); System.out.print("Enter Number of Hours: "); cycleHours[i]=input.nextInt(); do { System.out.print("Enter Number of Minutes: "); cycleMinutes[i]=input.nextInt(); if(cycleMinutes[i]>59) { System.out.println("Minutes cannot be more than 59, please Reenter"); } }while(cycleMinutes[i]>59); do { System.out.print("Enter Number of Seconds: "); cycleSeconds[i]=input.nextInt(); if(cycleSeconds[i]>59) { System.out.println("Seconds cannot be more than 59, please reenter"); } }while(cycleSeconds[i]>59); System.out.println("Enter timing for Running: "); System.out.print("Enter Number of Hours: "); runHours[i]=input.nextInt(); do { System.out.print("Enter Number of Minutes: "); runMinutes[i]=input.nextInt(); if(runMinutes[i]>59) { System.out.println("Minutes cannot be more than 59, please Reenter"); } }while(runMinutes[i]>59); do { System.out.print("Enter Number of Seconds: "); runSeconds[i]=input.nextInt(); if(runSeconds[i]>59) { System.out.println("Seconds cannot be more than 59, please reenter"); } }while(runSeconds[i]>59); }while(participants>i); break; case '2': System.out.println("********Triathlon Timing(All)**************"); System.out.println("*******************************************"); System.out.println("Name\tSwim\tBike\tRun\tTotal\t**"); for(i=0; i<participants; i++) { totalSwimSeconds[i] = (swimHours[i]*60)*60 + swimMinutes[i]*60 + swimSeconds[i]; totalRunSeconds[i] = (runHours[i]*60)*60 + runMinutes[i]*60 + runSeconds[i]; totalCycleSeconds[i] = (cycleHours[i]*60)*60 + cycleMinutes[i]*60 + cycleSeconds[i]; totalSeconds[i] = totalCycleSeconds[i] + totalRunSeconds[i] + totalSwimSeconds[i]; totalTimingHours[i] = totalSeconds[i] / 3600; remainder = totalSeconds[i] % 3600; totalTimingMinutes[i] = remainder / 60; totalTimingSeconds[i] = remainder % 60; System.out.print(name[i]+"\t"); System.out.print(swimHours[i]+":"+swimMinutes[i]+":"+swimSeconds[i]); System.out.print("\t"+cycleHours[i]+":"+cycleMinutes[i]+":"+cycleSeconds[i]); System.out.print("\t"+runHours[i]+":"+runMinutes[i]+":"+runSeconds[i] ); System.out.print("\t"+totalTimingHours[i]+":"+totalTimingMinutes[i]+":"+totalTimingSeconds[i]); System.out.println(" "); }while(i>name.length); break; case '3': int topTiming; topTiming = totalSeconds[0]; for(i=0;i<topTiming.length;i++) { if(totalSeconds[i]>topTiming) topTiming=totalSeconds[i]; System.out.println("The winner is: "+name[i]); System.out.println("***********************************************"); System.out.println("Name\tSwim\tBike\tRun\tTotal\t**"); System.out.println("***********************************************"); System.out.print(swimHours[i]+":"+swimMinutes[i]+":"+swimSeconds[i]); System.out.print("\t"+cycleHours[i]+":"+cycleMinutes[i]+":"+cycleSeconds[i]); System.out.print("\t"+runHours[i]+":"+runMinutes[i]+":"+runSeconds[i] ); System.out.print("\t"+totalTimingHours[i]+":"+totalTimingMinutes[i]+":"+totalTimingSeconds[i]); } break; case '4': System.out.println("Thank you for using this program."); break; default: System.out.println("Error, please enter only <1-4>"); break; }//End Switch }while(choice!='4'); //end of do-while loop }//End Main() }//End of class
show more
12 years ago
Beginning Java