The Orange Mane -  a Denver Broncos Fan Community  

Go Back   The Orange Mane - a Denver Broncos Fan Community > Orange Mane Discussion > Orange Mane Central Discussion
Register FAQ Members List Calendar Chat Room Mark Forums Read



Reply
 
Thread Tools Display Modes
Old 02-19-2011, 06:24 PM   #1
Hotwheelz
Perennial Pro-bowler
 
Hotwheelz's Avatar
 

Join Date: Mar 2006
Posts: 843
Default Does Anyone Speak Java: The Sequel

I'm having trouble debugging this:

Code:
/*
    Chapter 3: Free Time Calculator
    Programmer: Censored
    Date: February 19, 2011
    Filename: FreeTimeCalc.java
    Purpose: This project calculates your free time based
         on time spent sleeping, at school/work and driving.
*/

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class FreeTimeCalc extends Applet implements ActionListener
{
    //declare variables
    Image logo; //declare an image object
    int sleepTime, workTime, driveTime;
    double hoursInAWeek = 168.0;
    double freeTime;

    //construct components
    Label swcLabel = new Label("CENSORED FREE TIME CALCULATOR");
    Label sleepLabel = new Label("Enter how much time you sleep per week to the nearest hour: ");
        TextField sleepField = new TextField(10);
    Label workLabel = new Label("Enter how much time you work per week to the nearest hour: ");
        TextField workField = new TextField(10);
    Label driveLabel = new Label("Enter how much time you drive per week to the nearest hour: ");
        TextField driveField = new TextField(10);
    Button calcButton = new Button("Calculate");
    Label outputLabel = new Label(
    "Click the calculate button to see your free time.");

    public void init()
        [
            setForeground(Color,red);
            add(swcLabel);
            add(sleepLabel);
            add(sleepField);
            add(workLabel);
            add(workField);
            add(calcButton);
            add(driveLabel);
            add(driveField);
            calcButton.addActionListener(this);
            add(outputLabel);
            logo = getImage(getDocumentBase(), "logo.gif");
        }

        public void actionPerformed(ActionEvent e)
        {
            sleepTime = Integer.parseInt(sleepField.getText());
            workTime = Integer.parseInt(workField.getText());
            driveTime = Integer.parseInt(driveField.getText());
            double freeTime = 1 - (driveTime + sleepTime + workTime) / hoursInAWeek;
            outputLabel.setText("You are free " + (Math.round(freeTime) * 100) + "% of the time.");
        }

        public void paint(Graphics g)
        {
            g.drawImage(logo,125,160,this);
        }
}
Here's the errors:

Quote:
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:34: expected
public class void init()
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:34: invalid method declaration; return type required
public class void init()
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:34: ';' expected
public class void init()
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:37: invalid method declaration; return type required
add(swcLabel);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:37: expected
add(swcLabel);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:38: invalid method declaration; return type required
add(sleepLabel);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:38: expected
add(sleepLabel);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:39: invalid method declaration; return type required
add(sleepField);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:39: expected
add(sleepField);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:40: invalid method declaration; return type required
add(workLabel);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:40: expected
add(workLabel);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:41: invalid method declaration; return type required
add(workField);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:41: expected
add(workField);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:42: invalid method declaration; return type required
add(calcButton);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:42: expected
add(calcButton);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:43: invalid method declaration; return type required
add(driveLabel);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:43: expected
add(driveLabel);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:44: invalid method declaration; return type required
add(driveField);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:44: expected
add(driveField);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:45: expected
calcButton.addActionListener(this);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:45: illegal start of type
calcButton.addActionListener(this);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:46: invalid method declaration; return type required
add(outputLabel);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:46: expected
add(outputLabel);
^
F:\School\CIS 153\Lab 5\FreeTimeCalc.java:47: expected
logo = getImage(getDocumentBase(), "logo.gif");
^
24 errors

Tool completed with exit code 1
The culprit seems to be public void init().

Last edited by Hotwheelz; 02-19-2011 at 06:26 PM..
Hotwheelz is offline   Reply With Quote
Sponsored Links
Old 02-19-2011, 06:29 PM   #2
Ray_Lewis'_Victim
Corpse
 
Ray_Lewis'_Victim's Avatar
 

Join Date: Dec 2005
Location: Golden
Posts: 109
Default

Looks like you're opening void init() with a square bracket, not a curly brace.
Ray_Lewis'_Victim is offline   Reply With Quote
Old 02-19-2011, 06:32 PM   #3
CEH
Ring of Famer
 
CEH's Avatar
 

Join Date: Mar 2004
Posts: 4,329
Default

public void init()
[


You have a left bracket instead of a left brace "{"
CEH is offline   Reply With Quote
Old 02-19-2011, 06:33 PM   #4
Hotwheelz
Perennial Pro-bowler
 
Hotwheelz's Avatar
 

Join Date: Mar 2006
Posts: 843
Default

Quote:
Originally Posted by Ray_Lewis'_Victim View Post
Looks like you're opening void init() with a square bracket, not a curly brace.
I feel smart. Thanks.
Hotwheelz is offline   Reply With Quote
Old 02-19-2011, 07:28 PM   #5
Play2win
Ring of Famer
 

Join Date: Nov 2003
Posts: 9,628

Adopt-a-Bronco:
The Duke
Default

I'm in the middle of Cramming for my JAVA class. Textbook is the Comprehensive intro to Java by Y. Daniel Liang. Real good book. But ONLINE courses suck, especially online 8 week courses... in programming... I'll find out in a couple of weeks how this goes YAAAA!!!!
Play2win is offline   Reply With Quote
Old 02-19-2011, 08:44 PM   #6
ghwk
Ring of Famer
 
ghwk's Avatar
 
Survivor survivor!

Join Date: Jul 2008
Posts: 4,858

Adopt-a-Bronco:
Peyton's C3-C5
Default

I took fortran once so I am of no use to you. I am also of no use to you because I had to drop the class when I couldn't make a random number generator.
ghwk is offline   Reply With Quote
Old 02-20-2011, 08:24 AM   #7
Mr. Elway
cakn patna
 

Join Date: Jul 2009
Posts: 967
Default

Quit posting your homework on the forum and figure it out yourself. People are going to be relying on you to program on your own one day!
Mr. Elway is offline   Reply With Quote
Old 02-20-2011, 08:33 AM   #8
theAPAOps5
A new beginning!
 
theAPAOps5's Avatar
 

Join Date: Aug 2006
Location: Seattle
Posts: 31,824

Adopt-a-Bronco:
Watermock - RIP
Default

Quote:
Originally Posted by Mr. Elway View Post
Quit posting your homework on the forum and figure it out yourself. People are going to be relying on you to program on your own one day!
Yeah asking for help is unamercian. Don't ever ask for help.
theAPAOps5 is offline   Reply With Quote
Old 02-20-2011, 08:57 AM   #9
HILife
Ring of Famer
 
HILife's Avatar
 
Mrs. Alicia Hilife

Join Date: Jun 2006
Location: DC - NOVA - DMV - VA - Take your pick
Posts: 4,599
Default

HILife is offline   Reply With Quote
Reply

Thread Tools
Display Modes



Forum Jump


All times are GMT -7. The time now is 01:09 AM.


Denver Broncos