average scores/ due today/ 2 errors has to do with the panel set up

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

41 Replies - 1350 Views - Last Post: 29 July 2011 - 04:58 PM Rate Topic: -----

#16 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10176
  • View blog
  • Posts: 37,571
  • Joined: 27-December 08

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 06:52 AM

Exactly- private members can only be accessed within the class.

Also, something I've seen that trips people up sometimes is that the following case is legal b/c other.x is accessed within the class A. If I tried to access other.x outside of class A, the code would fail to compile.
class A{
    private int x;

    public A(A other){ this.x = other.x; }
}


Was This Post Helpful? 1
  • +
  • -

#17 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 07:25 AM

The if...else structure is an example of a repetition structure.

true or false.? to me it's false because if it's a false statement it goes on possibly outside the loop?

I'm worried because the logical side of my brain is not functioning properly.
Was This Post Helpful? 0
  • +
  • -

#18 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 07:30 AM

nevermind that's the while loop.
Was This Post Helpful? 0
  • +
  • -

#19 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 07:49 AM

ok. I answered false to this question but I think it could be true.
The itemStateChanged() method is part of the ItemEvent class. Because a clicking of a mouse is an event. But the itemStateChanged() method is a header so the event should be included in it's class? Right...? Can I get a shout out on the cash cab?
Was This Post Helpful? 0
  • +
  • -

#20 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10176
  • View blog
  • Posts: 37,571
  • Joined: 27-December 08

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 07:51 AM

Interactions with the GUI like mouse clicks, button clicks, focus changes, etc., all fire Events. These Events are objects (meaning you deal with ItemEvent objects, not the ItemEvent class), not classes, and contain certain functionalities and attributes (methods and instance fields).
Was This Post Helpful? 1
  • +
  • -

#21 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 07:52 AM

The class A statement almost looks more like VB than Java to me, but what do I know. I can't wait to put that one in my memory banks,but I'll have to do it a different day.! I will be asking questions on that one.
Was This Post Helpful? 0
  • +
  • -

#22 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 07:58 AM

driver classes call get() and set() instance methods, both public.
Was This Post Helpful? 0
  • +
  • -

#23 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 08:19 AM

okay, much better...86% not too bad for someone who didn't grow up with a microwave :). Making an A in the class and I have no idea what I'm doing. K, I have to turn my code in for my other programs but that won't happen until after 3. I'm taking you to school with me to take my other test, but It's proctored so I won't be back until after 3. We have to get that code to work! Gotta make my internet teacher happy :)
Was This Post Helpful? 0
  • +
  • -

#24 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2194
  • View blog
  • Posts: 5,222
  • Joined: 10-September 10

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 08:31 AM

I loaded the last version of your average score program, and here are the main problems:

1. frame != Frame.
2. Panel topPanel(); is silly. (What's the '()' after topPanel?)
3. totalGrades in your constructor is undefined

Fix those things and your program will compile and run. There are still problems with displaying the results on your Panel, but that's next.

This post has been edited by GregBrannon: 29 July 2011 - 08:32 AM

Was This Post Helpful? 0
  • +
  • -

#25 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 11:37 AM

okay, I'm back. 2 tests down and one more to go, but I need to study for this one yet. But this homework is due today! Man, summer school is killer!
Was This Post Helpful? 0
  • +
  • -

#26 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 11:51 AM

View Postmacosxnerd101, on 29 July 2011 - 07:51 AM, said:

Interactions with the GUI like mouse clicks, button clicks, focus changes, etc., all fire Events. These Events are objects (meaning you deal with ItemEvent objects, not the ItemEvent class), not classes, and contain certain functionalities and attributes (methods and instance fields).




I can't wait to check out this blog! but it will not be today(sad face)

View PostGregBrannon, on 29 July 2011 - 08:31 AM, said:

I loaded the last version of your average score program, and here are the main problems:

1. frame != Frame.
2. Panel topPanel(); is silly. (What's the '()' after topPanel?)
3. totalGrades in your constructor is undefined

Fix those things and your program will compile and run. There are still problems with displaying the results on your Panel, but that's next.



Not sure where to put the frame!= Frame so, I'm going to experiment.
Was This Post Helpful? 0
  • +
  • -

#27 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 12:23 PM

I'm just too sleep deprived, this is cracking me up. It worked fine without the dang panel stuff. But that was at 4: am.
Was This Post Helpful? 0
  • +
  • -

#28 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10176
  • View blog
  • Posts: 37,571
  • Joined: 27-December 08

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 12:26 PM

You've been given a lot of good suggestions. If something isn't working, please:
-Post your revised code
-Specifically describe your problems
-Post error messages exactly as they appear on your compiler

Without this information, we are the blind leading the blind.
Was This Post Helpful? 0
  • +
  • -

#29 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 12:42 PM

at this point I don't know what I've changed, but I don't think I changed too much. I'm going to google frame != Frame to see what I can see.

errors: C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:15: cannot find symbol
symbol: class frame
public class AverageScores extends frame
^
C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:29: cannot find symbol
symbol : method setLayout(java.awt.BorderLayout)
location: class AverageScores
this.setLayout(new BorderLayout());
^
C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:30: cannot find symbol
symbol : variable totalGrades
location: class AverageScores
topPanel.setLayout(new GridLayout((totalGrades + 1),2,10,10));
^
C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:30: cannot find symbol
symbol : constructor GridLayout(<nulltype>,int,int,int)
location: class java.awt.GridLayout
topPanel.setLayout(new GridLayout((totalGrades + 1),2,10,10));
^
C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:33: cannot find symbol
symbol : method add(java.awt.Panel,java.lang.String)
location: class AverageScores
add(topPanel,BorderLayout.NORTH);
^
C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:77: cannot find symbol
symbol : method setTitle(java.lang.String)
location: class AverageScores
f.setTitle("Average Scores");
^
C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:78: cannot find symbol
symbol : method setBounds(int,int,int,int)
location: class AverageScores
f.setBounds(50, 100, 300, 400);
^
C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:79: cannot find symbol
symbol : method setLocationRelativeTo(<nulltype>)
location: class AverageScores
f.setLocationRelativeTo(null);
^
C:\Documents and Settings\CE User\Desktop\Java_OnLine_Course\chpt6\AverageScores.java:80: cannot find symbol
symbol : method setVisible(boolean)
location: class AverageScores
f.setVisible(true);
^
9 errors

Tool completed with exit code 1

/*
Name: 		Charyl Janney
Date:		July 21 2011
Project: 	Chpt5ex3
File Name:	AverageScores.java
This application calculates an average upon enter number of
scores and calculating an average of these scores.
*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
import java.io.*;

public class AverageScores extends frame
{

//Declare variable
	  Panel topPanel;
	  int nrOfTests[];
	  double sumOfAllGrades;

public AverageScores()
{

		topPanel = new Panel();
		//setup frame

		this.setLayout(new BorderLayout());
		topPanel.setLayout(new GridLayout((totalGrades + 1),2,10,10));

		//add components to frame
	    add(topPanel,BorderLayout.NORTH);
	}

 public static void main(String[] args) throws IOException
{


	try
    {

        BufferedReader input = new BufferedReader(new InputStreamReader(System.in) );

	 System.out.print( "Please enter number of tests: " );

         int nrOfTests = Integer.parseInt(input.readLine());

         //the sumOfAllGrades
         double sumOfAllGrades = 0;

         for( int i=0; i < nrOfTests; i++ )

    {

         System.out.print( "Enter the grade for Test " +(i+1)+ ": " );

         double grade = Double.parseDouble(input.readLine());

	 //add current grade to sumOffAllGrades
          sumOfAllGrades += grade;
    }
	 //calculating average
         double average = sumOfAllGrades/nrOfTests;
         System.out.println("The total grade average is: " + average);

     }

         catch( Exception e )

     {

           e.printStackTrace();
     }
     //sets Frame up
     		 AverageScores f = new AverageScores();
			 f.setTitle("Average Scores");
			 f.setBounds(50, 100, 300, 400);
			 f.setLocationRelativeTo(null);
             f.setVisible(true);
             {
		}

  }

}



Was This Post Helpful? 0
  • +
  • -

#30 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10176
  • View blog
  • Posts: 37,571
  • Joined: 27-December 08

Re: average scores/ due today/ 2 errors has to do with the panel set up

Posted 29 July 2011 - 12:43 PM

As GregBrannon said, frame != Frame. Java is case sensitive, so frame should be capitalized.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3