Hello all this is my first time here. So I'm doing this program for school and we are supposed to follow the below UML. The program below works the way it is however it uses the int pkg instead of the char that it is supposed to. So the user has to type 1 2 or 3 instead of the A B or C like they should. So if anyone knows how to fix this or has any suggestions they would be much appreciated.
Also if I did anything wrong with my first post I apologize in advance.
InternetCharges
- pkg: char
- hours: double
+ InternetCharges(p: char, h: double)
+setPkg(p:char):void
+setHours(h: double): void
+getPkg():char
+getHours():double
+getCharges():double
public class InternetCharges { private int pkg; private double hours; public InternetCharges(int p, double h) { pkg = p; hours = h; } public void setPkg(char p) { pkg = p; } public void setHours(double h) { hours = h; } public int getPkg() { return pkg; } public double getHours() { return hours; } public double getCharges() { double charges = 0; if (pkg == 1) charges = 9.95; else if (pkg == 2) charges = 14.95; else if (pkg == 3) charges = 19.95; else if (pkg == 3) charges = (hours * 0); if (pkg == 3) charges = charges + (hours * 0); else if ((hours > 10) && (pkg == 1)) charges = charges + ((hours - 10) * 2); else if ((hours > 20) && (pkg == 2)) charges = charges + (hours - 20); return charges; } }
import java.util.Scanner; public class InternetChargesDemo { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int pkg; double hours; System.out.println("What package have you purchased? A=1 B=2 and C=3"); pkg = keyboard.nextInt(); System.out.println("How many hours have you used? "); hours = keyboard.nextDouble(); InternetCharges IC = new InternetCharges(pkg, hours); System.out.printf("Your total charges for this month are: $%,.2f\n" , IC.getCharges()); } }