COMP1405的assignment1怎么做啊?我一点头绪没有.

狐狸哟

assassinates
注册
2003-03-30
消息
9,439
荣誉分数
0
声望点数
0
我快疯了.

我以前一点编程经验没有.真不知如何下手.
This assignment asks that you program two classes (MarksCalculator and LoanCalculator). Each class should contain the methods described below and be as complete as possible. Part marks might be awarded if the classes are incomplete. For both classes, submit your .java files as well as .txt files containing your output and testing. Also submit a readme.txt file that explains each of your files. You may want to choose filenames such as MarksCalculatorTest.txt , LoanCalculatorTest.txt etc.... Testing will be marked! Submit your assignment using the submission system, which is accessible through any Internet browser. Note!!! If your internet connection at home is down or does not work, we will not accept this as a reason for handing in an assignment late ... so submit the assignment BEFORE it is due!

All assignments will be marked for style, testing and your solutions. So just because you merely complete the questions, it does not mean that you'll get perfect. MAKE SURE TO SUBMIT EVERYTHING WELL AHEAD OF TIME AND USING THE SAME STEPS (AND MACHINE) THAT YOU USED ON ASSIGNMENT #0.

The MarksCalculator Class

This class should have at the following four methods:

1) computePercentage
2) computeLetterGrade
3) getMark
4) main

Note the main method should contain code to test the other three methods. You will be graded on how well you test your code. Using only the test code provided here is not sufficient. The main method should have the following signature:
public static void main (String args[])


Each of these methods is a public static method and should have the return values and parameters described below. If you have any other methods in this class they should only be there to be used by one of the above four methods.

The computePercentage method computes a student’s mark in an imaginary course and returns that mark as a float. The method takes 4 floats as parameters: assign1, assign2, midterm and, exam (in that order). Each of these parameters is the percentage that the student obtained in assignment 1, assignment 2, the midterm and the final exam respectively. The method computes the final grade by assuming that the assignments have equal value and are worth 25% of their final grade, that the midterm is worth 25% of the final grade and that the final exam is worth 50% of the final grade.

Thus the following test code:

float grade;
grade = MarksCalculator.computePercentage(50f,70.0f,70.0f,80.0f);
System.out.println("The computed percentage is: " + grade);

Should generate the following output:

The computed percentage is: 72.5


The computeLetterGrade method decides what letter grade the parameter corresponds to and returns that letter as a char. The method takes a single float as a parameter: percentGrade. The letter grades are given according to the following table:

percentGrade Letter Grade
Less than 50.0 F
50.0 or more and less than 60.0 D
60.0 or more and less than 70.0 C
70.0 or more and less than 80.0 B
80.0 or more A

The following test code:

char grade;
grade = MarksCalculator.computeLetterGrade(72.5f);
System.out.println("The corresponding grade is: " + grade);

Should generate the following output:

The corresponding grade is: B



The getMark method asks the user to enter two numbers: The first number is the full mark of an assignment, which must be an integer greater than 0, and the second number is the actual mark obtained by a student. This number is also an integer, which is greater than or equal to 0, and less than or equal to the full mark. Then the program calculates the percentage and returns it as a float (maximum of 100 minimum of 0). If the user entered a value, which is not in the given range, your program should output an error message and ask the user to re-enter it. The output of a test run of the method is shown below. NOTE: The error messages for incorrect input should be identical to those in the example below. This method will use the Keyboard class. To download this class please go to www.scs.carleton.ca/~courses/assignments/Keyboard.java

The following test code:

float mark;
mark = MarksCalculator.getMark();
System.out.println("The grade entered was: " + mark);

Should generate the following output (given the stated input):

Please enter the maximum grade: -10
The maximum grade must be greater than zero
Please enter the maximum grade: 0
The maximum grade must be greater than zero
Please enter the maximum grade: 21
Please enter the achieved grade: 24
Please enter a number less than 22
Please enter the achieved grade: -10
Please enter a positive integer
Please enter the achieved grade: 11
The grade entered was: 52.38095


The LoanCalculator Class

This class should have three methods:

1) sizeOfPayments
2) checkPayment
3) displayPayments
4) main

Note the main method should contain code to test the other three methods. You will be graded on how well you test your code. Using only the test code provided here is not sufficient. The main method should have the following signature:
public static void main (String args[])

These methods make computations on loans that accumulate interest every month and that have monthly payments. The first method takes three parameters: two doubles loanAmount, interestRate and an int numOfPayments. The loanAmount is the dollar value of the loan. The interestRate is the equivalent yearly rate of interest specified as a decimal (e.g. if interestRate is 0.12 and loanAmount is $1000.00 then the monthly interest on the loan is 0.12 * $1000.00 / 12 = $10.00). Lastly the numOfPayments is the number of payments to complete the loan. The other two methods also take three parameters all of which are doubles: loanAmount, interestRate and monthlyPayment. The first two parameters are the same as in the sizeOfPayments method but the last (monthlyPayment) is the amount of money paid back every month. Note, that the interest is computed and added at the end of the month, before the payment is made!

The sizeOfPayments method computes how large the monthly payment must be to repay the loan in the given number of payments and returns this number as a double.
If we assume that A=loanAmount, r = interestRate/12 and t=numOfPayments then the formula for the sizeOfPayments is:

sizeOfPayments = A * r * (r + 1)t / ((r + 1)t ? 1)


The following test code:

double payment;
payment = LoanCalculator.sizeOfPayments(5000.0, 0.05, 30);
System.out.println("The monthly payment is: " + payment);
payment = LoanCalculator.sizeOfPayments(5000.0, 0.05, 20);
System.out.println("The monthly payment is: " + payment);
payment = LoanCalculator.sizeOfPayments(5000.0, 0.10, 20);
System.out.println("The monthly payment is: " + payment);

Should produce the following output:

The monthly payment is: 177.6468218168832
The monthly payment is: 261.0814977760977
The monthly payment is: 272.4496005600592


The checkPayment method returns a boolean value (i.e., true or false) indicating if the monthly payment is more than the interest for the first month. The method does not print anything.

The following test code:

boolean isEnough;
isEnough = LoanCalculator.checkPayment(1000.0, 0.1, 1.0);
System.out.println("The payment is large enough: " + isEnough);
isEnough = LoanCalculator.checkPayment(1200.0, 0.1, 10.0);
System.out.println("The payment is large enough: " + isEnough);
isEnough = LoanCalculator.checkPayment(1200.0, 0.1, 100.0);
System.out.println("The payment is large enough: " + isEnough);

Should produce the following output:

The payment is large enough: false
The payment is large enough: false
The payment is large enough: true

The displaySchedule method displays the amount of the loan, the interest rate of the loan and for every month it displays the amount paid and the amount remaining (note the amount paid is the same for all month’s except the last month). Finally the method displays the total amount paid. All dollar values and interest rates are displayed with $ and % and only two decimal places. This should be done using the DecimalFormat class. The method does not return anything. Please note that because the DecimalFormat class is used there could be some round-off error in the below results, those are acceptable in this assignment.

The following test code:

LoanCalculator.displaySchedule(5000.0, 0.05, 500.0);


Should produce the following output:

The loan is $5000.00 at an interest rate of 5.00%

Month Payment Amount Remaining
1 $500.00 $4520.83
2 $500.00 $4039.67
3 $500.00 $3556.50
4 $500.00 $3071.32
5 $500.00 $2584.12
6 $500.00 $2094.89
7 $500.00 $1603.61
8 $500.00 $1110.30
9 $500.00 $614.92
10 $500.00 $117.48
11 $117.97 $0.00

The total amount paid was $5117.97
 
具体哪个地方不懂,可以提出来,大家一起研究
 
后退
顶部