Web Analytics Made Easy -
StatCounter textbook example that gives 'Cannot find symbol' error - CodingForum

Announcement

Collapse
No announcement yet.

textbook example that gives 'Cannot find symbol' error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • textbook example that gives 'Cannot find symbol' error

    New to programming but I've typed this code directly from my text book example yet keep getting a 'Cannot find symbol' error referring to 'DoubleClass' as noted below. Any help is greatly appreciated as always.

    DataComparison.java:81: error: cannot find symbol
    public static void calculateAverage(Scanner inp, DoubleClass courseAvg)
    symbol: class DoubleClass
    location: class DataComparison

    DataComparison.java:99: error: cannot find symbol
    public static void printResult(PrintWriter outp, String courseId, int groupNo, DoubleClass avg)
    symbol: class DoubleClass
    location: class DataComparison

    DataComparison.java:15: error: cannot find symbol
    DoubleClass avg1 = new DoubleClass(); //average for a course in group 1
    symbol: class DoubleClass


    Code:
    import java.io.*;
    import java.util.*;
    
    public class DataComparison
    {
    	public static void main (String[] args)
    									throws FileNotFoundException
    	{
    					//Step 1
    		String courseId1;			//course ID for group 1
    		String courseId2;			//course ID for group 2
    		
    		int numberOfCourses;
    		
    		DoubleClass avg1 = new DoubleClass();	//average for a course in group 1
    		DoubleClass avg2 = new DoubleClass();	//average for a course in group 2
    		
    		double avgGroup1;		//average group 1
    		double avgGroup2;		//average group 2
    		
    		
    					//Step 2 Open the input and output files
    		Scanner group1 = new Scanner(new FileReader("group1.txt"));
    		Scanner group2 = new Scanner(new FileReader("group2.txt"));
    		
    		PrintWriter outfile = new PrintWriter("student.out");
    		
    		
    		avgGroup1 = 0.0;					//Step 3
    		avgGroup2 = 0.0;					//Step 4
    		
    		numberOfCourses = 0;
    		
    				//print heading: Step 6
    		outfile.println("Course ID   Group No   Course Average");
    		
    		while (group1.hasNext() && group2.hasNext())
    			{
    				courseId1 = group1.next();
    				courseID2 = group2.next();
    				
    				if (!courseId1.equals(courseId2))
    				{
    					System.out.println("Data error: Course IDs do not match.");
    					System.out.println("Program terminates.");
    					outfile.println("Data error: Course Ids do not match.");
    					outfile.println("Program terminates.");
    					outfile.close();
    					return;
    				}
    				else
    				{
    					calculateAverage(group1,  avg1);
    					calculateAverage(group2,  avg2);
    					printResult(outfile, courseId1, 1, avg1);
    					printResult(outfile, courseId2, 2, avg2);
    					avgGroup1 = avgGroup1 + avg1.getNum();
    					avgGroup2 = avgGroup2 + avg2.getNum();
    					outfile.println();
    					numberofCourses++;
    				}
    			}
    			
    			if (group1.hasNext() && !group2.hasNext())
    				System.out.println("Ran out of data for group 2 before group 1.");
    			
    			else if (!group1.hasNext() && group2.hasNext())
    				System.out.println("Ran out of data for group 1 before group 2.");
    			
    			else
    			{
    				outfile.printf("Avg for group 1: %.2f %n", (avgGroup1 / numberOfCourses));
    				outfile.prtinf("Avg for group 2: %.2f %n", (avgGroup2 / numberOfCourses));
    			}
    			
    			group1.close();
    			group2.close();
    			outfile.close();
    		}
    		
    		public static void calculateAverage(Scanner inp, DoubleClass courseAvg)
    		{
    			double totalScore = 0.0;
    			
    			int numberOfStudents = 0;
    			int score = 0;
    			
    			score = inp.nextInt();
    			
    			while (score != -999)
    			{
    				totalScore = totalScore + score;
    				numberOfStudents++;
    				score = inp.nextInt();
    			}
    			
    			courseAvg.setNum(totalScore / numberOfStudents);
    		}
    		public static void printResult(PrintWriter outp, String courseId, int groupNo, DoubleClass avg)
    		{
    			if (groupNo == 1)
    				outp.print("  " + courseId + "   ");
    			else 
    				outp.print("        ");
    				
    			outp.printf("%9d %15.2f%n", groupNo, avg.getNum());
    		}
    	}

  • #2
    Java does not have a 'DoubleClass' class. There is a 'Double' class, but it doesn't appear to match what you have for methods.
    So this is a class you are expected to create yourself.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

    Comment


    • #3
      Originally posted by Fou-Lu View Post
      Java does not have a 'DoubleClass' class. There is a 'Double' class, but it doesn't appear to match what you have for methods.
      So this is a class you are expected to create yourself.
      Ok, thanks for the reply. I would not suggest anyone use the Malik Java Programming - From Problem Analysis to Program Design textbook for a beginning Java book.

      The reviews on Amazon are horrible and the book does a poor job describing the "why" of what you're doing and there are numerous coding errors and typos that I've come across.
      Last edited by jwombles; Sep 13, 2011, 09:12 AM.

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎