What's new

Java Pa help sure napo ako Java po ito dami kasi error

RIMURU_tempest300

Eternal Poster
Established
Joined
Jul 2, 2019
Posts
823
Solutions
1
Reaction
1,216
Points
449
Ito Task
"write a program by creating an "Employee" class having the following method and print the final salary.
-'getinfo()'which takes the salary, number of hours of work per day of employee as parameter
-_'AdSal()'which adds P100 to salary of the employee if its is less than P500.
-'AddWork()'which adds P500 to salary of the employee if the number of hours of work per day is more than 6 hours."


TAPOS ito po code ko
class Main{

float.salary.no_of_hours

void getinfo(float no_of_hours,float salary)
{
this.salary=salary;
this.no_of_hours_=no_of_hours;
}
void addSalary();

Test(salary<500);

salary+=100()


void addWork();

Test(no_of_hours>6)

salary+=500;


void printSalary();

System.out.println("Final Salary of the employee ="+salary+"$");

public static void main(String[] args)

System.out.println("Enter the salary of Employee:");
float salary=sc.nextFloat;

System.out.println("Enter the number of working hours:");
float no_of_hrs=sc.nextFloat;

Employee emp = new Employee2();
emp.getinfo(no_of_hrs.salary);
emp.addSalary();
emp.addWork();
emp.printSalary();
}
}




ITO PO ERROR diko kasi maintindihan kung ano po <identifier> meaning nyan hehe


+ javac -cp . Main.java
Main.java:3: error: <identifier> expected
float.salary.no_of_hours
^
Main.java:12: error: invalid method declaration; return type required
Test(salary<500);
^
Main.java:12: error: îllégâl start of type
Test(salary<500);
^
Main.java:14: error: <identifier> expected
salary+=100()
^
Main.java:14: error: ';' expected
salary+=100()
^
Main.java:19: error: invalid method declaration; return type required
Test(no_of_hours>6)
^
Main.java:19: error: <identifier> expected
Test(no_of_hours>6)
^
Main.java:26: error: <identifier> expected
System.out.println("Final Salary of the employee ="+salary+"$");
^
Main.java:26: error: îllégâl start of type
System.out.println("Final Salary of the employee ="+salary+"$");
^
Main.java:28: error: ';' expected
public static void main(String[] args)
^
Main.java:33: error: <identifier> expected
System.out.println("Enter the number of working hours:");
^
Main.java:33: error: îllégâl start of type
System.out.println("Enter the number of working hours:");
^
Main.java:37: error: <identifier> expected
emp.getinfo(no_of_hrs.salary);
^
Main.java:37: error: <identifier> expected
emp.getinfo(no_of_hrs.salary);
^
Main.java:38: error: <identifier> expected
emp.addSalary();
^
Main.java:39: error: <identifier> expected
emp.addWork();
^
Main.java:40: error: <identifier> expected
emp.printSalary();
^
Main.java:42: error: class, interface, or enum expected
}
^
18 errors
+ java -cp . Main
Error: Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
 
Di ko lang alam kung ano ang dapat na ginagawa ng Test() sa code mo pero pwede sigurong "If" nalang ang gamitin mo. Tulad nito:

JavaScript:
//Main.java

import java.util.Scanner;

public class Main {
 

  public static void main(String Args[])
  {
    Scanner input = new Scanner(System.in);
   
    System.out.printf("Enter Salary: ");
    float salary = input.nextFloat();
   
    System.out.printf("Enter No. of Work Hours per Day: ");
    float hours = input.nextFloat();
   
    Employee emp = new Employee();
    emp.GetInfo(salary, hours);
    emp.AdSal();
    emp.AddWork();
    emp.printSalary();
  }
}

JavaScript:
//Employee.Java

public class Employee{
 
  float salary, hours;
 
  void GetInfo(float sal, float n_hours)
  {
    this.salary = sal;
    this.hours = n_hours;
  }
 
  void AdSal()
  {
    if(this.salary < 500)
    {
      this.salary += 100;
    }
  }
 
  void AddWork()
  {
    if(hours > 6)
    {
      this.salary += 500;
    }
  }
 
  void printSalary()
  {
    System.out.printf("Total Salary: %.2f\n", this.salary);
  }
}

Output:
1652333879872.png
 

Attachments

Di ko lang alam kung ano ang dapat na ginagawa ng Test() sa code mo pero pwede sigurong "If" nalang ang gamitin mo. Tulad nito:

JavaScript:
//Main.java

import java.util.Scanner;

public class Main {
 

  public static void main(String Args[])
  {
    Scanner input = new Scanner(System.in);
 
    System.out.printf("Enter Salary: ");
    float salary = input.nextFloat();
 
    System.out.printf("Enter No. of Work Hours per Day: ");
    float hours = input.nextFloat();
 
    Employee emp = new Employee();
    emp.GetInfo(salary, hours);
    emp.AdSal();
    emp.AddWork();
    emp.printSalary();
  }
}

JavaScript:
//Employee.Java

public class Employee{
 
  float salary, hours;
 
  void GetInfo(float sal, float n_hours)
  {
    this.salary = sal;
    this.hours = n_hours;
  }
 
  void AdSal()
  {
    if(this.salary < 500)
    {
      this.salary += 100;
    }
  }
 
  void AddWork()
  {
    if(hours > 6)
    {
      this.salary += 500;
    }
  }
 
  void printSalary()
  {
    System.out.printf("Total Salary: %.2f\n", this.salary);
  }
}

Output:
View attachment 1935746
ayy yung Test() mali po yun "if" talaga dapat yun diko na delete pero thank u very much lods😍mabuhay ka hanggat gusto mo hehe

Di ko lang alam kung ano ang dapat na ginagawa ng Test() sa code mo pero pwede sigurong "If" nalang ang gamitin mo. Tulad nito:

JavaScript:
//Main.java

import java.util.Scanner;

public class Main {
 

  public static void main(String Args[])
  {
    Scanner input = new Scanner(System.in);
 
    System.out.printf("Enter Salary: ");
    float salary = input.nextFloat();
 
    System.out.printf("Enter No. of Work Hours per Day: ");
    float hours = input.nextFloat();
 
    Employee emp = new Employee();
    emp.GetInfo(salary, hours);
    emp.AdSal();
    emp.AddWork();
    emp.printSalary();
  }
}

JavaScript:
//Employee.Java

public class Employee{
 
  float salary, hours;
 
  void GetInfo(float sal, float n_hours)
  {
    this.salary = sal;
    this.hours = n_hours;
  }
 
  void AdSal()
  {
    if(this.salary < 500)
    {
      this.salary += 100;
    }
  }
 
  void AddWork()
  {
    if(hours > 6)
    {
      this.salary += 500;
    }
  }
 
  void printSalary()
  {
    System.out.printf("Total Salary: %.2f\n", this.salary);
  }
}

Output:
View attachment 1935746
last po lods ano po itong error na ito? thank u in advance po hehe

Screenshot_2022-05-12-17-52-43-72_a927ed2714ba3b9021f681846134c26f.jpg
 

Attachments

Last edited:
Last edited:

Similar threads

Back
Top