Sorry, this is the first class.
import java.util.Scanner;
public class ISPMain
{
public ISPMain()
{
// initialise instance variables
}
/**
*
*/
public static void main( String [] args)
{
System.out.println("Package A: For $9.95 per month, 10 hours of access are provided. \nAdditional hours are $2.00 per hour.");
System.out.println("Package B: For $14.95 per month, 20 hours of access are provided. \nAdditional hours are $1.00 per hour.");
System.out.println("Package C: For $19.95 per month, unlimited access is provided.\n");
System.out.println("Which package would you like?");
Scanner kb = new Scanner(System.in);
String pkg = kb.nextLine();
char A = pkg.charAt(0);
double hoursUsed = 0;
if (A == 'A' || A == 'B')
{
System.out.println("Number of hours of accessed used?");
hoursUsed = kb.nextDouble();
}
ISP obj = new ISP(A, hoursUsed);
}
}
Here's the other class with that keeps getting the error.
public class ISP
{
with your own
private char pkg;
private double hoursUsed;
/**
* Constructor for objects of class ISP
*/
public ISP(char pkg, double hoursUsed)
{
this.pkg = pkg;
this.hoursUsed = hoursUsed;
calculateCharges();
printSavings();
}
public char getPkg()
{
return pkg;
}
public double getHoursUsed()
{
return hoursUsed;
}
public void setPkg(char pkg)
{
this.pkg = pkg;
}
public void setHoursUsed(double hoursUsed)
{
this.hoursUsed = hoursUsed;
}
public ISP()
{
setHoursUsed(0.0);
setPkg('A');
}
public double calculateCharges()
{
double totalCharges = 0;
if (pkg == 'A')
{
double perMonth = 9.95;
double additionalPerHour = 2.00;
int providedHours = 10;
if (hoursUsed <= 10)
{
totalCharges = perMonth;
}
else if (hoursUsed > 10)
{
totalCharges = perMonth + (hoursUsed - 10) * additionalPerHour;
}
}
else if (pkg == 'B')
{
double perMonth = 14.95;
double additionalPerHour = 1.00;
int providedHours = 20;
if (hoursUsed <= 20)
{
totalCharges = perMonth;
}
else if (hoursUsed > 20)
{
totalCharges = perMonth + (hoursUsed - 20) * additionalPerHour;
}
}
else if (pkg == 'C')
{
double perMonth = 19.95;
totalCharges = perMonth;
}
System.out.println(totalCharges);
return totalCharges;
}
public double printSavings()
{
double ABSavings = 0;
if (pkg == 'A')
{
ISP packageA = new ISP('A',hoursUsed);
ISP packageB = new ISP('B',hoursUsed);
double pkgASave = packageA.calculateCharges();
double pkgBSave = packageB.calculateCharges();
if (pkgBSave < pkgASave )
{
ABSavings = (pkgASave - pkgBSave);
System.out.println("You would have saved " + ABSavings + "by choosing package B" );
}
}
return ABSavings;
}
}