需要循环方面的帮助

发布于 2024-10-01 03:22:33 字数 2162 浏览 4 评论 0原文

免责声明:我班上的老师没有提供任何示例,也没有在课堂上展示任何循环示例(他向我们展示的一个示例他说这是错误的,他使用了错误的示例),除此之外,他没有说是否它是一个控制循环、嵌套循环、for、do 或 while 循环,因此我在这里需要帮助,因为我有一个非常懒惰的老师。

我只会发布我需要帮助的事情的一部分(问题循环的第二部分)

编辑:发布完整的问题以供澄清。

Wacky Widgets Welding 公司想要计算未来十年每位员工的加薪幅度。该公司目前计划每年将每位员工的工资增加5%。例如,目前年薪为 25,000 美元的员工明年将赚取 26,250 美元,第二年为 27,562.50 美元,第三年为 28,940.63 美元。设计如下,创建两个类图和伪代码:

a) 一个 Employee 服务类,包含员工 ID 号和员工当前的年薪。包括以下内容:
  i) 一个默认构造函数和一个重载构造函数。
  ii) 每个属性的访问器和修改器方法。

b) PayReport 应用程序类,包含两个方法:main() 方法和 printPayData() 方法。 main() 方法从名为“employee.txt”的文件中读取员工记录,并将它们一次一个地发送到 printPayData() 方法。 printPayData() 方法生成一个报告,显示员工的编号以及该员工未来 10 年每年的工资。

这是我到目前为止从作业和教科书的帮助中收集到的信息。

Public class PayReport

Public void main ()

   Employee oneWorker
   Open (Employee.txt)
   oneWorker = read (Employee.txt)
   while oneWorker is not at end of file
       printPayData = read(employee.txt)
   endwhile
   close(employee.txt)
return

public void printPayData (Employee emp)

   integer gross
   gross = emp.getemployeesalary() * 0.5
   print emp.getemployeeid(), gross
return
endClass

所以我想知道我的循环是否错误,现在的循环有什么缺陷,现在的循环有什么缺陷,以及这个循环需要进行哪些更改。

如果有人需要对我的循环基础进行任何详细说明或澄清,这里有更多信息。

Employee service class

public class Employee

  // declarations
  private employeeid : integer
  private employeesalary : integer

  public Employee ()
      employeeid = 0
      employeesalary  = 0
  return

  public Employee (id : integer, salary : integer)
      employeeid = id
      employeesalary = salary   
  return

  public integer getemployeeid ( ) 
  return employeeid

  public integer getemployeesalary ( ) 
  return employeesalary


  public void setCustomeraget(integer id) 
      employeeid = id
  return

  public void setEmployeesalary (integer salary) 
      employeesalary = salary
  return

End Class

因此,employee.txt = 将来自此处的此类)。

PS:如果需要任何其他信息,我将编辑它并提供更多信息

我的问题是,我基于伪代码的循环是否有缺陷,不起作用,以及我基于伪代码创建的循环是否需要更改。

当我在 ArgoUML 中创建这个类图,然后尝试为其生成代码时,该类没有在那里列出,它是空白的。

前任。

的生成代码

项目可用类

空白(不适用)

DISCLAIMER: The teacher in my class DOES NOT provide any examples or show any examples in class for looping (and the one example he showed us he said it was wrong, he used wrong example), and in addition to that he did not say whether it is a control loop, nested loop, a for, do, or while loop, thus I am in need of assistance of help here as I have a EXTREMELY LAZY TEACHER.

I am only going to post a part of the thing I need help with (Part II of question LOOPING)

Edit: Posted full question for clarification.

The Wacky Widgets Welding Company wants to calculate the pay increase for each of its employees over the next ten years. The company currently plans to increase each employee’s pay by 5 percent each year. For example, an employee who currently earns $25,000 a year will earn $26,250 next year, $27,562.50 the second year, and $28,940.63 the third year. Design the following, creating two class diagrams and pseudocode:

a) An Employee service class that contains an employee id number and the employee’s current yearly salary. Include the following:
  i) A default constructor and an overloaded constructor.
  ii) Accessor and mutator methods for each attribute.

b) A PayReport application class that contains two methods: the main() method and the printPayData() method. The main() method reads Employee records from a file named "employee.txt" and sends them, one at a time, to the printPayData() method. The printPayData() method produces a report that shows employee's number and the salary of the employee for each of the next 10 years.

This is what I gathered so far from the assignment and help from the textbook.

Public class PayReport

Public void main ()

   Employee oneWorker
   Open (Employee.txt)
   oneWorker = read (Employee.txt)
   while oneWorker is not at end of file
       printPayData = read(employee.txt)
   endwhile
   close(employee.txt)
return

public void printPayData (Employee emp)

   integer gross
   gross = emp.getemployeesalary() * 0.5
   print emp.getemployeeid(), gross
return
endClass

So I was wondering am I doing the looping wrong, what are the flaws with the looping right now, and is there any flaws with the looping right now, and what are the changes needed for this looping.

Here is more information if anyone needs any elaboration or clarification of what I am basing my looping on off.

Employee service class

public class Employee

  // declarations
  private employeeid : integer
  private employeesalary : integer

  public Employee ()
      employeeid = 0
      employeesalary  = 0
  return

  public Employee (id : integer, salary : integer)
      employeeid = id
      employeesalary = salary   
  return

  public integer getemployeeid ( ) 
  return employeeid

  public integer getemployeesalary ( ) 
  return employeesalary


  public void setCustomeraget(integer id) 
      employeeid = id
  return

  public void setEmployeesalary (integer salary) 
      employeesalary = salary
  return

End Class

so the employee.txt = would come from this class right here).

PS: if any additional information is needed, I will edit it and provide more information

MY question is, is the loop that I based of my pseudocode flawed, doesn't work, and are changes needed to the loop I created based of my pseudocode.

When I created a class diagram of this in ArgoUML and then tried to generate a code for it, the class is not listed there, it's blank.

EX.

generation code for project

Available Classes

blank (N/A)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情丝乱 2024-10-08 03:22:33

我发现您的代码存在一些问题。

  1. printPayData = read(employee.txt)

当您想要将读取的信息传递给函数时,这看起来像您设置的 printPayData 等于您从文件中读取的内容。这可能更合适。

printPayData( 读取(employee.txt) )

2.
printPayData 不会打印员工未来 10 年的工资。它应该看起来更像这样。

print employeeNumber
integer i = 0
integer salary = current employee Salary

while ( i < 10 )
   print salary
   salary = salary * 1.05
   i = i + 1
end while

I see a couple of problems with your code.

  1. printPayData = read(employee.txt)

This looks like your setting printPayData equal to what you read from the file, when you want to pass the info read to the function. This might be more appropriate.

printPayData( read(employee.txt) )

2.
printPayData does not print out an employees salary over the next 10 years. It should look more like this.

print employeeNumber
integer i = 0
integer salary = current employee Salary

while ( i < 10 )
   print salary
   salary = salary * 1.05
   i = i + 1
end while
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文