Question: Currently working on an CS project to make a simple Credit Card payment schedule program involving a jsp, servlet, and java class. I have written

Currently working on an CS project to make a simple Credit Card payment schedule program involving a jsp, servlet, and java class. I have written out some starter code for the 3 classes, but it is not complete because it doesn't run or get/use user input, and I don't know how to fix it. A user should be able to enter their name, account number, and balance; then the program should output a table looks like this producing output until balance is zero.

Currently working on an CS project to make a simple Credit Card

MY CODE FOR index.jsp:

pageEncoding="ISO-8859-1"%>

CreditCard cc = new CreditCard(); //Unsure if necessary

%>

Credit Card Payment Schedule

Credit Card Payment Schedule

Enter first and last name

Enter your first and last name:

Enter your account number:

Enter balance:

__________________________________________________________________

My code for the servlet:

package ccPaymentSchedule;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.*;

import javax.servlet.http.*;

/**

* Servlet implementation class CardServlet

*/

@WebServlet("/CardServlet")

public class CardServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

/**

* @see HttpServlet#HttpServlet()

*/

public CardServlet() {

super();

// TODO Auto-generated constructor stub

}

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

response.getWriter().append("Served at: ").append(request.getContextPath());

}

/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

doGet(request, response);

}

}

__________________________________________________________________________________

My code for credit card class:

package ccPaymentSchedule;

import java.text.NumberFormat;

public class CreditCard {

private String firstName = "Joe";

private String lastName = "Smith";

private int accountNum = 5;

private double curBal = 100;

private double percentToPay = 10;

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public int getAccountNum() {

return accountNum;

}

public void setAccountNum(int accountNum) {

this.accountNum = accountNum;

}

public double getCurBal() {

return curBal;

}

public void setCurBal(double curBal) {

this.curBal = curBal;

}

public double getPercentToPay() {

return percentToPay;

}

public void setPercentToPay(double percentToPay) {

this.percentToPay = percentToPay;

}

public String printSchedule() {

String masterString = "";

//

double curBal = getCurBal();

int month = 1;

double interest;

double payment;

double initial_monthly_payment = (getPercentToPay() * curBal) / 100;

System.out.printf(" %5s %10s %10s %10s", "Month", "Interest", "Payment", "Balance");

while (curBal > 0.00) {

interest = (1.5 * curBal) / 100;

if (curBal

payment = curBal + interest;

curBal = 0;

} else {

payment = ((curBal + interest) * getPercentToPay()) / 100;

curBal = curBal + interest - payment;

}

System.out.printf(" %5s %10s %10s %10s", NumberFormat.getInstance().format(month),

NumberFormat.getCurrencyInstance().format(interest)

, NumberFormat.getCurrencyInstance().format(payment),

NumberFormat.getCurrencyInstance().format(curBal));

month++;

}

return masterString;

}

}

Sample Output: Credit Payment Schedule Customer: Victor Allan Account #: 2222 Balance Due: $500.00 Month Interest Payment Balance 1 $7.50 $50.75 $456.75 2 $6.85 $46.36 $417.24 3 $6.26 $42.35 $381.15 4 $5.72 $38.69 $348.18 5$5.22 $35.34 $318.06 6 $4.77 $32.28 $290.55 7 $%4.36 $29.49 $265.42 8$3.98 $26.94 $242.46 9$3.64 $24.61 $221.49 10 $3.32 $22.48 $202.33 11 $3.03 $20.54 $184.83 12 $2.77 $18.76 $168.84 13 $2.53 $17.14 $154.23 Sample Output: Credit Payment Schedule Customer: Victor Allan Account #: 2222 Balance Due: $500.00 Month Interest Payment Balance 1 $7.50 $50.75 $456.75 2 $6.85 $46.36 $417.24 3 $6.26 $42.35 $381.15 4 $5.72 $38.69 $348.18 5$5.22 $35.34 $318.06 6 $4.77 $32.28 $290.55 7 $%4.36 $29.49 $265.42 8$3.98 $26.94 $242.46 9$3.64 $24.61 $221.49 10 $3.32 $22.48 $202.33 11 $3.03 $20.54 $184.83 12 $2.77 $18.76 $168.84 13 $2.53 $17.14 $154.23

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!