0% found this document useful (0 votes)
3 views

Tutorial 7

The document outlines a programming tutorial consisting of five activities focused on implementing various Java classes and methods. Activities include creating an Employee class, converting decimal integers to binary recursively, reversing strings recursively, formatting numbers with commas, and assessing password strength based on specific criteria. Each activity specifies deliverables, including the necessary Java files for submission.

Uploaded by

vthanhthanh69
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Tutorial 7

The document outlines a programming tutorial consisting of five activities focused on implementing various Java classes and methods. Activities include creating an Employee class, converting decimal integers to binary recursively, reversing strings recursively, formatting numbers with commas, and assessing password strength based on specific criteria. Each activity specifies deliverables, including the necessary Java files for submission.

Uploaded by

vthanhthanh69
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming 1

Tutorial 7
Activity 1
Implement a class Employee. An employee has a name and a salary. Provide a constructor with
two parameters:

public Employee(String employeeName, double currentSalary)

and methods:

public String getName()


public double getSalary()
public void raiseSalary(double byPercent)

These methods return the name and salary, and raise the employee’s salary by a certain percentage.
Sample usage:

Employee em = new Employee("Harry Jones", 50000);


em.raiseSalary(10); // Harry gets a 10 percent raise
System.out.println(em.getName() + " is paid $" + em.getSalary() + "/month");

Supply an EmployeeTester class that tests all methods.

Deliverable

Employee.java
EmployeeTester.java

Activity 2
Write a program that reads an integer and output its binary form. This exercise was already
included in a previous tutorial. However, this time you’re required to implement a recursive
method to convert a decimal integer into a binary string.

Deliverable

RecursiveDec2Bin.java
Activity 3
Write and run a recursive method to reverse a string.

Expected result

Enter a string: helloworld


The reverse string is: dlrowolleh

Deliverable

RecursiveStringReverse.java

Activity 4
Write a program that reads a number between 1,000 and 999,999 from the user and prints it with
a comma separating the thousands.
(*) Use what you’ve learned about exception handling to make sure the user enters a valid integer
and that integer is between the required range.

Expected result

Please enter an integer between 1000 and 999999: 23456


23,456

Deliverable

ThousandSeparatingComma.java

Activity 5
Ask user to enter a password. Measure its strength with the following rules:
 Length:
o From 8 to 12, 1 point.
o > 12, 2 points.
 Contains at least one uppercase letter: 1 point
 Contains at least one lowercase letter: 1 point
 Contains at least one digit: 1 point
 Contains non-alphanumeric characters (symbols): 1 point
Then rate the strength:
 1-2 points: weak
 3-4 points: medium
 5-6 points: strong

Expected result

Case 1:
Enter a new password: 123456
Strength: 1 (weak)

Case 2:
Enter a new password: andrew1974
Strength: 3 (medium)

Case 3:
Enter a new password: peterX124%_beTTy
Strength: 6 (strong)

Deliverable

PasswordStrength.java

You might also like