Click here to Skip to main content
15,077,154 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Java
public abstract class Employee 
    private String name; 
    private long cprNum; 
    private String position; 
    public Employee ( ) { 
        this ("Unknown", 0, "Unknown"); 
    public Employee (String eName, long code, String pos) {
        setName (eName) ; 
        setCprNum(code); 
        setPosition (pos); 
    public void setName (String eName) { 
        name = eName; 
    public boolean setCprNum(long code) { 
        if (code > 0 && code < 100000000) 
            cprNum = code; 
            return true; 
        else{ 
            System.out.println("Invalid CPR, initializg it to 0"); 
            cprNum = 0; 
            return false; 
    public void setPosition (String pos) { 
        position pos; 
    public String getName ( ) ( 
        return name; 
    public long get CprNum( ){ 
        return cprNum; 
    public String getPosition( ) 
        return position; 
    public abstract double salary( ); // abstract method 
    public String toString( ) 
        return ("Name: name + "CPR: corNum "Position: 11 + position); 
    end Employee


What I have tried:

to slove it and try to write the methods but I can’t
Posted
Updated 23-Sep-21 2:14am
v2
Comments
Member 15329613 22-Sep-21 13:48pm
   
What is your question?

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
   
to slove it and try to write the methods but I can’t
Small wonder, since even after I reformatted it, it is still a mess. You have unclosed blocks (missing close brace characters). Missing braces completely for certain blocks. An open parenthesis, wher an open brace is required. And 'end' statement that does not exist in Java ...

I suggest you go to Java Tutorials Learning Paths[^] and start learning the language properly.
   
A minimilistic, compilable and runnable, version of your code.
Java
abstract class Employee
{
  private String name;
  private long cprNum;
  private String position;
  public Employee ( )
  {
        this ("Unknown", 0, "Unknown");
  }
  public Employee (String eName, long code, String pos)
  {
        setName (eName) ;
        setCprNum(code);
        setPosition (pos);
  }
  public void setName (String eName)
  {
        name = eName;
  }
  public boolean setCprNum(long code)
  {
    if (code > 0 && code < 100000000)
    {
      cprNum = code;
      return true;
    }
    else
    {
      System.out.println("Invalid CPR, initializg it to 0");
      cprNum = 0;
      return false;
    }
  }
  public void setPosition (String pos)
  {
    position = pos;
  }
  public String getName ( )
  {
    return name;
  }
  public long getCprNum( )
  {
    return cprNum;
  }
  public String getPosition( )
  {
    return position;
  }
  public abstract double salary( ); // abstract method 
  public String toString( )
  {
        return ("Name: " + name + ", CprNum: " + cprNum + ", Position: " + position);
  }
}

public class LuckyEmployee extends Employee
{
  @Override
  public double salary( ) { return 1000000; }
  public static void main( String arg[] )
  {
    LuckyEmployee lemp = new LuckyEmployee();
    System.out.println(lemp.toString() + ", Salary: " + lemp.salary());
  }
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900