473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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,present reading,previous 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.Scanner;

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

Scanner keyboard= new Scanner(System.in);
System.out.println("Welcome to Name Gas");
name=keyboard.charAt(0);
System.out.println("What type of customer are you? 'H' or 'h'(home)|| 'C' or 'c' (commercial)");
choice=keyboard.charAt(0);
System.out.println("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.println("Present meter reading" + present);
System.out.println("Previous meter reading" + previous);
System.out.println("Enter how many cubic used :" + usage);
System.out.println("Cost this month $: " + cost);

}
}
}
}
Mar 5 '08 #1
3 1478
sukatoa
539 512MB
the program is supposed to calculate home or commercial gas usage and then print the type of customer,present reading,previous 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.
Mar 5 '08 #2
the program is supposed to calculate home or commercial gas usage and then print the type of customer,present reading,previous 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..
Mar 5 '08 #3
sukatoa
539 512MB
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...Please 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...
Mar 5 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Peng Jian | last post by:
I have a function that is called very very often. Can I improve its efficiency by declaring its local variables to be static?
2
by: hb | last post by:
Hi, I have a asp.net web application written in C#. The application is backed by a SQL Server 2000 database. At current time, it's very slow. I guess there are problems on asp.net coding,...
4
by: ladislav | last post by:
I made this program test prime. I want it improve I have idea but I don’t now how it insert in into program. Howe somebody else idea? My idea: if(prime==true) i*i==false;...
9
by: goosen_cug | last post by:
This program is a "Sequential List" class I want to do the Union Operation,Intersection Operation of the Set.But this program have a problem: /////////////////////////// Compiling... Set.cpp...
11
by: Peted | last post by:
Im using c# 2005 express edition Ive pretty much finished an winforms application and i need to significantly improve the visual appeal of the interface. Im totaly stuck on this and cant seem...
8
by: tony | last post by:
Hi, now I've known the basics about C++. What I can do is pretty limited. I've known something in Java: 1.Networking(Socket, RMI, Servlet) 2.Database(JDBC) 3.GUI (Java Swing) 4.and some others...
0
by: nondos | last post by:
Hello, I'm currently design my project menus most of it, is a labels and picturebox which moves and change color, i've notice the preformance is not very well i've would like to know if there's...
5
by: Gilles Ganault | last post by:
Hello I'm no PHP expert, and I'm reading "Building scalable web sites". In the tips section, the author mentions using templates to speed things up. I was wondering how the template engines...
4
by: Russell Mangel | last post by:
Hi, The code I have posted searches for a pattern of bytes starting from the end of Byte array *backwords*, if a match is found, return the starting index of those found bytes. Since one of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.