This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2021/8/11

can yuh tell me what is wrong and what I am missing.

1
2
danpost danpost

2021/8/14

#
divinity wrote...
i still dont understand what u mean
No code should follow after the end of the while loop currently ending at line 54 (except maybe a "Goodbye." message being given -- as I had shown above).
Move line 54 to the end of the code.
there is no input line following the main menu (should be a scanin line at 35).
Insert at line 35:
command = scanin.next();
divinity divinity

2021/8/14

#
I did just that and put there but the result hasnt changed, danpost there is something wrong with it. I cant seem to figure it out. and i also removed line 54 to end of the line and you know what i get when i run it. nothing. here is the revised code
package personnel;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author User
 */
public class Personnel {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scanin = new Scanner(System.in);
        
        
        String firstname, lastname;
        double hourlywage;
        String command = "";
        String n,p,r, s,h;
        double annualsalary, new_wage;
        double hoursworked;
        double hourly =0, salaried=0;
        float percentinc;       
        Employee[] newemp = new Employee[50];
        
        while(command.equalsIgnoreCase("q")){
            System.out.print("Please select one of the following option");
            System.out.print("n - Select new employee");
            System.out.print("p - To compute paychecks");
            System.out.print("r - For raise wages");
            System.out.print("q - To quit");
            command = scanin.next();
            
        if(command.equals("n")){
            System.out.print("Enternew employee name");
            firstname = scanin.next();
            System.out.print("Enter new employee last name");
            lastname = scanin.next();
        }else if(hourly == 'h' || salaried == 's'){
            System.out.print("Enter number of hourly wage");
        }else if(command.equals("n")){
            System.out.print("Enter new employee name");
            firstname = scanin.next();
            
            System.out.print("Enter last name");
            lastname = scanin.next();
        }else if(hourly == 'h' || salaried == 's'){
            System.out.print("Enter annual salary");
            annualsalary = scanin.nextDouble();
        }
     
     
        if(command.equals("p")){
            System.out.print("Enter number of hours worked");
            hoursworked = scanin.nextDouble();
        }else if(command.equals("r")){
            System.out.print("Enter percentage increase");
            percentinc = scanin.nextFloat();
        } else{
            System.out.print("Enter new wages");
            new_wage = scanin.nextDouble();
        }
        while(!command.equals("q")){
            System.out.println("Enter a number or q to quit");
            command = scanin.next();
        }   
        if(!command.equals("q")){
            int num = Integer.parseInt(command);
            
       }
    } 
    
}
 
}
and here is the result when i run the code
BUILD SUCCESSFUL (total time: 0 seconds)
danpost danpost

2021/8/14

#
Remove lines 42 and 43. Remove lines 50 thru 53. Remove lines 62 thru 65. None of those codes are main menu options. They must be coded at a deeper level (within one of the other options). Remove lines 66 thru 71. 'q' is taken care of within the while condition itself (line 29). Except that you need to negate that condition (add an '!' to it).
divinity divinity

2021/8/15

#
I did as you said to do and I am still getting the same result as above. here is the revised version
import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author User
 */
public class Personnel {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scanin = new Scanner(System.in);
        
        
        String firstname, lastname;
        double hourlywage;
        String command = "";
        String n,p,r, s,h;
        double annualsalary, new_wage;
        double hoursworked;
        double hourly =0, salaried=0;
        float percentinc;       
        Employee[] newemp = new Employee[50];
        
        while(command.equalsIgnoreCase("!q")){
            System.out.print("Please select one of the following option");
            System.out.print("n - Select new employee");
            System.out.print("p - To compute paychecks");
            System.out.print("r - For raise wages");
            System.out.print("q - To quit");
            command = scanin.next();
            
        if(command.equals("n")){
            System.out.print("Enter new employee name");
            firstname = scanin.next();
            System.out.print("Enter new employee last name");
            lastname = scanin.next();
        }
        else if(command.equals("n")){
            System.out.print("Enter new employee name");
            firstname = scanin.next();
            
            System.out.print("Enter last name");
            lastname = scanin.next();
        
        }
     
        if(command.equals("p")){
            System.out.print("Enter number of hours worked");
            hoursworked = scanin.nextDouble();
        }else if(command.equals("r")){
            System.out.print("Enter percentage increase");
            percentinc = scanin.nextFloat();
        } 
        
    } 
    
}
 
}
Super_Hippo Super_Hippo

2021/8/15

#
I guess it should be
while(!command.equalsIgnoreCase("q"))
instead of
while(command.equalsIgnoreCase("!q"))
divinity divinity

2021/8/16

#
hi super_Hippo, I did that and I am still getting the same result. something wrong somewhere in the codes.
BUILD SUCCESSFUL (total time: 0 seconds)
divinity divinity

2021/8/18

#
hi danpost, super_Hippo. please take a look at all of the classes in the program and tell me what I am missing or where I have gone wrong and what can be fix. because I am not getting the result that I am looking for I am stating with the employee class, then the employee class, hourlyemployee class, then salariedemployee class, and then the main, which is the personnel class and the result expected. so here goes: the employee class
    String firstname;
    String lastname;
    double hourlywage;
    float rate;
    double pay;
    int extrahours;
    double wagepercentage;
    boolean wage;
    

public Employee(String firstname, String lastname, double hourlywage){
    
    this.firstname = firstname;
    this.lastname = lastname;
    setWage(hourlywage);
        
    }
   
    public abstract double comPay(double hours);{
    
    pay=(40 * rate)+ (extrahours * rate + 1.5);
   }
    
    public String getfirstname(){
        return firstname;
    }
    public String getlastname(){
        return lastname;
    }
    public double gethourlywage(){
        return hourlywage;
    }
    public void setfirstname(String firstname){
        this.firstname = firstname;
    }
    public void setlastname(String lastname){
        this.lastname = lastname;
    }
   
     public void setWage(double hourlywage) {
         wage = (hourlywage < 0.0) && (hourlywage <= 1.5);
        
    }
    public void wagepercentage(double percentage){
        wagepercentage = wagepercentage * ((100 + percentage)/100);
        
    }
    @Override
    public String toString(){
        return "Employee details "+"\n"+ "Employee firstname is"+ firstname+"\n"+"Employee last name is:  "+"" + "Hourly wage is "+hourlywage;
    }

}
the hourlyemployee class
package personnel;

/**
 *
 * @author User
 */
public  class HourlyEmployee extends Employee {
    
    String firstname;
    String lastname;    
    float rate;
    double comPay;
    double hourlyWage;    
    double totalpay=0;
    double wage;
    double hours;

    public HourlyEmployee(String firstname, String lastname, double hourlywage) {
        super(firstname, lastname, hourlywage);
        setWage(hourlyWage);
    }
    
    public  double comPay(){
        
        return 0;
    }
    public String getfirstname(){
        return firstname;
    }
    public String getlastname(){
        return lastname;
    }
    public double gethourlywage(){
        return hourlywage;
    }
    public void setfirstname(String firstname){
        this.firstname = firstname;
    }
    public void setlastname(String lastname){
        this.lastname = lastname;
    }
    public void sethourlywage(double hourlywage){

        this.hourlywage = hourlywage;
     }
        
    public double getWage(){
        return wage;
    }

     public void setWage(double hourlyWage) {
      // wage =
    }
     public double getHours() {
        return hours;
    }
  
    public void setHours(double hoursWorked){
      
      hours = hoursWorked;
        
    }
    
    public double earnings(){
      if(getHours()<=40)       
       
      return getWage()* getHours();
      
     return 40 * getWage() + (getHours() - 40 * getWage() * 1.5);
       
    }
    
    @Override
    public String toString(){
        return "Employees details"+ " "+ "First name is "+ firstname+""+"Hourlywage is "+hourlywage;
    }

}
the salariedemployee class
public class SalariedEmployee extends Employee {
    
    String firstname;
    String lastname;
    double annualsalary;
    double comPay, salary;
    int hours;
    
    
    public SalariedEmployee(String firstname,String lastname, double annualsalary){
        super(firstname, lastname, annualsalary);
        salary = this.annualsalary;
    }
    public String getfirstname(){
        return firstname;
    }
    public String getlastname(){
        return lastname;
    }
    public double getannualsalary(){
        return annualsalary;
    }
    public void setfirstname(String firstname){
        this.firstname = firstname;
    }
    public void setlastname(String lastname){
        this.lastname = lastname;
    }
    public void setannualsalary(double annualsalary){
        this.annualsalary = annualsalary;
    }
   
    public double comPay(double hours) {
        if(hours > 40){
            double extrahours = hours - 40;
            pay = (40 * rate) + (extrahours * rate);
        }
        else{
            pay =  hours * rate;
        }
       return annualsalary;
    }
    
    public String toString(){
        return "Salaried Employee "+"\n"+"Employee name is"+firstname+"\n"+"Annual Salaried is"+ annualsalary;
    }

}
the personnel class (main class)
 */
public class Personnel {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner keyin = new Scanner(System.in);
        
        
        String firstname, lastname;
        double hourlywage;
        String command = "";
        String n,p,r, s,h;
        double annualsalary;
        double hoursworked;
        double hourly =0, salaried=0;
        float percentage;       
        Employee[] newemp = new Employee[50];
        
        while(command.equalsIgnoreCase("q")){
            System.out.print("Please select one of the following option");
            System.out.print("n - Select new employee");
            System.out.print("p - To compute paychecks");
            System.out.print("r - For raise wages");
            System.out.print("q - To quit");
            command = keyin.next();
            
        if(command.equals("n")){
            System.out.print("Enter new employee name");
            firstname = keyin.next();
            System.out.print("Enter new employee last name");
            lastname = keyin.next();
        if(hourly == 'h' || salaried == 's'){
            System.out.print("Enter hourly wage");
            hourlywage = keyin.nextDouble();
            
        }else{
            System.out.print("");
        }
     }
        else if(command.equals("n")){
            System.out.print("Enter new employee name");
            firstname = keyin.next();            
            System.out.print("Enter last name");
            lastname = keyin.next();
        if(hourly == 'h' || salaried == 's'){
            System.out.print("Enter annual salary");
            annualsalary = keyin.nextDouble();
        }
     }
     
        if(command.equals("p")){
            System.out.print("Enter number of hours worked");
            hoursworked = keyin.nextDouble();
        }else if(command.equals("r")){
            System.out.print("Enter percentage increase");
            percentage = keyin.nextFloat();
        } 
        
    } 
    
}
 
}
I have added back some code. I guess u will see why I added back in and this is the result that I am looking for Commands: n- New employees p- Compute paychecks r- Raise wages q- Quit Enter command: n Enter name of new employee: Plumber, Phil Hourly (h) or salaried (s): h Enter hourly wage: 40.00 Commands: n- New employees p- Compute paychecks r- Raise wages q- Quit Enter command: n Enter name of new employee: Coder, Carol Hourly (h) or salaried (s): s Enter annual salary: 80000 Commands: n- New employees p- Compute paychecks r- Raise wages q- Quit Enter command: p Enter number of hours worked by Plumber, Phil: 50 Pay: $2200.00 Enter number of hours worked by Coder, Carol: 50 Pay: $ 1538.46 Commands: n- New employees p- Compute paychecks r- Raise wages q- Quit Enter command: r Enter percentage increase: 4.5 New Wages -------------------- Plumber, Phil $41.80/hour Coder, Carol $ 83600.00/year Commands: n- New employees p- Compute paychecks r- Raise wages q- Quit Enter command: q the result above is how the program should run : please tell me how I can get the program to run just like the result show.
danpost danpost

2021/8/19

#
You need a menu to show first and foremost. Once you get that, you will need to re-write all codes below line 28.
divinity wrote...
hi super_Hippo, I did that and I am still getting the same result
After doing this, you should at least get a menu to show up. If no menu shows, then you may need to strip it down and start with bare minimum, to build from there. Note: after each addition of new implementation, it should do what you want. That is, the program should run and the new codes should perform as wanted. In other words, work on one thing at a time; get it working properly before moving on to the next thing. It is hard to build onto something that is already flawed.
You need to login to post a reply.
1
2