how can i improve this program....thank you

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • monkey1001
    New Member
    • Dec 2007
    • 10

    how can i improve this program....thank you

    the program is supposed to calculate home or commercial gas usage and then print the type of customer,presen t reading,previou s reading,cubic used and cost for the month..the user inputs values btw 0-9999 and to determine number of cubic used subtract the previous from present.if present is less then previous subtract previous reading form 9999
    add the current reading to that difference ot get cubic used
    my trouble is the calculation i think if nothing else....

    import java.util.Scann er;

    public class NameGasUtilityC ompany
    {
    public static void main(String [] args)
    {
    char choice;
    int value,present,p revious,cubic;
    char home,commercial ,name,usage;
    double cost;

    Scanner keyboard= new Scanner(System. in);
    System.out.prin tln("Welcome to Name Gas");
    name=keyboard.c harAt(0);
    System.out.prin tln("What type of customer are you? 'H' or 'h'(home)|| 'C' or 'c' (commercial)");
    choice=keyboard .charAt(0);
    System.out.prin tln("Enter only cubic value in the range 0-9999");
    value=keyboard. nextInt();

    (usage = previous-present);
    if(present < previous)
    { usage = (previous - 9999)* present;
    (usage=present + usage);
    else
    usage = previous-present;
    }
    if (choice == 'H' || choice == 'h')
    {
    // use this formula constant
    {if (cubic == 70)
    cost = 5.00;
    else if (cubic <= 100)
    cost = cubic * .05;
    else if (cubic <= 400)
    cost = cubic * .025;
    else
    cost = cubic * .015;
    }

    if (choice == 'C' || choice == 'c')
    {
    //use this formula or constant
    {if (cubic == 200)
    cost = 30.00;
    else if (cubic <=500)
    cost = cubic * .04;
    else if (cubic > 700)
    cost = cubic * .03;
    }

    System.out.prin tln("Present meter reading" + present);
    System.out.prin tln("Previous meter reading" + previous);
    System.out.prin tln("Enter how many cubic used :" + usage);
    System.out.prin tln("Cost this month $: " + cost);

    }
    }
    }
    }
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    Originally posted by monkey1001
    the program is supposed to calculate home or commercial gas usage and then print the type of customer,presen t reading,previou s reading,cubic used and cost for the month..the user inputs values btw 0-9999 and to determine number of cubic used subtract the previous from present.if present is less then previous subtract previous reading form 9999
    add the current reading to that difference ot get cubic used
    my trouble is the calculation i think if nothing else....

    You forgot to post your code in code tags... ;-)

    About your trouble, it may takes time to analyze your code if you don't show us your formula...

    Please give us sample on a specific input with expected output...

    example:

    if this is my input, then this should be the output...


    Don't forget to test your code in the worst case...


    Sukatoa.

    Comment

    • monkey1001
      New Member
      • Dec 2007
      • 10

      #3
      Originally posted by monkey1001
      the program is supposed to calculate home or commercial gas usage and then print the type of customer,presen t reading,previou s reading,cubic used and cost for the month..the user inputs values btw 0-9999 and to determine number of cubic used subtract the previous from present.if present is less then previous subtract previous reading form 9999
      add the current reading to that difference ot get cubic used
      my trouble is the calculation i think if nothing else....
      the input is to determine the type of customer using the value btw 0-9999 and prompt user for the present and previous reading. the output is to print something that looks like a bill including header,customer type,presenet and previous reading,number cubic used and amount due..

      Comment

      • sukatoa
        Contributor
        • Nov 2007
        • 539

        #4
        Originally posted by monkey1001
        the input is to determine the type of customer using the value btw 0-9999 and prompt user for the present and previous reading. the output is to print something that looks like a bill including header,customer type,presenet and previous reading,number cubic used and amount due..
        at line 20, why you inclose the statement in a parenthesis?

        Please check if the braces are inclosed...

        Your keyboard object is not a String object, it is a Scanner...Pleas e read about String.

        Also your choice object... it is a character... an attempt to extract the character into a character is not-allowed...

        Trying to store integer type values in character type variable is not allowed...



        Maybe your trouble is how to fix this code.... ;-)

        If you just read the book and have an experiment of it,
        Im sure you won't ask this kind of question...

        Comment

        Working...