problem with two extends of Inheritance
Hi guys,
I am currently doing a problem that is as follows ( I have not yet put in the Main method):
Define a class named Payment that contains a member variable of type double that stores the amount of the payment and appropriate accessor and mutator methods. Also create a method named paymentDetails that outputs an English sentence that describes the amount of the payment.
Next define a class named CashPayment that is derived from Payment. This class should redefine the paymentDetails method to indicate that the payment is in cash. Include appropriate constructor(s).
Define a class named CreditCardPayment that is derived from Payment. This class should contain member variables for the name on the card, expiration date, and credit card number. Include appropriate constructor(s). Finally, redefine the paymentDetails method to include all credit card information in the printout.
Create a main method that creates at least two CashPayment and two CreditCardPayment objects with different values and calls paymentDetails for each.
My code so far is as follows:
Code:
import java.util.Scanner;
public class Payment71
{
//Payment amount
private double amount;
//Constructor to initialize amount to 0
public Payment()
{
amount = 0.0;
}
//Constructor to initialize payment amount
public Payment(double paymentAmount)
{
amount = paymentAmount;
}
//Sets the payment amount
public void setPayment(double paymentAmount)
{
amount = paymentAmount;
}
//Returns the payment amount
public double getPayment()
{
return amount;
}
//Prints a description of the payment
public void paymentDetails()
{
System.out.println("The payment amount is " + amount);
}
}
public class CashPayment extends Payment71
{
Scanner keyboard = new Scanner(System.in);
char answer = null;
char answer1 = 'Y';
char answer2 = 'N';
public Payment()
{
System.out.println("If payment is in cash, please enter Y.");
System.out.ptinln("If payment is not in cash, please enter N.");
answer = keyboard.nextChar();
if (answer.equalsIgnoreCase(answer1))
{
System.out.println("Please enter amount of cash payment.");
amount = keyboard.nextDouble();
}
else if (answer.equalsIgnoreCase(answer2))
{
System.out.println("Payment is not in cash.");
}
}
public void paymentDetails()
{
System.out.println("The payment amount is " + amount + " and is cash");
}
}
public class CreditCardPayment extends Payment71
{
Scanner keyboard = new Scanner(system.in);
String CCname;
double CCexperation;
int CCnumber;
public String getCCname()
{
System.out.println("Enter credit card name.");
CCname = keyboard.nextLine();
}
public double getCCexperation()
{
System.out.println("Enter credit card experation date.");
CCexperation = keyboard.nextLine();
}
public int getCCnubmer()
{
System.out.println("Enter credit card number.");
CCnumber = keyboard.nextInt();
}
public void paymentDetails()
{
System.out.println("The payment amount is " + amount + " and is cash");
}
public double getAmount(double amount)
{
System.out.println("Please enter amount payment.");
amount = keyboard.nextDouble();
}
public void paymentDetails()
{
System.out.println("The payment amount is " + amount + " and is credit.");
System.out.println("The credit card holders name is " + CCname + ". ");
System.out.println("The date of experation on the card is " + CCexperation + ". ");
System.out.println("The credit card number is " + CCnumber + ". ");
}
}
I get three error messages right now, which say "Payment7_1.java:34: invalid method declaration; return type required" at lines 34, 40, and 72. Does anyone know why?
And secondly, how would the problem know if I payed in cash or credit? Do I need to implement some IF loops, or will the program go through all classes?
Thanks for any help, and you can be sure once fix these two questions there will be more. :)