Creating an ISP Bill for Customer Problem, What did i do wrong?

Ok so the point of this program is to create a bill for customers selecting different packages for this ISP. Now i have done all the code, made the methods and what now, but there is a problem, in my main method which tests the methods in my class, the object does not get passed through the method and my toString method does not return the output. i will post the code below, did i do anything wrong?
this is the code for the class:
public class Customer extends appProg
    //these are the base set of hours for each package
    public final double BASE_HOURS_A= 10.00;
    public final double BASE_HOURS_B= 20.00;
    public final double BASE_HOURS_C= 9999999999999999999999999999999999999999.00;
    //these are the base costs for each package
    public final double BASE_COST_A= 9.95;
    public final double BASE_COST_B= 14.95;
    public final double BASE_COST_C= 19.95;
    //these are the additional costs per hour for the packages
    public final double PER_HOUR_COST_A= 2.00;
    public final double PER_HOUR_COST_B= 1.00;
    public final double PER_HOUR_COST_C= 0.00;
    private double totalCharges;
    private char packageType;
    private double hoursUsed;
    private String customerName;
    // Below are the Constructors for this class
    // The constructors will help instantiate the object
    public Customer()
    {   totalCharges=0;
        packageType='b';
        hoursUsed=0.0;
        customerName="";
    public Customer(char packageType, double hoursUsed, String customerName)
        this.packageType=packageType;
        this.hoursUsed=hoursUsed;
        this.customerName=customerName;
    // The following are the accessor methods
    // the getPackage method returns the package type
    public char getPackage()
        return packageType;
    // the getHoursUsed() returns the hours used of the customer
    public double getHoursUsed()
        return hoursUsed;
    // the getCustomerName() returns the name of the customer
    public String getCustomerName()
        return customerName;
    //the totalCharges methods calculates the total charges
    public double totalCharges()
        if(packageType=='A' && hoursUsed>10.00)
                totalCharges=((hoursUsed-10)*PER_HOUR_COST_A)+(hoursUsed*BASE_COST_A);
        if(packageType=='A' && hoursUsed<=10.00)
            totalCharges=(hoursUsed*BASE_COST_A);
        if(packageType=='B' && hoursUsed>20.00)
                totalCharges=((hoursUsed-20)*PER_HOUR_COST_B)+(hoursUsed*BASE_COST_B);
        if(packageType=='B' && hoursUsed<=20.00)
            totalCharges=(hoursUsed*BASE_COST_B);
        if(packageType=='C')
            totalCharges=(BASE_COST_A);
        return totalCharges;
    //The following are the mutator methods
    //the setPackage method will set the package type for the customer
    public void setPackage(char packageType)
        this.packageType=packageType;
    //the setHours method will set the amount of hours used for that customer
    public void setHours(double hoursUsed)
        this.hoursUsed=hoursUsed;
    //the setCustomerName method will set the name for the customer
    public void setCustomerName(String customerName)
        this.customerName=customerName;
   //the following are input and output methods
   public String toString()
       return "You have used a total of "+hoursUsed+" hours and your total cost is "+totalCharges+"";
} // end class Customerand this is the code for the appProgram that goes with it:
public class appProg
    //************* MAIN METHOD ******************************************
    public static void main(String[] args)
          String packageT;
          char packagetype;
          double hoursUsed;
          String name;
          Scanner keyboard = new Scanner(System.in);
          System.out.println("This program was written by Ashkan Gholami for CSC15 with JONES.");
          System.out.println("");
          System.out.print("Please enter the Customers name: ");
          name=keyboard.nextLine();
          System.out.print("Please enter the package type: ");
          packageT=keyboard.nextLine();
          packagetype=packageT.charAt(0);
          System.out.print("Please enter the hours used: ");
          hoursUsed=keyboard.nextDouble();
          keyboard.nextLine();
          switch(packagetype)
             case 'A':
                System.out.println(""+name+" has chosen package A.");
                break;
             case 'B':
                System.out.println(""+name+" has chosen package B.");
                break;
             case 'C':
                System.out.println(""+name+" has chosen package C.");
                break;
             case 'a':
                System.out.println(""+name+" has chosen package A.");
                break;
             case 'b':
                System.out.println(""+name+" has chosen package B.");
                break;
             case 'c':
                System.out.println(""+name+" has chosen package C.");
                break;
             default:
                System.out.println("That is an invalid package type!");
                break;
          Customer customer1= new Customer(packagetype,hoursUsed,name);
          customer1.totalCharges();
          customer1.toString();
    }      

in my main method which tests the methods in my class,
the object does not get passed through the method That statement makes no sense. You can pass objects to methods. However, you do not pass objects "through methods". In any case, neither your totalCharges() method nor your toString() method is defined to accept any parameters--much less an object as a parameter.
and my toString method does not return the outputHow do you know that? Your toString() method is defined to return a String. Where in your program do you attempt to display the String that is returned?
did i do anything wrong?If you call a method on an object, and the method returns something, you need to assign the returned value to a variable--otherwise the returned value will disappear into the ether. Subsequently, if you want to display the returned value, you have to take steps to do that as well.
It sounds like you need to revisit a simple "Hello World" program and play around with it a little bit.

Similar Messages

  • I am at starbucks and when I try to download my free music on itunes, my password is always rejected, even when i am forced to create a new one!!!  what am I doing wrong, who do I ask for help

    I am at starbucks and when I try to download my free music on itunes, my password is always rejected, even when i am forced to create a new one!!!  what am I doing wrong, who do I ask for help?

    Due to recent security issues and identify theft (mostly due to phishing scams), the iTunes Store seems to be requiring more frequent verification of credit card information when a card is registered in your account, even if you have a balance from a prepaid card. Either just go through the verification process or, if you have a credit card entered and you don't expect to need the card anytime soon, go into the Payment information in your account and set the payment method to "none" which should then stop the regular requirements for verification  (it may still ask - mine does - but you should just be able to click through the buttons without problems).
    Hope this helps.

  • I rented a movie from itunes(The Untouchables), and it won't play. It lets me click on it but then is just black and won't play. I saw that I was billed for it. What should I do?

    I rented a movie from itunes(The Untouchables), and it won't play. It lets me click on it but then is just black and won't play. I saw that I was billed for it. What should I do?

    I'd report the problem to the iTunes Store. 
    Log in to the Store. Click on "Account" in your Quick Links. When you're in your Account information screen, go down to Purchase History and click "See all".
    Find the item that is not playing properly. If you can't see "Report a Problem" next to the item, click the "Report a problem" button. Now click the "Report a Problem" link next to the item.

  • TS1702 what do you do if you get billed for an app you did not purchase?

    I received a bill for an app I did not purchase.  How do I reconcile this issue with iTunes?

    Contact itunes support
    http://www.apple.com/support/itunes/contact/

  • HT1689 I was billed for gaming credits I did not receive.  What do I do?

    I was billed for gaming credits I did not receive.

    Try contacting iTunes support and ask them for help : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • TS3074 While trying to download Itunes on my lenovo laptop it tells me in an error box the following : " this installation package could not be opened verify that it exsist or contact the vendor for more info" what did i do?

    While trying to download Itunes on my lenovo laptop it tells me in an error box the following : " this installation package could not be opened verify that it exsist or contact the vendor for more info" what did i do?

    Perhaps the answer provided for this problem in Microsoft's forums will help.
    Good luck.

  • I just updated my iPad to OS5 and all of my apps are gone. What did I do wrong and how can I get them back? Several were paid for. Thanks

    I just updated my iPad to OS5 and all of my apps are gone. What did I do wrong and how can I get them back? Several were paid for. Thanks

    If you have failed to make sure that any apps purchased on the iphone were transferred to your computer before updating, then you will have to redownload.
    Open itunes store, click Purchased, under Quick Links.

  • TS1424 I have been billed for an item I did not want and did not intentionally purchase, How can I get this reversed.

    I have been billed for an item I did not want and did not intentionally purchase.
    How can I get this reversed?

    All purchases are considered final, but you can try contacting iTunes support and see if they will give you a refund or credit : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • I was setting up my IPod Nano 7 for the first time and I can't play the songs I bought. What did I do wrong?

    I was setting up my IPod Nano7 for the first time and purchased 3 songs.  When I went to play it on my IPod the screen said "No Music".  What did I do wrong?

    We are going through same thing and looks like alot of other people also. Seems to me Apple would have invalid email instead of us loosing the gift card all together. Very irratating. Good Luck.

  • HT3702 I was billed for an app i did not purchase

    I was billed for an application i did not purchase. I was emailed the receipt and it has been taken out of my bank account.

    Assuming this wasn't for an in-app purchase you forgot or made inadvertently, first change the password to your Apple ID in case someone else has been able to obtain access. Then go here:
    http://www.apple.com/support/itunes/contact/
    and follow the instructions to report the issue to the iTunes Store.
    Regards.

  • All my Photos disappeared after I saved a photo from an email from my wife. I am running Mountain lion on Mac book pro 2012, help. What did I do wrong?

    All my Photos disappeared after I saved a photo to Iphoto from an email from my wife. I am running Mountain lion on Mac book pro 2012, help. What did I do wrong?

    Apply the two fixes below in order as needed:
    Fix #1
    Launch iPhoto with the Command+Option keys held down and rebuild the library.
    Since only one option can be run at a time start with Option #3, followed by #4 and then #1 as needed.
    Fix #2
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    1 - download iPhoto Library Manager and launch.
    2 - click on the Add Library button, navigate to your Home/Pictures folder and select your iPhoto Library folder.
    3 - Now that the library is listed in the left hand pane of iPLM, click on your library and go to the File ➙ Rebuild Library menu option.
    4 - In the next  window name the new library and select the location you want it to be placed.
    5 - Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments.  However, books, calendars, cards and slideshows will be lost. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.
    OT

  • Music not recognized from old PC to new, what did i do wrong.

    So i just got a new PC.  I saved my entire Itunes file on an external hardrive.  The music all transfers to the new PC and i loaded it into the newest Itunes.  I authorized the new computer through Itunes and got all artwork.  Now i cannot play songs or transfer music to my i-pod.  I had to rboot the Ipod. so now i have an empty Ipod and a bunch of Music I cannot play.  I've connested my Iphone and it seems to recognize it, but I'm afraid to connest it again until i trust the itunes to work.  When I try to play a song it say cannot locate the original/
    What did i do wrong?  What can I do?  I still have the old tower available to retreive Itunes
    Thanks for any advice
    MJ

    The index page copied from the template is now reading the css.  I did nothing other than shut down DW and open it again.  Maybe it just takes a while for the process to complete.  Am now creating more pages that are also not reading css.  Will do the same and see if it all connects.

  • Nesting: What did I do wrong?

    I just put together 4 shows that were all using the same credits. i created the credits in a new timeline, dragged that sequence to the viewer and then overwrote it into the end of the other 4 sequences.
    I had to make a change to the credits, opened the master credit sequence updated and re-rendered. The updated version did not pass down to the other sequences. I had to go into each sequence, double-click on the credits in the sequence and update each one individually. In the end I had 5 credits sequences open (the original + 4), yet there's only 1 credits sequence in the bins.
    What did I do wrong, shouldn't the 4 shows update automatically when I change the master credit sequence?
    Thanks.

    I had a nesting nightmare in my project. There were nested sequences inside of other nested sequences to keep things organized. What I ended up dong was creating an entirely new final sequence. Then after all the changes were made in all the nests, I opened each nest one at a time, copied all the clips in it, pasted it into the new sequence, made a fresh nest of the clips, then did the same for the next sequence. This way nothing was more than one nest deep in the timeline, and everything was fresh. I made some changes after that and didn't have any issues.
    It worked as a fix but I will be interested in watching the thread to see if someone has the solution to this issue.

  • What did i do wrong

    I inserted a new method into the code, and it seems to work alright, but it doesn't solve the problem.
    import java.util.*;
    public class Summer
       public static void main (String[] args)
         Scanner in = new Scanner(System.in);
         int first = 0;
         int last = 0;
         int total = 0;
         int i = 0;
         System.out.println("Hello. I will calculate the sum");
         System.out.println("of consecutive integers.");
         System.out.println("Please enter the starting number:");
         first = in.nextInt();
         System.out.println("Please enter the ending number:");
         last = in.nextInt();
         while (last < first)
           System.out.println(last + " is smaller than " + first);
           System.out.println("The ending number must be bigger than the first");
           System.out.println("Enter the starting number again");
           first = in.nextInt();
           System.out.println("Enter the ending number again");
           last = in.nextInt();
           System.out.println("The sum of the numbers are " + total);
           total = sum(last, first);
                 for (i = first; i <= last; i++)
             total = total + i;     
                  public static int sum(int num1, int num2)
                       int result;
                       result = num1 + num2;
                       return result;
    }what did i do wrong?

    I'm going to try to list the things you could fix here to make this better code. It might seem like a lot and I'm not trying to be mean or rude, I'm just trying to be helpful.
    First this part of your code:
    System.out.println("Hello. I will calculate the sum");
         System.out.println("of consecutive integers.");
         System.out.println("Please enter the starting number:");
         first = in.nextInt();
         System.out.println("Please enter the ending number:");
         last = in.nextInt();
         while (last < first)
           System.out.println(last + " is smaller than " + first);
           System.out.println("The ending number must be bigger than the first");
           System.out.println("Enter the starting number again");
           first = in.nextInt();
           System.out.println("Enter the ending number again");
           last = in.nextInt();
           System.out.println("The sum of the numbers are " + total);
           total = sum(last, first);
         }This code is repetitive and can be shortened greatly. Notice that the result you are looking for is that the number "last" entered is greater than first. So why not begin the loop right away like this to reduce your code by almost half?:
    // bring this outside of the loop so that it only shows once
    System.out.println("Hello. I will calculate the sum");
    System.out.println("of consecutive integers.");
    // last and first are originally set equal to 0 so this loop will begin right away
    while (last <= first) {    
         System.out.println("Please enter the starting number:");
         first = in.nextInt();
         System.out.println("Please enter the ending number:");
         last = in.nextInt();
        // add an if statement to print the please re-enter message
       if (last <= first) {
           System.out.println(last + " not larger than " + first);
           System.out.println("The ending number must be bigger than the first");
    }Second,
    The total part should not be in the loop. Notice how in your original code, the total was inside the loop so even if incorrect numbers were entered, the total would be displayed. The user would then be asked to enter new numbers and the total would be displayed again. I am assuming that the wanted behavior is to only display the total when correct numbers are entered. So we need to take the total out of the loop.
    Third,
    in your orignal code:
    System.out.println("The sum of the numbers are " + total);
           total = sum(last, first);Here you are printing the value total before the total is calculated. That means that the value shown in the print will be incorrect. You must calculate the value of total before printing it.
    I think this will get to the point where the code is almost what you are looking for.
    Right now, your sum method simply adds the two numbers together, which could be done with a simple + sign, rather than writing a new method.
    The for loop which I can see in your code looks like it will perform the action you are looking for.
    What you need to do is move this for loop to the line just above the line where you are printing the total.
    This means that the for loop will calculate the total, and then print it. If you print the total before calculating it you won't see the right value.
    I hope this was clear and that it helped,
    let me know if you have more questions and I will try to be more clear.

  • I had to change my windows identification code and now, I cant access to my IPad anymore even if I have synchronized my IPad with my computer. What did I do wrong ?

    Cannot access to my Ipad anymore since I had to change my Windows identification code on my computor. What did I do wrong ?

    I'm having a similar problem on an iPhone 4.  I receive Hotmail messages, but cannot send them successfully.  I get an error message stating: "Cannot Send Mail. The user name or password for "SMTP:[email address]@smtp.live.com" is incorrect."
    If the user name or password is incorrect, how can I still receive emails?  That makes no sense.
    I've updated my new Hotmail password under Email Settings, and even deleted the account and started over.  That was no help.

Maybe you are looking for