I'm having some trouble getting this program to work, my assignment deals with inheritance, and I'm basically trying to call my methods in main in order to run them.... so here's what I've gotten so far.
import javax.swing.*; public class Order { private static String customer, numb, quant, unitPrice; private static int custNumber; private static double orderQuant, unitCost; public static double total; public static void setCustomer() { customer = JOptionPane.showInputDialog(null,"Enter customer name:"); } public static String getCustomer() { return customer; } public static void setCustNumber() { numb = JOptionPane.showInputDialog(null, "Enter costumer number:"); custNumber = Integer.parseInt(numb); } public static int getCustNumber() { return custNumber; } public static void setOrderQuant() { quant = JOptionPane.showInputDialog(null, "Enter quantity ordered:"); orderQuant = Double.parseDouble(quant); } public static double getOrderQuant() { return orderQuant; } public static void setUnitCost() { unitPrice = JOptionPane.showInputDialog(null, "Enter quantity ordered:"); unitCost = Double.parseDouble(unitPrice); } public static double getUnitCost() { return unitCost; } public static void computePrice() { total = (orderQuant * unitCost); } public static void display() { JOptionPane.showMessageDialog(null, "Customer Number: " + custNumber + "\nCustomer Name: " + customer + "\nQuantity Ordered: " + Math.round(orderQuant) + "\n Price Each: $" + unitCost + "\nThe cost of your order is: $" + total); } }public class ShippedOrder extends Order { private final double shipHandle = 4.00; public void computePrice() { super.total = ((getOrderQuant() * getUnitCost()) + shipHandle); } public double getTotal() { return total; } }import javax.swing.*; public class UseOrder { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "First, enter data for a pick up order."); Order.setCustNumber(); Order.setCustomer(); Order.setOrderQuant(); Order.setUnitCost(); Order.computePrice(); Order.display(); JOptionPane.showMessageDialog(null, "Now, enter data for a shipped order."); Order.setCustNumber(); Order.setCustomer(); Order.setOrderQuant(); Order.setUnitCost(); ShippedOrder.computePrice(); Order.display(); } }
basically the problem is with the computePrice() methods in both the Order, and ShippedOrder classes. computePrice() method in Order, is supposed to be overridden by the computePrice() in ShippedOrder, basically adding $4.00 to the total. However if I make the computePrice() method in Order non-static, the UseOrder class can't use it but ShippedOrder class can, and if I make it static UseOrder class can use it, but ShippedOrder can't.
Quite a conundrum for me. I did read something about creating a new instance of the method perhaps? But dealing with inheritance I'm not quite sure how to go about doing such a thing. Thank you in advance for your help.