Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Error in Java Programming

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Doomwinner
Advanced Cheater
Reputation: -1

Joined: 07 Oct 2009
Posts: 79
Location: USA

PostPosted: Sat Apr 13, 2013 7:55 pm    Post subject: Error in Java Programming Reply with quote

Making a program involving Super and sub classes for a college course.

But I don't understand the error.

Can't figure out what the problem is.


This was pre-made, there shouldn't be any errors here:

Code:
/**
   The Employee class stores data about an employee
   for the Employee and ProductionWorker Classes
   programming challenge.
*/

public class Employee
{
   private String name;             // Employee name
   private String employeeNumber;   // Employee number
   private String hireDate;         // Employee hire date
   
   /**
      This constructor initializes an object with a name,
      employee number, and hire date.
      @param n The employee's name.
      @param num The employee's number.
      @param date The employee's hire date.
   */
     
   public Employee(String n, String num, String date)
   {
      name = n;
      setEmployeeNumber(num);
      hireDate = date;
   }

   /**
      The no-arg constructor initializes an object with
      null strings for name, employee number, and hire
      date.
   */
     
   public Employee()
   {
      name = "";
      employeeNumber = "";
      hireDate = "";
   }
   
   /**
      The setName method sets the employee's name.
      @param n The employee's name.
   */

   public void setName(String n)
   {
      name = n;
   }

   /**
      The setEmployeeNumber method sets the employee's
      number.
      @param e The employee's number.
   */

   public void setEmployeeNumber(String e)
   {
      if (isValidEmpNum(e))
         employeeNumber = e;
      else
         employeeNumber = "";
   }

   /**
      The setHireDate method sets the employee's
      hire date.
      @param h The employee's hire date.
   */

   public void setHireDate(String h)
   {
      hireDate = h;
   }

   /**
      The getName method returns the employee's name.
      @return The employee's name.
   */

   public String getName()
   {
      return name;
   }

   /**
      The getEmployeeNumber method returns the
      employee's number.
      @return The employee's number.
   */

   public String getEmployeeNumber()
   {
      return employeeNumber;
   }

   /**
      The getHireDate method returns the
      employee's hire date.
      @return The employee's hire date.
   */
   
   public String getHireDate()
   {
      return hireDate;
   }

   /**
      isValidEmpNum is a private method that
      determines whether a string is a valid
      employee number.
      @param e The string containing an employee
             number.
      @return true if e references a valid ID number,
              false otherwise.
   */

   private boolean isValidEmpNum(String e)
   {
      boolean status = true;
     
      if (e.length() != 5)
         status = false;
      else
      {
         if ((!Character.isDigit(e.charAt(0))) ||
             (!Character.isDigit(e.charAt(1))) ||
             (!Character.isDigit(e.charAt(2))) ||
             (e.charAt(3) != '-')              ||
             (!Character.isLetter(e.charAt(4))))
               status = false;
      }
     
      return status;
   }

   /**
      toString method
      @return A reference to a String representation of
              the object.
   */
   
   public String toString()
   {
      String str = "Name: " + name + "\nEmployee Number: ";
     
      if (employeeNumber == "")
         str += "INVALID EMPLOYEE NUMBER";
      else
         str += employeeNumber;
         
      str += ("\nHire Date: " + hireDate);
      return str;
   }
}




This creates an instance of the class(es), this is where the error is picked up:

Code:
//This Runs the Super and Sub Class


import java.util.*;

public class EmployeePROG
   {

      public static void main(String[] args)
      {

      ProductionWorker one = new ProductionWorker("John Doe", "123-A", "April 1st");


      System.exit(0);
      }




   }



The extension I made: the error is either here or in the previous code.

Code:
//extension for Employee.java
import java.util.*;

public class ProductionWorker extends Employee
   {
      public static void main(String n, String num, String date)
      {

      int Shift = 0; //Day or Night     Day = 1   Night = 2
      double HPR = 0.0; //Hourly pay rate


      Shift = 1;

      HPR = 2.5;

      }

   }

_________________
Do I frustrate you? How about now?
Back to top
View user's profile Send private message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Sat Apr 13, 2013 10:35 pm    Post subject: Reply with quote

http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
Back to top
View user's profile Send private message
Doomwinner
Advanced Cheater
Reputation: -1

Joined: 07 Oct 2009
Posts: 79
Location: USA

PostPosted: Sun Apr 14, 2013 8:27 am    Post subject: Reply with quote

That certainly covers what I'm learning right now, but doesn't quite clarify where I personally screwed up. To me, this code makes perfect sense (Appearently not to java though).
_________________
Do I frustrate you? How about now?
Back to top
View user's profile Send private message
shitposter
Newbie cheater
Reputation: 5

Joined: 12 Nov 2008
Posts: 13

PostPosted: Sun Apr 14, 2013 9:20 am    Post subject: Reply with quote

What's the error?
Back to top
View user's profile Send private message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Sun Apr 14, 2013 9:58 am    Post subject: Reply with quote

Doomwinner wrote:
That certainly covers what I'm learning right now, but doesn't quite clarify where I personally screwed up. To me, this code makes perfect sense (Appearently not to java though).

Read about subclass constructors.
Back to top
View user's profile Send private message
deviluc
Cheater
Reputation: 1

Joined: 02 Jun 2010
Posts: 28

PostPosted: Mon Apr 15, 2013 1:26 pm    Post subject: This post has 1 review(s) Reply with quote

Isn't there missing a
Code:
super(n, num, date);
call in the constructor of ProductionWorker?

P.S.: It would be usefull to know which error is being thrown by your compiler Wink
Back to top
View user's profile Send private message
jucce
Advanced Cheater
Reputation: 1

Joined: 02 Apr 2013
Posts: 99

PostPosted: Mon Apr 15, 2013 2:23 pm    Post subject: This post has 1 review(s) Reply with quote

Change this line in the class ProductionWorker:
Code:
public static void main(String n, String num, String date)

to
Code:
public ProductionWorker(String n, String num, String date)
You aren't defining the constructor correctly.
Back to top
View user's profile Send private message
Doomwinner
Advanced Cheater
Reputation: -1

Joined: 07 Oct 2009
Posts: 79
Location: USA

PostPosted: Tue Apr 16, 2013 2:35 pm    Post subject: Reply with quote

Thank you, jucce.

I have been told repeatedly how ugly my code is, but your the first one to simply tell me my problem and solution instead of telling me to break it up into parts, or just read the section on so-and-so. (No offense Innovation, I am thinking of my teacher and classmate{who had good intent}, not you.)


And thanks to you too, deviluc, I was, but it wasn't what was throwing my particular error, and the way the book I used read, I didn't think I needed it.

+Karma to you both!(Please give time for cooldown)

_________________
Do I frustrate you? How about now?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites