Question: Please fix my code, I have 3 programs to refactor and I mess them up very bad, if you can, please write a test class

Please fix my code, I have 3 programs to refactor and I mess them up very bad, if you can, please write a test class for these programs thank you very much.

Childrensprice[charge()] Regularprice[getCharge()] NewReleasePrice [getCharge(), getFrequentRenter, Point()

Price [getCharge(), getFrequentRenter, Point()]

Movie [title: String, getCharge(), getFrequentRenterPoint()]

Rental [daysRented:int, getCharge(), getFrequentRenterPoints()]

Customer [ name:String, statement(), htmlStatement(), getTotalCharge(), getTotalFrequentRenterPoint()]

***************************************************

import java.util.* ;

class Customer {

private String _name;

private Vector _rentals = new Vector();

public Customer(String name) {

_name = name;

}

public void addRental(Rental arg) {

_rentals.addElement(arg);

}

public String getName() {

return _name;

}

public String statement() {

Enumeration rentals = _rentals.elements();

String result = "Rental Record for " + getName() + " ";

while (rentals.hasMoreElements()) {

Rental each = (Rental) rentals.nextElement();

//show figures for this rental

result += "\t" + each.getMovie().getTitle()+ "\t" +

String.valueOf(each._movie.getCharge(each)) + " ";

}

//add footer lines

result += "Amount owed is " + String.valueOf(getTotalCharge()) + " ";

result += "You earned " + String.valueOf(getTotalFrequentRenterPoints()) +

" frequent renter points";

return result;

}

public String htmlStatement() {

Enumeration rentals = _rentals.elements();

String result = "

Rentals for " + getName() + "

";

while (rentals.hasMoreElements()) {

Rental each = (Rental) rentals.nextElement();

//show figures for each rental

result += each.getMovie().getTitle()+ ": " + String.valueOf(each._movie.getCharge(each)) + "
";

} //add footer lines

result += "

You owe " + String.valueOf(getTotalCharge()) + "

";

result += "On this rental you earned " +

String.valueOf(getTotalFrequentRenterPoints()) +

" frequent renter points

";

return result;

}

private double getTotalFrequentRenterPoints(){

double result = 0;

Enumeration rentals = _rentals.elements();

while (rentals.hasMoreElements()){

Rental each = (Rental) rentals.nextElement();

result += each._movie.getCharge(each);

}

return result;

}

private double getTotalCharge(){

double result = 0;

Enumeration rentals = _rentals.elements();

while (rentals.hasMoreElements()){

Rental each = (Rental) rentals.nextElement();

result += each._movie.getCharge(each);

}

return result;

}

private int frequentRenterPoints(int frequentRenterPoints, Rental each) {

// add frequent renter points

frequentRenterPoints ++;

// add bonus for a two day new release rental

if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) &&

each.getDaysRented() > 1) frequentRenterPoints ++;

return frequentRenterPoints;

}

}

**********************************************

import java.util.* ;

public class Movie {

public static final int CHILDRENS = 2;

public static final int REGULAR = 0;

public static final int NEW_RELEASE = 1;

private String _title;

private Price _price;

public Movie(String title, int priceCode) {

_title = title;

setPriceCode(priceCode);

}

abstract class Price {

abstract int getPriceCode()

{

class ChildrensPrice extends Price {

int getPriceCode() {

Return Movie.CHILDREN; }

}

class NewReleasePrice extends Price {

int getPriceCode() {

Return Movie.NEW_RELEASE;

}

}

class RegularPrice extends Price {

int getPriceCode() {

Return Movie.REGULAR;

}

}

}

}

public int getPriceCode() {

return _price.getPriceCode();

}

public void setPriceCode (int arg) {

switch(arg)

{

case Movie.REGULAR:

_price = new RegularPrice();

break;

case Movie.CHILDREN:

_price = new ChildrensPrice();

break;

case Movie.NEW_RELEASE:

_price = new NewReleasePrice();

break;

default:

throw new IllegalArgumentException(Incorrect Price Code);

}

}

public String getTitle() {

return _title;

}

double getCharge(int daysRented) {

double result = 0;

switch (getPriceCode()) {

case Movie.REGULAR:

result += 2;

if (daysRented > 2)

result += (daysRented - 2) * 1.5;

break;

case Movie.NEW_RELEASE:

result += daysRented * 3;

break;

case Movie.CHILDRENS:

result += 1.5;

if (daysRented > 3)

result += (daysRented - 3) * 1.5;

break;

}

return result;

}

int getFrequentRenterPoints(int daysRented){

if ((priceCode() == Movie.NEW_RELEASE) && daysRented > 1)

return 2;

else

return 1;

}

}

*******************************************

import java.util.* ;

public class Rental {

Movie _movie;

private int _daysRented;

public Rental(Movie movie, int daysRented) {

_movie = movie;

_daysRented = daysRented;

}

public int getDaysRented() {

return _daysRented;

}

public Movie getMovie() {

return _movie;

}

public double getCharge(){

return _movie.getCharge(_daysRented);

}

int getFrequentRenterPoints(){

return _movie.getFrequentRenterPoints(_daysRented);

}

}

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!