Java Question

So here is the basis of my code, I need help with inputting the correct code which will allow me to create a class that writes employee payroll records to a file and a class that checks that the records have been written. please help!

import java.util.Scanner;

public class EmployeePayroll
{
//STUDENTS INSERT LINE COMMENTS FOR EACH VARIABLE.
private String employeeName = “”;
private int hoursWorked = 0;
private double payRate = 0.0;
private double grossPay = 0.0;
private double retire401K = 0.0;
private double percent401K = 0.0;
private double grossPayTotal = 0.0;
private double total401K = 0.0;
private int firstNmLength = 0;

private Scanner input = new Scanner(System.in);

/**
* STUDENTS ARE TO INSERT COMMENT BOXES FOR EACH METHOD.
*/
public EmployeePayroll()
{
}//STUDENTS ARE TO INSERT LINE COMMENTS FOR EACH CLOSE BRACE.

public EmployeePayroll(String emplName, int hrsWrkd, double hourlyPay, double retirementPercent)
{
setEmployeeName(emplName);
setHoursWorked(hrsWrkd);
setPayRate(hourlyPay);
set401K(retirementPercent);
}

public final void setEmployeeName(String employeeName)
{
while(!isAlpha(employeeName))
{
System.out.printf(“%nEnter valid first name: “);
employeeName = input.nextLine();
}

this.employeeName = employeeName;
}

public void setEmployeeName(int i)
{
String first = “”, last = “”;

System.out.printf(“%nEnter the %semployee\’s first name press enter then the last “
+ “name press enter: “, i == 0 ? “” : “next “);
first = input.nextLine();
last = input.nextLine();

while(!isAlpha(first))
{
System.out.printf(“%nEnter valid first name: “);
first = input.nextLine();
}

firstNmLength = first.length();

while(!isAlpha(last))
{
System.out.printf(“%nEnter valid last name: “);
last = input.nextLine();
}

employeeName = first + ” ” + last;
}

public final void setHoursWorked(int hoursWorked)
{
this.hoursWorked = hoursWorked;
}

public void setHoursWorked(String first)
{
System.out.printf(“%nEnter the number of hours worked for %s: “, first);

while(!input.hasNextInt())
{
input.next();
System.out.printf(“%nInvalid type! Re-enter the number of “
+ “hours worked for %s: “, first);
}
hoursWorked = input.nextInt();

while(hoursWorked > 40 || hoursWorked < 5)
{
hoursWorked = testHoursWorked(hoursWorked);
}

}

public final void setPayRate(double payRate)
{
this.payRate = payRate;
}

public void setPayRate()
{
System.out.printf(“%nEnter the employee\’s hourly pay rate: “);

while(!input.hasNextDouble())
{
input.next();
System.out.printf(“%nInvalid type! Re-enter the hourly pay rate: “);
}
payRate = input.nextDouble();

while(payRate < 7.25 || payRate > 26.00)
{
payRate = testPayRate(payRate);
}
}

public void calcGrossPay()
{
grossPay = hoursWorked * payRate;
}

public final void set401K(double percent401K)
{
this.percent401K = percent401K;
}

public void set401K()
{
System.out.printf(“%nEnter the employee\’s 401K contribution “
+ “as a percentage of salary (not to exceed 10%%): “);

while(!input.hasNextDouble())
{
input.next();
System.out.printf(“%nInvalid type! Re-enter the 401K contribution “
+ “not to exceed 10%% of salary: “);
}
percent401K = input.nextDouble();

while(percent401K > 10.00)
{
percent401K = test401K();
}
}

public void calcRetire401K()
{
retire401K = percent401K/100 * grossPay;
}

public String getEmployeeName()
{
return employeeName ;
}

public int getHoursWorked()
{
return hoursWorked;
}

public double getPayRate()
{
return payRate;
}

public double get401K()
{
return percent401K;
}

public double getGrossPay()
{
return grossPay;
}

public double getRetire401K()
{
return retire401K;
}

public int testHoursWorked(int hoursWorked)
{
if(hoursWorked > 40)
{
System.out.printf(“%nHours worked cannot EXCEED 40. Please re-enter: “);
}

if(hoursWorked < 5)
{
System.out.printf(“%nHours worked cannot be LESS than 5. Please re-enter: “);
}

while(!input.hasNextInt())
{
input.next();
System.out.printf(“%nInvalid type! Re-enter the number of hours “
+ “worked not less than 5 or greater than 40: “);
}

return input.nextInt();
}

public double testPayRate(double payRate)
{
if(payRate < 7.25)
{
System.out.printf(“%nHourly pay cannot be LESS than $7.25. Please re-enter: “);
}

if(payRate > 26)
{
System.out.printf(“%nHourly pay cannot EXCEED $26.00. Please re-enter: “);
}

while(!input.hasNextDouble())
{
input.next();
System.out.printf(“%nInvalid type! Re-enter an hourly pay rate that “
+ “is not less than $7.25 or greater than $26.00: “);
}

return input.nextDouble();
}

public double test401K()
{
System.out.printf(“%nContribution cannot EXCEED 10%%. Please re-enter: “);

while(!input.hasNextDouble())
{
input.next();
System.out.printf(“%nInvalid type! Re-enter a contribution “
+ “NOT exceeding 10%% of salary: “);
}
return input.nextDouble();
}

public boolean isAlpha(String name)
{
return name != null && name.chars().allMatch(Character::isLetter);
}

}

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount

Posted in Uncategorized

Java Question

Instructions

  1. Review the Assessment Criteria to make sure you understand the criteria for earning your grade for this assignment.
  2. Create the workshop folder with name of the form LastnameFirstname Workshop Four.
  3. In the workshop folder, create an exercise folder for each programming exercise. This folder contains all files required by and resulting from completion of the assigned exercise.
  4. Any exercise that indicates “Write a method called …” presumes that the required method will be included in a fully running program (class). The main method will invoke any required method(s) providing the calling parameters necessary to demonstrate proper function of the method.
  5. Exercise 9.5
    1. The referenced code in both parts is available in the textbook code examples.
    2. Both method powArray and method histogram will be invoked from a main method.
    3. The main method should demonstrate testing the two methods and provide meaningful, formatted output messages.
  6. Exercise 9.2
    1. Factorial is implemented as a recursive method in Chapter 8; a while loop version is depicted at https://www.tutorialspoint.com/Java-program-to-calculate-the-factorial-of-a-given-number-using-while-loop (copy/paste this URL into your browser).
    2. Complete exercise 9.2, addressing all four steps. Include a comment in the factorial method indicating your response to questions in 9.2.4.
    3. The main method should demonstrate testing the factorial method providing meaningful, formatted output messages Use values for which you know the result for basic testing then stress to 30-factorial as required in exercise.
  7. Exercise 10.1, 10.2, and 10.3
    1. Use the Java Tool at PythonTutor.com to visualize the execution of each program.
    2. Use screenshots, annotation, and other responses to clearly address all requirements and questions posed in the exercises.
    3. For Exercises 10.2 and 10.3, only the ‘main’ method is presented. The methods findCenter, distance, and printPoint are available in the PointRect java program in Chapter 10 example code. A complete program must be created with the main and required methods prior to utilizing the Java Tool at PythonTutor.com.
    4. No commenting or variable name style requirements apply on these specific exercises.
  8. Each successful program should include a .java and a .class file. For example, Exercise 2.3 will produce the files Time.java (source) and Time.class (compiled) in an exercise folder.
  9. All elements of the assignment will be in a single folder (see Step 2).
    1. Create a zip archive of the workshop folder including all files and exercise folders and submit it for grading.
  10. Points will be deducted:
    1. For lack of Javadoc comment format for class and method comments and relevant tags as depicted in Appendix B.
    2. For insufficient comments, unconventional variable naming, or unstructured program formatting in the programming that may cause reading difficulty.
    3. For any minor grammar related compile error or for any major structure or function related compile error that causes compile failure to generate a new .class file.
    4. For any runtime error with any valid input and expected output per original requirements in the exercise.
    5. For any runtime failure to identify any invalid input, send out a warning message, and allow users to re-enter a valid input to continue processing.
  11. When you have completed your assignment, submit the Zip archive created in step 9 to your instructor using the Assignment submission by the end of the workshop .

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount

Posted in Uncategorized

Java Question

Overview

UML class diagrams are useful tools for mapping out different classes for an object-oriented program. The UML class diagram displays the attributes and methods of each class as well as showing relationships between classes. In this activity, you will analyze a UML class diagram and implement either the Cat or the Dog class. The purpose of this activity is to give you practice interpreting a UML class diagram and implementing a class based on that diagram. Implementing classes based on a UML diagram is a valuable skill to help you work as a part of a development team. This assignment will also help prepare you to implement the Pet class as part of your Project One submission.

Prompt

For this assignment, you will select either the Cat or the Dog Java class from the UML diagram. Open the Virtual Lab (Apporto) by clicking on the link in the Virtual Lab Access module. Then open your Eclipse IDE and create a new class. Use the Eclipse IDE Tutorial if you need help with creating a class in Eclipse.

  1. Before you begin, review the following UML Class Diagram, paying special attention to the attributes and behaviors of each class. As a note, though the diagram illustrates an inheritance relationship between the classes, the class you choose to implement does not have to inherit from the Pet class for the purposes of this assignment. You will learn more about implementing inheritance in later modules.

This UML Class diagram shows three classes: Pet, Dog, and Cat. The Dog and Cat classes inherit from the Pet class. Each class is described below. The Pet class variables are petType, petName, petAge, dogSpaces, catSpaces, daysStay, and amountDue. All variables are private. The Pet class methods are getPetType, setPetType, getPetName, setPetName, getPetAge, setPetAge, getDogSpaces, setDogSpaces, getCatSpaces, setCatSpaces, getDaysStay, setDaysStay, getAmountDue, and setAmountDue. All methods are public. The Dog class variables are dogSpaceNumber, dogWeight, and grooming. All variables are private. The Dog class methods are getDogSpaceNumber, setDogSpaceNumber, getDogWeight, setDogWeight, getGrooming, and setGrooming. All methods are public. The only variable in the Cat class is catSpaceNumber, which is private. The methods are getCatSpaceNumber and setCatSpaceNumber. All methods are public.

  1. Next, you will implement either the Cat or Dog Java class. Your class must meet all of the specifications from the UML Class diagram. Be sure to include the following in your Cat or Dog class:
    • All attributes (variables) with appropriate data types. Note that the types are not specified in this UML class diagram. You will need to think about what the most appropriate data type is for each attribute.
    • At least one constructor method that initializes values for all attributes
    • Accessors and mutators for all attributes. Each attribute should have a corresponding accessor (“getter”) and mutator (“setter”) method. These methods are indicated in the class diagram.
    • In-line comments and appropriate white space, according to the style guidelines you have learned so far in the course

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount

Posted in Uncategorized

Java Question

  1. Complete exercise 1.3 in your textbook.
    1. For each of the 10 actions, copy the observed error message or capture a screenshot depicting result.
    2. If no error message, attempt to run the program.
    3. If an error occurs when running the program, copy the observed error message or capture a screenshot.
    4. Results from items a, b, and c will be copied to a Microsoft Word document with a name of the form LastnameFirstnameOne.
    5. The document should be formatted clearly identify the result of each of the 10 actions.
  2. Complete exercise 2.3, steps 1 through 6 in the textbook.
  3. Complete exercise 3.3 in the textbook.
  4. Basic style requirements:
    1. As noted in the textbook, the primary examples in the reading are succinct in that they minimize comments and utilize terse variable names to conserve page space. Reviewing the example files provided, one observes more appropriate style.
    2. Inside your Java programs (Java source code) be sure to include all necessary comments. At the beginning of each Java program you must include the following minimum lines of comments .

      // Exercise Name: Exercise 2.3 Time.java
      // Student Name: Your Name
      // Date: October 10, 2019
      // This program demonstrates use of basic arithmetic operators and
      // initiates thinking about compound entities represented by multiple values.

    3. Variable names must be meaningful in appropriate case.
    4. Class names and method names must be meaningful in appropriate case.
    5. Statements will be appropriately indented as depicted in the textbook examples (set Indent Level of DrJava to 5).
    6. Java source code must be well written, readable with appropriate white space, and inline comments.
  5. Each successful program should include a .java and a .class file.
  6. All elements of the assignment will be in a single folder (see Instruction 2) .
    1. Create a zip archive of the workshop folder including all files and exercise folders and submit it for grading using the assignment submission link.
    2. For example, Exercise 2.3 will produce the files Time.java (source) and Time.class (compiled) in an exercise folder.
    3. The workshop folder will include a Word document for exercise 1.3 and exercise folders for exercises 2.3 and 3.3.
  7. The following will result in the loss of points:
    1. Insufficient comments, unconventional variable naming, or unstructured program formatting in the programming that may cause reading difficulty.
    2. Any minor grammar related compile error, or any major structure or function related compile error that causes a compile failure generating a new .class file.

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount

Posted in Uncategorized

Java Question

You must submit two separate copies (one Word file and one PDF file)using the Assignment Template on Blackboard via the allocated folder. These files must not be in compressed format.

It is your responsibility to check and make sure that you have uploaded both the correct files.

Zero mark will be given if you try to bypass the SafeAssign (e.g. misspell words, remove spaces between words, hide characters, use different character sets, convert text into imageor languages other than English or any kind of manipulation).

You are advised to make your work clear and well-presented. This includes filling your information on the cover page.

You must use this template, failing which will result in zero mark.

You MUST show all your work, and text must not be converted into an image, unless specified otherwise by the question.

The work should be your own, copying from students or other resources will result in ZERO mark.

Use Times New Roman font for all your answers.

1.5 Marks

Learning Outcome(s): Explain the basic principles of programming, concept of language, and universal constructs of programming languages. Develop a program based on specification using programming language elements including syntax, data types, conditional statement, control structures, procedures, arrays, objects and classes.

Question One

Write a complete Java program that do the following:1. Print out your name in one line2. Print out your ID in one line3. Ask the user to enter his weight and height, thencalculate his Body Mass Index According to the following formula and displayhis BMI.BMI= Note:Your program output should lookas shown below. Note: you should Include the screenshot of the programoutput as a part of your answer. Otherwise,zeromarks will be awarded.

1.5 Marks

Learning Outcome(s): Develop a program based on specification using programming language elements including syntax, data types, conditional statement, control structures, procedures, arrays, objects and classes.

Question Two

Write a Java program that readstwo integers in two variables x and y and then permutes the value of the twovariables. Note: your program should look like this:Enter x: 2Enter y: 5The new value of the variable x is: 5The new value of the variable y is: 2Note: you should Include the screenshot of the programoutput as a part of your answer. Otherwise,zeromarks will be awarded.

2 Marks

Learning Outcome(s): Develop a program based on specification using programming language elements including syntax, data types, conditional statement, control structures, procedures, arrays, objects and classes.

Question Three

Write an application that calculates the squaresand cubes of the numbers from 0 to 10 and prints the resulting values in tableformat, as shown below. (Use the formatting for printing)Note:Your program output should lookas shown below.Note:you should Include the screenshot of the program output as a part of youranswer. Otherwise,zeromarks will be awarded.

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount

Posted in Uncategorized

Java Question

⚡ PROBLEMS to be answered

Homework 1

Objects – Pick one of the following scenarios and

  • model using at least 7 classes: one parent, two children, two grandchildren of one of the child classes, and 2 other classes in a has-some or has-a relationship with some of the previous 5 classes. The parent-child relationship is an inheritance (is-a) relationship.
  • Provide at least one typed instance variable and one method that compellingly differentiates each class from the others. Make sure to include the return type and the types of the arguments for any method being proposed.

  • Do not include constructors, getters, setters, or any no argument methods in your description.
  • Do not use the same example as previous posters.

Scenarios – lots of them spring to mind, but I don’t want the list to be too long. In this way, you can compare your ideas with those of other students, and I encourage to consider what other students have posted, you are also encouraged to make suggestions of other’s postings and make additional postings updating your own ideas in light of the suggestions by others.

  • An airplane
  • A train
  • An e-commerce company (eg, Amazon)
  • A city government
  • An airline (aspects of an entire company)
  • A government organization (eg, EPA, Defense)
    • NOTE: A general is not a kind of private, nor is a private a kind of general, for example.
    • Also, a general is not a kind of Defense Department
    • THUS: not all hierarchies are class hierarchies!

Note: This problem is NOT asking for a full implementation of these classes – a UML diagram, or similar level of detail, is adequate.

You will find many of the items in the following helpful:

I would emphasize the following kinds of relationships among classes:

is-a

parent/child relationship in a class hierarchy
perhaps better to use the phrase “is a kind of”, as in “a Private is a kind of Soldier” or “a SportsCar is a kind of Car”

is-some

a data structure in which all the elements have the same type.
This is the place where one should use generic classes.

has-a

an attribute (field) of one class inside another

has-some

a 1-to-n relationship,
a Vehicle will have one or more Occupant instance


PROBLEMS to be answered

For problems 1 through 4, explain why the code as shown is almost certainly not what the programmer intended, and how it should be fixed to work the way the programmer probably had in mind.

1. (10 pts) What is wrong with the following program and how should it be fixed?

1 public class MyClassA {
2 int v = 12;
3
4 public MyClassA (int pV) {
5 v = pV;
6 }
7
8 public static void main (String args []) {
9 MyClassA m = new MyClassA ();
10 } // end main
11 } // end class MyClassA

2. (10 pts) What is wrong with the following program and how should it be fixed?

1 public class MyClassB {
2 int v = 12;
3
4 public void MyClassB (int pV) {
5 v = pV;
6 }
7
8 public static void main (String args []) {
9 MyClassB m = new MyClassB (23);
10 } // end main
11 } // end class MyClassB

3. (10 pts) What is wrong with the following program and how should it be fixed?

1 public class MyClassD {
2 public static void main (String args []) {
3 MyClassC m = new MyClassC (23);
4 } // end main
5 } // end class MyClassD
6
7 class MyClassC {
8 int v = 12;
9
10 public MyClassC (int pV) {
11 int v = pV;
12 }
13
14 } // end class MyClassC

4. (10 pts) What is wrong with the following program and how should it be fixed?

1 public class MyClassE {
2 public static void main (String args []) {
3 MyClassF m = new MyClassF (23);
4 } // end main
5 } // end class MyClassE
6
7 class MyClassF {
8 int v = 12;
9
10 private MyClassF (int pV) {
11 v = pV;
12 }
13
14 } // end class MyClassF

5. (10 pts) Given all the problems identified in problems 1 through 4, explain in detail why the following code works, ie, compiles without errors or warnings.

1 public class MyClassG {
2 public static void main (String args []) {
3 MyClassH m = new MyClassH (23, true);
4 } // end main
5 } // end class MyClassG
6
7 class MyClassH {
8 int v = 12;
9
10 public MyClassH (int x, boolean b) {
11 this (x);
12 }
13
14 private MyClassH (int pV) {
15 v = pV;
16 }
17
18 } // end class MyClassH

6. (10 pts) Explain why the following class hierarchy is not reasonable:

  • DefenseDepartment
    • General
      • Private

7. (10 pts) Give at least one example of a reasonable field for each of the following classes in the following class hierarchy. Be sure that the field is at the right level in the hierarchy.

  • Vehicle
    • Car
    • Airplane
      • Passenger
      • Fighter
      • Bomber
    • SpaceShip

8. (10 pts) Give at least one example of a reasonable method for each of the following classes in the following class hierarchy. Be sure that the method is at the right level in the hierarchy. Constructors, getters and setters don’t count for this problem.

  • Vehicle
    • Car
    • Airplane
      • Passenger
      • Fighter
      • Bomber
    • SpaceShip

9. (10 pts) Are a Private and a Platoon in an encapsulation or an inheritance relationship? Explain

10. (10 pts) Present reasonable parent and child classes for the class Tree (the biological kind). Give a short explanation for why the classes you are proposing are in good parent-child relationships.

Grading Rubric:

Attribute

Meets

Does not meet

Problem 1

10 points
Explains why the code as shown is almost certainly not what the programmer intended.

Explains how it should be fixed to work the way the programmer probably had in mind.

0 points
Does not explain why the code as shown is almost certainly not what the programmer intended.

Does not explain how it should be fixed to work the way the programmer probably had in mind.

Problem 2

10 points
Explains why the code as shown is almost certainly not what the programmer intended.

Explains how it should be fixed to work the way the programmer probably had in mind.

0 points
Does not explain why the code as shown is almost certainly not what the programmer intended.

Does not explain how it should be fixed to work the way the programmer probably had in mind.

Problem 3

10 points
Explains why the code as shown is almost certainly not what the programmer intended.

Explains how it should be fixed to work the way the programmer probably had in mind.

0 points
Does not explain why the code as shown is almost certainly not what the programmer intended.

Does not explain how it should be fixed to work the way the programmer probably had in mind.

Problem 4

10 points
Explains why the code as shown is almost certainly not what the programmer intended.

Explains how it should be fixed to work the way the programmer probably had in mind.

0 points
Does not explain why the code as shown is almost certainly not what the programmer intended.

Does not explain how it should be fixed to work the way the programmer probably had in mind.

Problem 5

10 points
Given all the problems identified in problems 1 through 4, explains in detail why the code works, ie, compiles without errors or warnings.

0 points
Given all the problems identified in problems 1 through 4, does not explain in detail why the code works, ie, compiles without errors or warnings.

Problem 6

10 points
Explains why the class hierarchy is not reasonable.

0 points
Does not explain why the class hierarchy is not reasonable.

Problem 7

10 points
Gives at least one example of a reasonable field for each of the classes.

The field is at the right level in the hierarchy.

0 points
Does not give at least one example of a reasonable field for each of the classes.

The field is not at the right level in the hierarchy.

Problem 8

10 points
Gives at least one example of a reasonable method for each of the classes.

The method is at the right level in the hierarchy.

Does not include constructors, getters and setters.

0 points
Does not give at least one example of a reasonable method for each of the classes.

The method is not at the right level in the hierarchy.

Includes constructors, getters and setters.

Problem 9

10 points
Explains inheritance and encapsulation correctly and in sufficient detail given the example provided.

0 points
Does not explain inheritance and encapsulation correctly and in sufficient detail given the example provided.

Problem 10

10 points
Presents reasonable parent and child classes for the class Tree.

Gives a short explanation for why the classes you are proposing are in good parent-child relationships.

0 points
Does not present reasonable parent and child classes for the class Tree.

Does not give a short explanation for why the classes you are proposing are in good parent-child relationships.

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount

Posted in Uncategorized