"cannot resolve symbol" help..
Here is a very short and simpel program that won't compile after I reinstalled java on my computer.
import java.lang.Math.*;
import java.awt.*;
public class PiTest extends Frame {
public static void main(String[] p){
System.out.println("testing MATHs");
System.out.println(""+sin(10));
I get the following error:
PiTest.java:8: cannot resolve symbol
symbol : method sin (int)
location: class PiTest
System.out.println(""+sin(10));
^
[total 1553ms]
1 error
Why doesn't the compiler recognise the sine function? I have set my classpath to c:\j2sdk1.4.1_01\lib.
I don't know what I'm doing wrong...
Replace sin(10) with Math.sin(10), it should work.
import java.lang.Math.*;
import java.awt.*;
public class PiTest extends Frame {
public static void main(String[] p){
System.out.println("testing MATHs");
//System.out.println(""+sin(10));
System.out.println(""+Math.sin(10));
Similar Messages
-
Illegal start of expression and cannot resolve symbol HELP
Can someone pls help me?
These are the two problems:
--------------------Configuration: j2sdk1.4.1_02 <Default>--------------------
C:\Documents and Settings\Laila\My Documents\CMT2080\Coursework\Game\Mindboggler.java:291: illegal start of expression
public void inputJButtonActionPerformed( ActionEvent event )
^
C:\Documents and Settings\Laila\My Documents\CMT2080\Coursework\Game\Mindboggler.java:285: cannot resolve symbol
symbol: method inputJButtonActionPerformed (java.awt.event.ActionEvent)
inputJButtonActionPerformed( event);
Here is my code :
//Mind boggler quiz
//Marcelyn Samson
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.*;
import javax.swing.border.*;
import java.lang.*;
public class Mindboggler extends JFrame
// JPanel for welcome window
private JPanel welcomeJPanel;
private JPanel presetJPanel;
private JLabel titleJLabel;
private JLabel quizJLabel;
private JLabel girlJLabel, headJLabel;
private JLabel introJLabel;
private JButton startJButton;
// JPanel for questionone window
private JPanel questiononeJPanel;
private JLabel textJLabel;
private JPanel becksJPanel;
private JButton oneJButton, twoJButton, threeJButton, fourJButton, nextJButton;
//JPanel for questiontwo window
private JPanel questiontwoJPanel;
private JPanel orlandoJPanel;
private JLabel q2JLabel;
private JCheckBox lordJCheckBox;
private JCheckBox faceJCheckBox;
private JCheckBox piratesJCheckBox;
private JButton next2JButton;
private JButton inputJButton;
//JPanel for questionthree
private JPanel questionthreeJPanel;
private JPanel howmuchJPanel;
private JLabel howmuchJLabel;
private JLabel nameJLabel;
private JTextField nameJTextField;
private JLabel moneyJLabel;
private JTextField moneyJTextField;
private JButton next3JButton;
//Publics
public JPanel welcomeJFrame, questionJFrame, questiontwoJFrame, questionthreeJFrame;
//contentPane
public Container contentPane;
//no argument constructor
public Mindboggler()
createUserInterface();
//create and position components
private void createUserInterface()/////////////////////////; semo colon do not edit copy paste
//get contentPane and set layout to null
contentPane = getContentPane();
contentPane.setLayout ( null );
welcome();
//set properties of applications window
setTitle( "Mindboggler" ); // set JFrame's title bar string
setSize( 600, 400 ); // set width and height of JFrame
setVisible( true ); // display JFrame on screen
} // end method createUserInterface
public void welcome(){
// set up welcomeJPanel
welcomeJPanel = new JPanel();
welcomeJPanel.setLayout( null );
welcomeJPanel.setBounds(0, 0, 600, 400);
welcomeJPanel.setBackground( Color.GREEN );
// set up textJLabel
titleJLabel = new JLabel();
titleJLabel.setText( "Mind Boggler" );
titleJLabel.setLocation( 30, 10);
titleJLabel.setSize( 550, 70);
titleJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 30 ) );
titleJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add( titleJLabel );
// set up presetJPanel
presetJPanel = new JPanel();
presetJPanel.setLayout( null );
presetJPanel.setBounds( 150, 10, 300, 80 );
presetJPanel.setBackground( Color.GRAY );
welcomeJPanel.add( presetJPanel );
//setup Intro JLabel
introJLabel = new JLabel();
introJLabel.setText( "Think, think, think. Can you get all the questions right?" );
introJLabel.setBounds( 40, 100, 500, 200 );
introJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 18 ) );
introJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(introJLabel);
//set up head JLabel
headJLabel = new JLabel();
headJLabel.setIcon( new ImageIcon( "head.jpeg") );
headJLabel.setBounds( 540, 5, 40, 160 );
headJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(headJLabel);
//setup girlJLabel
girlJLabel = new JLabel();
girlJLabel.setIcon( new ImageIcon( "girl.Jjpeg") );
girlJLabel.setBounds( 5, 10, 60, 100 );
girlJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(girlJLabel);
//set up startJbutton
startJButton = new JButton();
startJButton.setText( "Start" );
startJButton.setBounds(250, 300, 100, 30);
startJButton.setFont( new Font( "SansSerif", Font.BOLD, 14) );
welcomeJPanel.add(startJButton);
contentPane.add(welcomeJPanel);
startJButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
question();
public void question()
//set up question one JPanel
welcomeJPanel.setVisible(false);
questiononeJPanel = new JPanel();
questiononeJPanel.setLayout( null );
questiononeJPanel.setBounds(0, 0, 600,400);
questiononeJPanel.setBackground( Color.GREEN );
// set up textJLabel
textJLabel = new JLabel();
textJLabel.setText( "Who did Beckham supposedly cheat with?" );
textJLabel.setLocation( 20, 20);
textJLabel.setSize( 550, 70);
textJLabel.setFont( new Font( "SansSerif", Font.BOLD, 20 ) );
textJLabel.setHorizontalAlignment( JLabel.CENTER );
questiononeJPanel.add( textJLabel );
// set up presetJPanel
becksJPanel = new JPanel();
becksJPanel.setLayout( null );
becksJPanel.setBorder( new TitledBorder(
"Question 1" ) );
becksJPanel.setBounds( 10, 10, 570, 80 );
becksJPanel.setBackground( Color.GRAY );
questiononeJPanel.add( becksJPanel );
// set up oneJButton
oneJButton = new JButton();
oneJButton.setBounds( 10, 120, 300, 40 );
oneJButton.setText( "Britney Spears" );
oneJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( oneJButton );
// set up twoJButton
twoJButton = new JButton();
twoJButton.setBounds( 10, 180, 300, 40 );
twoJButton.setText( "Meg Ryan" );
twoJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( twoJButton );
// set up threeJButton
threeJButton = new JButton();
threeJButton.setBounds( 10, 240, 300, 40 );
threeJButton.setText( "Rebecca Loos" );
threeJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( threeJButton );
// set up fourJButton
fourJButton = new JButton();
fourJButton.setBounds( 10, 300, 300, 40 );
fourJButton.setText( "Angelina Jolie" );
fourJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( fourJButton );
// set up nextJButton
nextJButton = new JButton();
nextJButton.setBounds ( 375, 300, 150, 40 );
nextJButton.setText("Next");
nextJButton.setBackground( Color.GRAY );
questiononeJPanel.add( nextJButton );
contentPane.add(questiononeJPanel);
nextJButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
questiontwo();
public void questiontwo()
//set up question two JPanel
questiononeJPanel.setVisible(false);
questiontwoJPanel=new JPanel();
questiontwoJPanel.setLayout(null);
questiontwoJPanel.setBounds(0, 0, 600, 400);
questiontwoJPanel.setBackground( Color.GREEN );
// set up q2JLabel
q2JLabel = new JLabel();
q2JLabel.setBounds( 20, 20, 550, 70 );
q2JLabel.setText( "What films has Orlando Bloom starred in?" );
q2JLabel.setFont(new Font( "SansSerif", Font.BOLD, 20 ) );
q2JLabel.setHorizontalAlignment( JLabel.CENTER );
questiontwoJPanel.add(q2JLabel);
//set up orlandoJPanel
orlandoJPanel = new JPanel();
orlandoJPanel.setLayout(null);
orlandoJPanel.setBorder( new TitledBorder("Question 2"));
orlandoJPanel.setBounds( 10, 10, 570, 80);
orlandoJPanel.setBackground(Color.GRAY);
questiontwoJPanel.add(orlandoJPanel);
// set up lordJCheckBox
lordJCheckBox = new JCheckBox();
lordJCheckBox.setBounds( 16, 112, 200, 24 );
lordJCheckBox.setText( "1. Lord of The Rings" );
questiontwoJPanel.add( lordJCheckBox );
// set up faceJCheckBox
faceJCheckBox = new JCheckBox();
faceJCheckBox.setBounds( 16, 159, 200, 24 );
faceJCheckBox.setText( "2. Face Off" );
questiontwoJPanel.add( faceJCheckBox );
// set up piratesJCheckBox
piratesJCheckBox = new JCheckBox();
piratesJCheckBox.setBounds( 16, 206, 200, 24 );
piratesJCheckBox.setText( "3. Pirates of The Caribean" );
questiontwoJPanel.add( piratesJCheckBox );
// set up inputJButton
inputJButton = new JButton();
inputJButton.setBounds(20, 256, 200, 21 );
inputJButton.setText( "Input answer" );
questiontwoJPanel.add( inputJButton );
inputJButton.addActionListener(
new ActionListener()
//event handler called when user clicks inputJButton
public void actionPerformed( ActionEvent event )
inputJButtonActionPerformed( event);
//show JOptionMessages when user clicks on JCheckBoxes and inputJButton
public void inputJButtonActionPerformed( ActionEvent event )
//display error message if no JCheckBoxes is checked
if ( ( !lordJCheckBox.isSelected() && !faceJCheckBox.isSelected() && !piratesJCheckBox.isSelected() ) )
//display error message
JOptionPane.showMessageDialog( null, "Please check two boxes", JOptionPane.ERROR_MESSAGE );
// if lordjcheckbox and pirates is selected = right
else
if ( ( lordJCheckBox.isSelected() && piratesJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats RIGHT!");
//if others are selected = wrong
else
if ( (lordJCheckBox.isSelected() && faceJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats WRONG");
else
( (faceJCheckBox.isSelected() && piratesJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats WRONG");
// set up nest2JButton
next2JButton = new JButton();
next2JButton.setBounds( 155, 296, 94, 24 );
next2JButton.setText( "Next" );
questiontwoJPanel.add( next2JButton );
contentPane.add(questiontwoJPanel);
next2JButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
questionthree();
} // end questiontwo
public void questionthree()
//setup questionthree JPanel
questiontwoJPanel.setVisible(false);
questionthreeJPanel = new JPanel();
questionthreeJPanel.setLayout(null);
questionthreeJPanel.setBounds(0, 0, 600, 400);
questionthreeJPanel.setBackground( Color.GREEN);
// main method
public static void main( String[] args )
Mindboggler application = new Mindboggler();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
} // end method main
}// end class
WOULD BE VERY GEATFULJust want to say thank you by the way for trying to help. Ive moved public void inputJButtonActionPerformed( ActionEvent event ) outside of brackets. Now i have a different problem on it. Sorry about this.
PROBLEM: --------------------Configuration: <Default>--------------------
C:\Documents and Settings\Laila\My Documents\CMT2080\Coursework\Game\Mindboggler.java:353: 'else' without 'if'
else ( ( !lordJCheckBox.isSelected() && !faceJCheckBox.isSelected && !piratesJCheckBox.isSelected() ) )
^
1 error
Process completed.
MY CODE:
//Mind boggler quiz
//Marcelyn Samson
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.*;
import javax.swing.border.*;
import java.lang.*;
public class Mindboggler extends JFrame
// JPanel for welcome window
private JPanel welcomeJPanel;
private JPanel presetJPanel;
private JLabel titleJLabel;
private JLabel quizJLabel;
private JLabel girlJLabel, headJLabel;
private JLabel introJLabel;
private JButton startJButton;
// JPanel for questionone window
private JPanel questiononeJPanel;
private JLabel textJLabel;
private JPanel becksJPanel;
private JButton oneJButton, twoJButton, threeJButton, fourJButton, nextJButton;
//JPanel for questiontwo window
private JPanel questiontwoJPanel;
private JPanel orlandoJPanel;
private JLabel q2JLabel;
private JCheckBox lordJCheckBox;
private JCheckBox faceJCheckBox;
private JCheckBox piratesJCheckBox;
private JButton next2JButton;
private JButton inputJButton;
//JPanel for questionthree
private JPanel questionthreeJPanel;
private JPanel howmuchJPanel;
private JLabel howmuchJLabel;
private JLabel nameJLabel;
private JTextField nameJTextField;
private JLabel moneyJLabel;
private JTextField moneyJTextField;
private JButton next3JButton;
//Publics
public JPanel welcomeJFrame, questionJFrame, questiontwoJFrame, questionthreeJFrame;
//contentPane
public Container contentPane;
//no argument constructor
public Mindboggler()
createUserInterface();
//create and position components
private void createUserInterface()/////////////////////////; semo colon do not edit copy paste
//get contentPane and set layout to null
contentPane = getContentPane();
contentPane.setLayout ( null );
welcome();
//set properties of applications window
setTitle( "Mindboggler" ); // set JFrame's title bar string
setSize( 600, 400 ); // set width and height of JFrame
setVisible( true ); // display JFrame on screen
} // end method createUserInterface
public void welcome(){
// set up welcomeJPanel
welcomeJPanel = new JPanel();
welcomeJPanel.setLayout( null );
welcomeJPanel.setBounds(0, 0, 600, 400);
welcomeJPanel.setBackground( Color.GREEN );
// set up textJLabel
titleJLabel = new JLabel();
titleJLabel.setText( "Mind Boggler" );
titleJLabel.setLocation( 30, 10);
titleJLabel.setSize( 550, 70);
titleJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 30 ) );
titleJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add( titleJLabel );
// set up presetJPanel
presetJPanel = new JPanel();
presetJPanel.setLayout( null );
presetJPanel.setBounds( 150, 10, 300, 80 );
presetJPanel.setBackground( Color.GRAY );
welcomeJPanel.add( presetJPanel );
//setup Intro JLabel
introJLabel = new JLabel();
introJLabel.setText( "Think, think, think. Can you get all the questions right?" );
introJLabel.setBounds( 40, 100, 500, 200 );
introJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 18 ) );
introJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(introJLabel);
//set up head JLabel
headJLabel = new JLabel();
headJLabel.setIcon( new ImageIcon( "head.jpeg") );
headJLabel.setBounds( 540, 5, 40, 160 );
headJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(headJLabel);
//setup girlJLabel
girlJLabel = new JLabel();
girlJLabel.setIcon( new ImageIcon( "girl.Jjpeg") );
girlJLabel.setBounds( 5, 10, 60, 100 );
girlJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(girlJLabel);
//set up startJbutton
startJButton = new JButton();
startJButton.setText( "Start" );
startJButton.setBounds(250, 300, 100, 30);
startJButton.setFont( new Font( "SansSerif", Font.BOLD, 14) );
welcomeJPanel.add(startJButton);
contentPane.add(welcomeJPanel);
startJButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
question();
public void question()
//set up question one JPanel
welcomeJPanel.setVisible(false);
questiononeJPanel = new JPanel();
questiononeJPanel.setLayout( null );
questiononeJPanel.setBounds(0, 0, 600,400);
questiononeJPanel.setBackground( Color.GREEN );
// set up textJLabel
textJLabel = new JLabel();
textJLabel.setText( "Who did Beckham supposedly cheat with?" );
textJLabel.setLocation( 20, 20);
textJLabel.setSize( 550, 70);
textJLabel.setFont( new Font( "SansSerif", Font.BOLD, 20 ) );
textJLabel.setHorizontalAlignment( JLabel.CENTER );
questiononeJPanel.add( textJLabel );
// set up presetJPanel
becksJPanel = new JPanel();
becksJPanel.setLayout( null );
becksJPanel.setBorder( new TitledBorder(
"Question 1" ) );
becksJPanel.setBounds( 10, 10, 570, 80 );
becksJPanel.setBackground( Color.GRAY );
questiononeJPanel.add( becksJPanel );
// set up oneJButton
oneJButton = new JButton();
oneJButton.setBounds( 10, 120, 300, 40 );
oneJButton.setText( "Britney Spears" );
oneJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( oneJButton );
// set up twoJButton
twoJButton = new JButton();
twoJButton.setBounds( 10, 180, 300, 40 );
twoJButton.setText( "Meg Ryan" );
twoJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( twoJButton );
// set up threeJButton
threeJButton = new JButton();
threeJButton.setBounds( 10, 240, 300, 40 );
threeJButton.setText( "Rebecca Loos" );
threeJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( threeJButton );
// set up fourJButton
fourJButton = new JButton();
fourJButton.setBounds( 10, 300, 300, 40 );
fourJButton.setText( "Angelina Jolie" );
fourJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( fourJButton );
// set up nextJButton
nextJButton = new JButton();
nextJButton.setBounds ( 375, 300, 150, 40 );
nextJButton.setText("Next");
nextJButton.setBackground( Color.GRAY );
questiononeJPanel.add( nextJButton );
contentPane.add(questiononeJPanel);
nextJButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
questiontwo();
public void questiontwo()
//set up question two JPanel
questiononeJPanel.setVisible(false);
questiontwoJPanel=new JPanel();
questiontwoJPanel.setLayout(null);
questiontwoJPanel.setBounds(0, 0, 600, 400);
questiontwoJPanel.setBackground( Color.GREEN );
// set up q2JLabel
q2JLabel = new JLabel();
q2JLabel.setBounds( 20, 20, 550, 70 );
q2JLabel.setText( "What films has Orlando Bloom starred in?" );
q2JLabel.setFont(new Font( "SansSerif", Font.BOLD, 20 ) );
q2JLabel.setHorizontalAlignment( JLabel.CENTER );
questiontwoJPanel.add(q2JLabel);
//set up orlandoJPanel
orlandoJPanel = new JPanel();
orlandoJPanel.setLayout(null);
orlandoJPanel.setBorder( new TitledBorder("Question 2"));
orlandoJPanel.setBounds( 10, 10, 570, 80);
orlandoJPanel.setBackground(Color.GRAY);
questiontwoJPanel.add(orlandoJPanel);
// set up lordJCheckBox
lordJCheckBox = new JCheckBox();
lordJCheckBox.setBounds( 16, 112, 200, 24 );
lordJCheckBox.setText( "1. Lord of The Rings" );
questiontwoJPanel.add( lordJCheckBox );
// set up faceJCheckBox
faceJCheckBox = new JCheckBox();
faceJCheckBox.setBounds( 16, 159, 200, 24 );
faceJCheckBox.setText( "2. Face Off" );
questiontwoJPanel.add( faceJCheckBox );
// set up piratesJCheckBox
piratesJCheckBox = new JCheckBox();
piratesJCheckBox.setBounds( 16, 206, 200, 24 );
piratesJCheckBox.setText( "3. Pirates of The Caribean" );
questiontwoJPanel.add( piratesJCheckBox );
// set up inputJButton
inputJButton = new JButton();
inputJButton.setBounds(20, 256, 200, 21 );
inputJButton.setText( "Input answer" );
questiontwoJPanel.add( inputJButton );
inputJButton.addActionListener(
new ActionListener()
//event handler called when user clicks inputJButton
public void actionPerformed( ActionEvent event )
inputJButtonActionPerformed( event);
// set up nest2JButton
next2JButton = new JButton();
next2JButton.setBounds( 155, 296, 94, 24 );
next2JButton.setText( "Next" );
questiontwoJPanel.add( next2JButton );
contentPane.add(questiontwoJPanel);
next2JButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
questionthree();
} // end questiontwo
public void questionthree()
//setup questionthree JPanel
questiontwoJPanel.setVisible(false);
questionthreeJPanel = new JPanel();
questionthreeJPanel.setLayout(null);
questionthreeJPanel.setBounds(0, 0, 600, 400);
questionthreeJPanel.setBackground( Color.GREEN);
//setup howmuchJLabel
howmuchJLabel = new JLabel();
howmuchJLabel.setText("I'm a student and would be very greatful if you could donate some money as it would help me very much.");
howmuchJLabel.setBounds(20, 20, 550, 70);
howmuchJLabel.setFont(new Font("SansSerif",Font.BOLD,14));
howmuchJLabel.setHorizontalAlignment(JLabel.CENTER);
questionthreeJPanel.add(howmuchJLabel);
//setup howmuchJPanel
howmuchJPanel = new JPanel();
howmuchJPanel.setLayout(null);
howmuchJPanel.setBorder( new TitledBorder("Question 3"));
howmuchJPanel.setBounds(10, 10, 570, 80);
howmuchJPanel.setBackground( Color.GRAY);
questionthreeJPanel.add(howmuchJPanel);
//setup nameJLabel
nameJLabel = new JLabel();
nameJLabel.setText("Name");
nameJLabel.setBounds(10, 160, 150, 24);
nameJLabel.setFont(new Font("SansSerif",Font.BOLD,12));
questionthreeJPanel.add(nameJLabel);
//setup nameJTextField
nameJTextField = new JTextField();
nameJTextField.setBounds(125, 160, 200, 24 );
questionthreeJPanel.add(nameJTextField);
contentPane.add(questionthreeJPanel);
//show JOptionMessages when user clicks on JCheckBoxes and inputJButton
public void inputJButtonActionPerformed( ActionEvent event )
//display error message if no JCheckBoxes is checked
else ( ( !lordJCheckBox.isSelected() && !faceJCheckBox.isSelected && !piratesJCheckBox.isSelected() ) )
//display error message
JOptionPane.showMessageDialog( null, "Please check two boxes", JOptionPane.ERROR_MESSAGE );
// if lordjcheckbox and pirates is selected = right
else
if ( ( lordJCheckBox.isSelected() && piratesJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats RIGHT!");
//if others are selected = wrong
else
if ( (lordJCheckBox.isSelected() && faceJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats WRONG");
else
( (faceJCheckBox.isSelected() && piratesJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats WRONG");
// main method
public static void main( String[] args )
Mindboggler application = new Mindboggler();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
} // end method main
}// end class -
"cannot resolve symbol" in a Timer !!!Please Help!!!
I am doing a program for a class which involves timers. I am using JCreator and when i try to construct a new timer, the compiler points to the "new" in the line:
Timer T1=new Timer(interval, ActionListener);
^
This is what it looks like and the error reads: cannot resolve symbol; constructor Timer.
please tell me if yiou have any information or suggestions as to how this error might be remedied.Sure, here it is:
import java.awt.event.*;
import javax.swing.Timer;
import javax.swing.JOptionPane;
import java.util.*;
interface ActionListener
void actionPerformed(ActionEvent event);
class Ploid
public static void main(String[] args)
class Car implements ActionListener
int mpg=30;
int mph=35;
int gtank=20;
int interval;
int changer;
int totalmiles;
Car(int x)
interval=x;
public void actionPerformed(ActionEvent event)
for(int c=0;c<(interval/1000);c++)
totalmiles=totalmiles+mph;
int hyt=mpg*gtank;
if(totalmiles>hyt)
int y=totalmiles-hyt;
totalmiles=totalmiles-y;
System.out.println(totalmiles);
else
System.out.println(totalmiles);
class SUV implements ActionListener
int mpg=15;
int mph=55;
int gtank=30;
int interval;
int changer;
int totalmiles;
SUV(int x)
interval=x;
public void actionPerformed(ActionEvent event)
for(int c=0;c<(interval/1000);c++)
totalmiles=totalmiles+mph;
int hyt=mpg*gtank;
if(totalmiles>hyt)
int y=totalmiles-hyt;
totalmiles=totalmiles-y;
System.out.println(totalmiles);
else
System.out.println(totalmiles);
class Semi implements ActionListener
int mpg=60;
int mph=80;
int gtank=50;
int interval;
int changer;
int totalmiles;
Semi(int x)
interval=x;
public void actionPerformed(ActionEvent event)
for(int c=0;c<(interval/1000);c++)
totalmiles=totalmiles+mph;
int hyt=mpg*gtank;
if(totalmiles>hyt)
int y=totalmiles-hyt;
totalmiles=totalmiles-y;
System.out.println(totalmiles);
else
System.out.println(totalmiles);
String flag="y";
String trav=JOptionPane.showInputDialog("How long do you want to drive?(1000=1 hour)");
int t1=Integer.parseInt(trav);
Car listen=new Car(t1);
SUV listener2=new SUV(t1);
Semi listener3=new Semi(t1);
final int t2=t1/1000;
final int t3=t1/t2;
ActionListener listener=null;
Timer T1=new Timer(t3, listener);
Timer T2=new Timer(t3, listener);
Timer T3=new Timer(t3, listener);
while(flag.equals("y"))
T1.start();
T2.start();
T3.start();
String g=JOptionPane.showInputDialog("Do you want to drive again?");
if((g.equals("y"))||(g.equals("Y")))
System.out.println("Let's Drive!");
else
flag=g;
System.exit(0);
}Here is the errors:
[errors]
A:\Ploid2.java:116: cannot resolve symbol
symbol : constructor Timer (int,ActionListener)
location: class javax.swing.Timer
Timer T1=new Timer(t3, listener);
^
A:\Ploid2.java:117: cannot resolve symbol
symbol : constructor Timer (int,ActionListener)
location: class javax.swing.Timer
Timer T2=new Timer(t3, listener);
^
A:\Ploid2.java:118: cannot resolve symbol
symbol : constructor Timer (int,ActionListener)
location: class javax.swing.Timer
Timer T3=new Timer(t3, listener);
^
3 errors
Process completed.
[errors]
****There is the source code and the errors the compiler returns. That should be more help.**** -
HELP PLEASE Cannot resolve symbol error
Only just started to atempt simple java programs and this same error keeps appearing. code i am using is:
import java.io.*;
class Q1
public static void main(String[] args) throws IOException
int num1,num2,sum;
/*program statements start here*/
System.out.printIn ("Input a number");
num1= Course_io.readInt();
System.out.printIn ("Input another number");
num2= Course_io.readInt();
sum= num2 - num1;
System.out.printIn ("Total is" +sum );
and this is the error message i keep getting:
javac -d . -g "C:\Java Programs\Q1.java"
C:\Java Programs\Q1.java:12: cannot resolve symbol
symbol : method printIn (java.lang.String)
location: class java.io.PrintStream
System.out.printIn ("Input a number");
^
C:\Java Programs\Q1.java:16: cannot resolve symbol
symbol : method printIn (java.lang.String)
location: class java.io.PrintStream
System.out.printIn ("Input another number");
^
C:\Java Programs\Q1.java:22: cannot resolve symbol
symbol : method printIn (java.lang.String)
location: class java.io.PrintStream
System.out.printIn ("Total is" +sum );
^
3 errors
Please help me, Thankyou.sum= num2 - num1;
System.out.printIn ("Total is" +sum );While you're at it, do something about this, it's misleading.
kind regards,
Jos -
Need help - method call error cannot resolve symbol
My code compiles fine but I continue to receive a method call error "cannot resolve symbol - variable superman" - can't figure out why. Here is my code:
public static String caesar(String message, int shift)
{ [b]String result = "";
for(int i = 0; i < message.length(); ++i)
{ [b]char newChar = message.charAt(i + shift);
result += newChar;
return result.toUpperCase();
I entered "superman" for message and "3" for the shift. Can someone please help? Thanks!Your post worked great - especially since it made me realize I was going about it all wrong! I was attempting to convert "superman" to "vxshupdq" - basically a cipher shift starting at index 0 and shifting it 3 character values which would result in s changing to v. I restructured my code:
public static String caesar(String message, int shift)
{ [b]String result = "";
for(int i = 0; i < message.length(); ++i)
{ [b]char newChar = message.charAt(i);
result += (newChar + shift) % message.length();
return result.toUpperCase();
But it's displaying the result as a "60305041". How can I get it to display the actual characters? -
Help!!! error: cannot resolve symbol
can anyone tell me how to solve the following problem
thank you
cannot resolve symbol
symbol : method decode (java.lang.String)
location: class java.lang.Short
Short psmShort = Short.decode(psmString);
^
Long bdAddrLong = Long.decode("0x" + bdAddrString);
^that is because these methods does not exist. What you can use instead is parseShort(String) or parseLong.
Maybe reading the javadoc could help you next time ;-)
hth
Kay -
PLEASE HELP: cannot resolve symbol class
it's showing me the error on the following lines 7 and 9
it says cannot resolve symbol class Name and cannot resolve symbol class Phone
I also have a package name addressBook and it contains two files Entry.java and Address.java
Here is the code:
import java.io.*;
import addressBook.*;
public class AddressDr
public static void main(String[] args)throws IOException
Name name;
Address address;
Phone phone;
Entry entry;
String first, last, middle, street, city, state, zip;
int areaCode, number;
BufferedReader in;
in=new BufferedReader(new InputStreamReader(System.in));
PrintWriter outFile;
outFile=new PrintWriter(new FileWriter("Entries"));
System.out.println("Quit entered fot the first name ends the " + "application.");
System.out.print("Enter first name: ");
first=in.readLine();
while (first.compareTo("Quit") !=0)
System.out.print("Enter last name: ");
last=in.readLine();
System.out.print("Enter middle name: ");
middle=in.readLine();
name=new Name(first, last, middle);
System.out.print("Enter street address: ");
street=in.readLine();
System.out.print("Enter city: ");
city=in.readLine();
System.out.print("Enter state: ");
state=in.readLine();
System.out.print("Enter ZIP code: ");
zip=in.readLine();
address=new Address(street, city, state, zip);
System.out.print("Enter areaCode: ");
areaCode = Integer.parseInt(in.readLine());
System.out.print("Enter number: ");
number=Integer.parseInt(in.readLine());
phone=new Phone(areaCode, number);
entry= new Entry(name, address, phone);
entry.writeToFile(outFile);
System.out.print("Enter first name: ");
first=in.readLine();
outFile.close();
}OK. Here is how I did it.
I have AddressDr which is Address driver.
I have two files Address and Entry which in package addressBook.
AddressDr:
import java.io.*;
import addressBook.*;
public class AddressDr
public static void main(String[] args)throws IOException
Name name;
Address address;
Phone phone;
Entry entry;
String first, last, middle, street, city, state, zip;
int areaCode, number;
BufferedReader in;
in=new BufferedReader(new InputStreamReader(System.in));
PrintWriter outFile;
outFile=new PrintWriter(new FileWriter("Entries"));
System.out.println("Quit entered fot the first name ends the " + "application.");
System.out.print("Enter first name: ");
first=in.readLine();
while (first.compareTo("Quit") !=0)
System.out.print("Enter last name: ");
last=in.readLine();
System.out.print("Enter middle name: ");
middle=in.readLine();
name=new Name(first, last, middle);
System.out.print("Enter street address: ");
street=in.readLine();
System.out.print("Enter city: ");
city=in.readLine();
System.out.print("Enter state: ");
state=in.readLine();
System.out.print("Enter ZIP code: ");
zip=in.readLine();
address=new Address(street, city, state, zip);
System.out.print("Enter areaCode: ");
areaCode = Integer.parseInt(in.readLine());
System.out.print("Enter number: ");
number=Integer.parseInt(in.readLine());
phone=new Phone(areaCode, number);
entry= new Entry(name, address, phone);
entry.writeToFile(outFile);
System.out.print("Enter first name: ");
first=in.readLine();
outFile.close();
Entry:
package addressBook;
import java.io.*;
public class Entry
Name name;
Address address;
Phone phone;
public Entry(Name newName, Address newAddress, Phone phoneNumber)
name = newName;
address = newAddress;
phone = phoneNumber;
public Name knowName()
return name;
public Address knowAddress()
return address;
public Phone knowPhone()
return phone;
public void writeToFile(PrintWriter outFile)
outFile.println(name.knowFirstName());
outFile.println(name.knowLastName());
outFile.println(name.knowMiddleName());
oufFile.println(address.knowStreet());
outFile.println(address.knowState());
outFile.println(address.knowCity());
outFile.println(address.knowZip());
outFile.println(phone.knowAreaCode());
outFile.println(phone.knowDigits());
Address:
package addressBook;
public class Address
String street;
String city;
String state;
String zipCode;
public Address(String newStreet, String newCity, String newState, String zip)
street=newStreet;
city=newCity;
state=newState;
zipCode=zip;
public String knowStreet()
return street;
public String knowCity()
return city;
public String knowState()
return state;
public String knowZip()
return zipCode;
} -
"cannot resolve symbol" error...please help
when itry to compile my program i get the error " cannot resolve
symbol" variable setLayout.
My program is very small. Can someone tell me why i keep
getting error?
thanx
trin.
import java.applet.*;
import java.awt.*;
public class MyProg extends Applet
Button btnOne = new Button("One");
Button btnTwo = new Button("Two");
public void init()
Panel pOne = new Panel( ) ;
pOne.setLayout = ( new GridLayout( ));
pOne.add(btnOne);
pOne.add(btnTwo);
add(pOne);Change:
pOne.setLayout = ( new GridLayout( ));to
pOne.setLayout( new GridLayout());It's a method call, not an assignment :) -
Getting error message Cannot Resolve Symbol when trying to compile a class
Hello All -
I am getting an error message cannot resolve symbol while trying to compile a java class that calls another java class in the same package. The called class compiles fine, but the calling class generates
the following error message:
D:\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes\cal>javac
ConnectionPool.java
ConnectionPool.java:158: cannot resolve symbol
symbol : class PooledConnection
location: class cal.ConnectionPool
private void addConnection(PooledConnection value) {
^
ConnectionPool.java:144: cannot resolve symbol
symbol : class PooledConnection
location: class cal.ConnectionPool
PooledConnection pcon = new PooledConnection(con);
^
ConnectionPool.java:144: cannot resolve symbol
symbol : class PooledConnection
location: class cal.ConnectionPool
PooledConnection pcon = new PooledConnection(con);
The code is listed as follows for PooledConnection.java (it compiles fine)
package cal;
import java.sql.*;
public class PooledConnection {
// Real JDBC Connection
private Connection connection = null;
// boolean flag used to determine if connection is in use
private boolean inuse = false;
// Constructor that takes the passed in JDBC Connection
// and stores it in the connection attribute.
public PooledConnection(Connection value) {
if ( value != null ) {
connection = value;
// Returns a reference to the JDBC Connection
public Connection getConnection() {
// get the JDBC Connection
return connection;
// Set the status of the PooledConnection.
public void setInUse(boolean value) {
inuse = value;
// Returns the current status of the PooledConnection.
public boolean inUse() {
return inuse;
// Close the real JDBC Connection
public void close() {
try {
connection.close();
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
Now the code for ConnectionPool.java class that gives the cannot
resolve symbol error
package cal;
import java.sql.*;
import java.util.*;
public class ConnectionPool {
// JDBC Driver Name
private String driver = null;
// URL of database
private String url = null;
// Initial number of connections.
private int size = 0;
// Username
private String username = new String("");
// Password
private String password = new String("");
// Vector of JDBC Connections
private Vector pool = null;
public ConnectionPool() {
// Set the value of the JDBC Driver
public void setDriver(String value) {
if ( value != null ) {
driver = value;
// Get the value of the JDBC Driver
public String getDriver() {
return driver;
// Set the URL Pointing to the Datasource
public void setURL(String value ) {
if ( value != null ) {
url = value;
// Get the URL Pointing to the Datasource
public String getURL() {
return url;
// Set the initial number of connections
public void setSize(int value) {
if ( value > 1 ) {
size = value;
// Get the initial number of connections
public int getSize() {
return size;
// Set the username
public void setUsername(String value) {
if ( value != null ) {
username = value;
// Get the username
public String getUserName() {
return username;
// Set the password
public void setPassword(String value) {
if ( value != null ) {
password = value;
// Get the password
public String getPassword() {
return password;
// Creates and returns a connection
private Connection createConnection() throws Exception {
Connection con = null;
// Create a Connection
con = DriverManager.getConnection(url,
username, password);
return con;
// Initialize the pool
public synchronized void initializePool() throws Exception {
// Check our initial values
if ( driver == null ) {
throw new Exception("No Driver Name Specified!");
if ( url == null ) {
throw new Exception("No URL Specified!");
if ( size < 1 ) {
throw new Exception("Pool size is less than 1!");
// Create the Connections
try {
// Load the Driver class file
Class.forName(driver);
// Create Connections based on the size member
for ( int x = 0; x < size; x++ ) {
Connection con = createConnection();
if ( con != null ) {
// Create a PooledConnection to encapsulate the
// real JDBC Connection
PooledConnection pcon = new PooledConnection(con);
// Add the Connection to the pool.
addConnection(pcon);
catch (Exception e) {
System.err.println(e.getMessage());
throw new Exception(e.getMessage());
// Adds the PooledConnection to the pool
private void addConnection(PooledConnection value) {
// If the pool is null, create a new vector
// with the initial size of "size"
if ( pool == null ) {
pool = new Vector(size);
// Add the PooledConnection Object to the vector
pool.addElement(value);
public synchronized void releaseConnection(Connection con) {
// find the PooledConnection Object
for ( int x = 0; x < pool.size(); x++ ) {
PooledConnection pcon =
(PooledConnection)pool.elementAt(x);
// Check for correct Connection
if ( pcon.getConnection() == con ) {
System.err.println("Releasing Connection " + x);
// Set its inuse attribute to false, which
// releases it for use
pcon.setInUse(false);
break;
// Find an available connection
public synchronized Connection getConnection()
throws Exception {
PooledConnection pcon = null;
// find a connection not in use
for ( int x = 0; x < pool.size(); x++ ) {
pcon = (PooledConnection)pool.elementAt(x);
// Check to see if the Connection is in use
if ( pcon.inUse() == false ) {
// Mark it as in use
pcon.setInUse(true);
// return the JDBC Connection stored in the
// PooledConnection object
return pcon.getConnection();
// Could not find a free connection,
// create and add a new one
try {
// Create a new JDBC Connection
Connection con = createConnection();
// Create a new PooledConnection, passing it the JDBC
// Connection
pcon = new PooledConnection(con);
// Mark the connection as in use
pcon.setInUse(true);
// Add the new PooledConnection object to the pool
pool.addElement(pcon);
catch (Exception e) {
System.err.println(e.getMessage());
throw new Exception(e.getMessage());
// return the new Connection
return pcon.getConnection();
// When shutting down the pool, you need to first empty it.
public synchronized void emptyPool() {
// Iterate over the entire pool closing the
// JDBC Connections.
for ( int x = 0; x < pool.size(); x++ ) {
System.err.println("Closing JDBC Connection " + x);
PooledConnection pcon =
(PooledConnection)pool.elementAt(x);
// If the PooledConnection is not in use, close it
if ( pcon.inUse() == false ) {
pcon.close();
else {
// If it is still in use, sleep for 30 seconds and
// force close.
try {
java.lang.Thread.sleep(30000);
pcon.close();
catch (InterruptedException ie) {
System.err.println(ie.getMessage());
I am using Sun JDK Version 1.3.0_02" and Apache/Tomcat 4.0. Both the calling and the called class are in the same directory.
Any help would be greatly appreciated.
tnx..
addiIs ConnectionPool in this "cal" package as well as PooledConnection? From the directory you are compiling from it appears that it is. If it is, then you are compiling it incorrectly. To compile ConnectionPool (and PooledConnection similarly), you must change the current directory to the one that contains cal and type
javac cal/ConnectionPool. -
Cannot resolve symbol: class EJBObject
Using javac I get this compile error on this file Calculator.java
Calculator.java:1: cannot resolve symbol
symbol : class EJBObject
location: package ejb
import javax.ejb.EJBObject;
^
Calculator.java:5: cannot resolve symbol
symbol : class EJBObject
location: interface Calculator
public interface Calculator extends EJBObject {
Source code for Calculator.java
import javax.ejb.EJBObject;
import java.rmi.*;
public interface Calculator extends EJBObject {
public long add (int x, int y) throws RemoteException;
public long subtract (int x, int y) throws RemoteException;This code is from a book, so I will assume its a classpath problem. My
classpath looks like:
"C\QTJava.zip".;%J2EE_HOME%\lib\j2ee.jar;%J2EE_HOME%\lib\locale
Also the following enviorment varibales have been set to:
J2EE_HOME
C:\Development\Java\j2sdkee1.3.1
JAVA_HOME
C:\Development\Java\jdk1.3.1
Path
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\Adaptec Shared\System;%JAVA_HOME%\bin;%J2EE_HOME%\bin
I can run j2EE, like "j2EE -verbose" (no problems)
also run cloudscape, like "cloudscape -start" (no problems)
also can run deploytool, like "deploytool" (no problems, & deploy sample ear files from cd book)
Your help is appreicated. -
Cannot resolve symbol : class odbc ERROR
Hi Helper
I am trying to compile a the following and I am getting the error
C:\jdk\websiter>javac MainServlet.java
MainServlet.java:86: cannot resolve symbol
symbol : class odbc
location: package jdbc
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
import java.util.*;
* This is the servlet to send the user the names of all the sites present in the database
public class MainServlet extends HttpServlet implements ServletConstants
Connection m_con;
PreparedStatement m_pstmt;
ResultSet m_res;
Vector m_vecsiteName;
public void Init(ServletConfig config) throws ServletException {
super.init(config);
}// end of init()
public void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
m_vecsiteName = new Vector();
try {
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
m_con = DriverManager.getConnection("jdbc:odbc:sitewd", "", "");
How can i fix it? thanks
VTReplace the Statement
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
as
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); -
Import java.util.Formatter - cannot resolve symbol
I use j2sdk1.4.2_04
when I try to compile my program using Formatter, it response error "cannot resolve symbol"
Pls help!Where did you get this java.util.Formatter from? If you check the official 1.4.2 API for Java, that class does not exisit! However, java.util.logging.Formatter, does exisit...
http://java.sun.com/j2se/1.4.2/docs/api/
If you ment: java.util.logging.Formatter have you checked the API to make sure you are using it correctly???
HTH. -
Cannot resolve symbol java.awt.graphics
// DrawRectangleDemo.java
import java.awt.*;
import java.lang.Object;
import java.applet.Applet;
public class DrawRectangleDemo extends Applet
public void paint (Graphics g)
// Get the height and width of the applet's drawing surface.
int width = getSize ().width;
int height = getSize ().height;
int rectWidth = (width-50)/3;
int rectHeight = (height-70)/2;
int x = 5;
int y = 5;
g.drawRect (x, y, rectWidth, rectHeight);
g.drawString ("drawRect", x, rectHeight + 30);
x += rectWidth + 20;
g.fillRect (x, y, rectWidth, rectHeight);
// Calculate a border area with each side equal tp 25% of
// the rectangle's width.
int border = (int) (rectWidth * 0.25);
// Clear 50% of the filled rectangle.
g.clearRect (x + border, y + border,
rectWidth - 2 * border, rectHeight - 2 * border);
g.drawString ("fillRect/clearRect", x, rectHeight + 30);
x += rectWidth + 20;
g.drawRoundRect (x, y, rectWidth, rectHeight, 15, 15);
g.drawString ("drawRoundRect", x, rectHeight + 30);
x=5;
y += rectHeight + 40;
g.setColor (Color.yellow);
for (int i = 0; i < 4; i++)
g.draw3DRect (x + i * 2, y + i * 2,
rectWidth - i * 4, rectHeight - i * 4, false);
g.setColor (Color.black);
g.drawString ("draw3DRect", x, y, + rectHeight + 25);
x += rectWidth + 20;
g.setColor (Color.yellow);
g.fill3DRect (x, y, rectWidth, rectHeight, true);
g.setColor (Color.black);
g.drawString ("fill3DRect", x, y, + rectHeight + 25);
Help me with this codes. I typed correctly but there still errors.
--------------------Configuration: JDK version 1.3.1 <Default>--------------------
D:\Program Files\Xinox Software\JCreator LE\MyProjects\DrawRectangleDemo.java:56: cannot resolve symbol
symbol : method drawString (java.lang.String,int,int,int)
location: class java.awt.Graphics
g.drawString ("draw3DRect", x, y, + rectHeight + 25);
^
D:\Program Files\Xinox Software\JCreator LE\MyProjects\DrawRectangleDemo.java:64: cannot resolve symbol
symbol : method drawString (java.lang.String,int,int,int)
location: class java.awt.Graphics
g.drawString ("fill3DRect", x, y, + rectHeight + 25);
^
2 errors
Process completed.
-------------------------------------------------------------------------------------------------------------------------------cannot resolve symbol
symbol : method drawString (java.lang.String,int,int,int)
This is telling you that you are trying to invoke the drawString() method with 4 parameters: String, int, int, int
If you look at the API the drawString() method need 3 parameters: String, int, int - so you have an extra int
location: class java.awt.Graphics
g.drawString ("draw3DRect", x, y, + rectHeight + 25);
Now is you look at your code you will find that you have 3 ',' in you method call. (I don't think you want the ',' after the y. -
Cannot resolve symbol: HashMap, put and strings
Hi,
why woudl I get a "cannot resolve symbol" at the line indicated by <============
sec_cands[i] should be a String already.
Can someone help me ?
Thanks in advance.
HashMap temp = new HashMap();
String [] sec_cands = sec_ex.getTargetPhrases();
int sec_length = sec_cands.length;
String [] allCands = new String[total_length];
if (sec_length > 0 ) {
for (int i = 0; i < sec_cands.length; i++)
allCands[fr_length+i] = sec_cands;
temp.put(sec_cands[i], true); <=================Sorry, I accidentally deleted a subscript from a line. The real code is "
HashMap temp = new HashMap();
String [] sec_cands = sec_ex.getTargetPhrases();
int sec_length = sec_cands.length;
String [] allCands = new String[total_length];
if (sec_length > 0 ) {
for (int i = 0; i < sec_cands.length; i++)
allCands[fr_length+i] = sec_cands;
temp.put(sec_cands[i], true); <================= -
Compiling error - cannot resolve symbol
Hi,
I am working on writing out this basic code for a project. When I compile, I get an error "Cannot resolve symbol" for the gpa variable. Please help!
My intention is to use the hours and points from the crHours and nbrPoints methods, and use them to calculate GPA in the grPtAvg method:
public class Student
public static void main(String[]args)
idNum();
crHours();
nbrpoints();
gpa = grPtAvg(hours, points);
System.out.println("Student's GPA is " + gpa);
public static void idNum()
int id = 2520;
System.out.println("Student's ID is " + id);
public static float crHours()
float hours = 5;
System.out.println("Student's credit hours are " + hours);
return hours;
public static float nbrpoints()
float points = 22;
System.out.println("Student's earned points are " + points);
return points;
public static float grPtAvg(float hours, float points)
float gpa;
gpa = points / hours;
System.out.println("Student's computed GPA is " + gpa);
return gpa;That's because you're doing the same thing (in a somewhat different way) with those.
The variables: hours and points have already been returned to main methd, right?Yes, but then the main method ignores them.
So, they should be available at this point in the code, is that right?Available in the sense that you can read them, but not in the sense that there are hours and points variables within scope in the main method.
You want to do this:
public static void main(String[] args) {
idNum();
float hours = crHours();
float points = nbrpoints();
//create a new float
float myComputetdGpa = grPtAvg(hours, points);
System.out.println("Student's GPA is " + myComputedGpa);
}
Maybe you are looking for
-
Is anyone facing problems with quicktime on lion???
I recently upgraded my macbook pro to lion osx and the problems keep showing up one by one... quicktime is the worst. it has literally stopped functioning! at first, there was this problem with audio and video not being synched; and then it got worse
-
Firefox segfaults with Flash content. x64. [Solved]
I'm running 64 bit Arch version 2010.05 and I installed flashplugin. When I navigate to a Flash website Firefox segfaults. It also happens on other pages such as Gmail. Chromium doesn't segfaults with Flash or any other page but Flash doesn't work ei
-
Older version, please help.
First and foremost, please don't eat my face off when I say, I use a PC. However, this is not to say I hate Macs. In fact I thoroughly enjoy them. I have my associates in Multimedia and Teleproduction technologies, and all work was done via Macs. My
-
I wanna know what are the defalut application will come iphone 4s.
-
The question is already in topic. I have tried it for several time but haven't succeeded. My tried (http://www.zone.ee/mahb02/main.vi) One problem is how to to calibration with first picture only, cause other pictures don't have ruler. Pictures are s