Question: Methods Chapter 1) create a class and write the following methods: a) int firstDigit(int n), returning the first digit of the argument b) int lasstDigit(int
Methods Chapter
1) create a class and write the following methods:
a) int firstDigit(int n), returning the first digit of the argument
b) int lasstDigit(int n), returning the last digit of the argument
c) int digits(int n), returning the number of digits of the argument
For example, firstDigit(1729) is 1, lastDigit(1729) is 9, and digits(1729) is 4.
Provide a program that tests your methods from a different class in a non static manner.
2) create a class with the method:
public static String repeat(String str, int n)
that returns the String str repeated n times. For example, repeat("ho", 3) returns hohoho.
Provide a program that tests your methods from a different class in a static manner.
3) Having a secure password is a very important practice, when much of our information is stored online. Write a program that validates a new password, following these rules:
-must be 8 characters long
-at least one upper case letter and one lower case letter
-at least on digit
Write a program that asks for a password, than asks again to confirm it. If the passwords do not match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid.
Objects Chapter
4) Implement a class Student. For the purpose of this exercise, a student has a name and a total quiz score. Supply an appropriate constructor and methods getName(), addQuiz(int score), getTotalScore(), and getAverageScore(). To compute the latter, you need to store the number of quizzes the student took.
Write a program that demonstrates the methods for a group of at least 4 students using an ArrayList to hold Student objects.
File Input and Output Chapter
6) It is a well-known phenomenon that most people are easily able to read a text whose words have two characters flipped, provided the first and last letter of each word are not changed. For example,
I dn'ot gvie a dman for a man taht can olny sepll a wrod one way. (Mark Twain)
Write a program with a method scramble(String word) that reads the contents of a file with a paragraph in it and constructs a scrambled version of the paragraph, randomly flipping two characters other than the first and last for all words greater than length 3.
7) A spreadsheet file can be stored as a comma separated file. For instance if a file called data.csv had the following in it:
name, quiz1, quiz2, quiz3, hw1, hw2, hw3, midterm, final
bill,8,9,10,50,45,43,88,93
jill,9,9,10,50,48,40,90,91
gill,6,5,7,38,22,40,70,73
will,8,9,9,40,45,43,83,94
totals,10,10,10,50,50,50,100,100
It would display in a program like Microsoft excel appropriately.
a) create a file called data.csv with this data on your hard drive.
b) read the file into a program calculating each students final percentage.
c) have the program write a new file with an extra column containing the final percentage for each student, a column heading for the first row, and the last row can end with 100 for its percentage.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
