[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

could you please tell me what is wrong with my code???I am not able to print all the 3 values entered..pls help fast.thanks in advance

k.varunshastry

12/21/2014 2:22:00 AM

import java.io.*;
class Electricity
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int no;
void no_of_customers()throws IOException
{
System.out.println("Enter the number of customers recorded during the day :");
no=Integer.parseInt(br.readLine());
}

String name[]=new String[100];
int units[]=new int[100];
double amt[]=new double[100];
void input() throws IOException
{



System.out.println("ENTER CUSTOMER INFORMATION : ");
System.out.println();

for(int i=0;i<no;i++)
{
System.out.println("enter name of customer:");
name[i]= br.readLine();
System.out.println("enter no. of units consumed:");
units[i]=Integer.parseInt(br.readLine());

if(units[i]<=50)
amt[i]=units[i]*1.45;
if(units[i]>=50 && units[i]<=100)
{
amt[i]=50*1.45 + (units[i]-50)*2.6;
}
else if(units[i]>100 && units[i]<=200)
{
if(units[i]>100 && units[i]<=150)
{
amt[i]=50*2.6 + 50*2.6 + (units[i]-100)*3.6;
}
else if(units[i]>150 && units[i]<=200)
{
amt[i]=50*2.6 + 50*2.6 + 50*3.6 + (units[i]-150)*3.6;
}
}
else if(units[i]>200)
{
if(units[i]>200 && units[i]<=250)
{
amt[i]=50*2.6 + 50*3.25 + 50*4.88 + 50*5.63 + (units[i]-200)*6.38;
}
else if(units[i]>250 && units[i]<=300)
{
amt[i]=50*2.6 + 50*3.25 + 50*4.88 + 50*5.63 + 50*6.38 + (units[i]-250)*6.88;
}
else if(units[i]>300 && units[i]<=400)
{
amt[i]=50*2.6 + 50*3.25 + 50*4.88 + 50*5.63 + 50*6.38 + 50*6.88 + (units[i]-300)*7.38;
}
else if(units[i]>400 && units[i]<=500)
{
amt[i]=50*2.6 + 50*3.25 + 50*4.88 + 50*5.63 + 50*6.38 + 50*6.88 + 100*7.38 + (units[i]-400)*7.88;
}
else
{
amt[i]=50*2.6 + 50*3.25 + 50*4.88 + 50*5.63 + 50*6.38 + 50*6.88 + 100*7.38 + 100*7.88+(units[i]-500)*8.38;
}
}
}
}


void sortbill()
{
for(int i=0;i<name.length-1;i++)
{
for(int j=0;j<name.length-1;j++)
{
if(amt[i]>amt[i+1])
{
double temp=amt[i];
amt[i]=amt[i+1];
amt[i+1]=temp;
String n=name[i];
name[i]=name[i+1];
name[i+1]=n;

}
}
}
for(int i=0;i<=no;i++)
{System.out.println(name[i]+" "+amt[i]);}
}
public void totbill()
{
double totamt=0;
for(int i=0;i<amt.length;i++)
{
totamt=totamt+amt[i];
}

System.out.println("total amount"+totamt);
}

void customer_name() throws IOException
{
int flag=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter customer name");
String n=br.readLine();
for(int i=0;i<no;i++)
{
if(n.equalsIgnoreCase(name[i]))
{
flag=1;
System.out.println(amt[i]);
}
}
if(flag==0)
System.out.println("name not found");
}
void palindrome()
{
for(int i=0;i<no;i++)
{
String rev=new String();
int l=name[i].length();
for(int j=l-1;j>=0;j--)
{
char ch=name[i].charAt(j);
rev=rev+ch;
}
if(rev.equalsIgnoreCase(name[i]))
System.out.println(name[i]);
}
}

static void main() throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Electricity obj=new Electricity();

obj.no_of_customers();
obj.input();
int ch;
do
{
System.out.println("\n");
System.out.println("****** _ _ _ _ *******");
System.out.println("****** |\\ /| | |\\ | | | *******");
System.out.println("****** | \\ / | |_ _ _ _ | \\ | | | *******");
System.out.println("****** | \\/ | | | \\ | | | *******");
System.out.println("****** | | | | \\ | | | *******");
System.out.println("****** | | |_ _ _ _ | \\| | _ _ _ | *******");
System.out.println(" \n");

System.out.println("1.To print customer name and bill amount from higher to lower amounts ");
System.out.println("2.To calculate total amount collected from all customers ");
System.out.println("3.To accept customer name and print the bill ");
System.out.println("4.To print palindrome names ");
System.out.println("5.To exit");
System.out.println("enter choice");

int c=Integer.parseInt(br.readLine());

switch(c)
{

case 1:
obj.sortbill();
break;

case 2:
obj.totbill();
break;

case 3:
obj.customer_name();
break;

case 4:
obj.palindrome();
break;

case 5:System.exit(0);

default:
System.out.println("---Invalid entry---");
break;

}
}
while(true);
}
}

OUTPUT
enter no. of units consumed:
125
enter name of customer:
sdf
enter no. of units consumed:
651
enter name of customer:
dasa
enter no. of units consumed:
322


****** _ _ _ _ *******
****** |\ /| | |\ | | | *******
****** | \ / | |_ _ _ _ | \ | | | *******
****** | \/ | | | \ | | | *******
****** | | | | \ | | | *******
****** | | |_ _ _ _ | \| | _ _ _ | *******


1.To print customer name and bill amount from higher to lower amounts
2.To calculate total amount collected from all customers
3.To accept customer name and print the bill
4.To print palindrome names
5.To exit
enter choice
1
varun 350.0
dasa 1643.36
null 0.0
null 0.0
10 Answers

Evertjan.

12/21/2014 9:14:00 AM

0

Varun <k.varunshastry@gmail.com> wrote on 21 dec 2014 in
comp.lang.javascript:

> import java.io.*;
> class Electricity

That's an easy one: Wrong NG

Javascript is *NOT* a script version of Java.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Thomas 'PointedEars' Lahn

12/21/2014 1:22:00 PM

0

Evertjan. wrote:

> Javascript is *NOT* a script version of Java.

*There* *is* *no* *Javascript*.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.

Evertjan.

12/21/2014 6:02:00 PM

0

Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote on 21 dec 2014 in
comp.lang.javascript:

> Evertjan. wrote:
>
>> Javascript is *NOT* a script version of Java.
>
> *There* *is* *no* *Javascript*.

And also if so it cannot be a script version of Java.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Tim Streater

12/21/2014 8:05:00 PM

0

In article <1697767.ygQdfQ1551@PointedEars.de>, Thomas 'PointedEars'
Lahn <PointedEars@web.de> wrote:

>Evertjan. wrote:
>
>> Javascript is *NOT* a script version of Java.
>
>*There* *is* *no* *Javascript*.

Yes there is. There's also javascript, you may have heard of it.

--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Thomas 'PointedEars' Lahn

12/21/2014 10:16:00 PM

0

Evertjan. wrote:

> Thomas 'PointedEars' Lahn [â?¦]:
>> Evertjan. wrote:
>>> Javascript is *NOT* a script version of Java.
>> *There* *is* *no* *Javascript*.
>
> And also if so it cannot be a script version of Java.

Yes, about something that does not exist there is a countably infinite
number of true statements about what it is not, including this one (which is
similar to â??rainbow unicorns with a jewel on their horn cannot survive on
Mars�¹); excluding, of course, all statements to the effect that it would be
not something that does not exist. However, such statements do not add to
the knowledge base and are therefore best avoided.

So, to whom it may concern, for future reference:

Mozilla JavaScript and other, different implementations of ECMAScript that
bear the â??JavaScriptâ? name and are discussed here are _not_ scripted Java.
The name â??JavaScriptâ? (with capital â??Sâ?) was merely chosen by Netscape
Communications Corp. for the programming language in its Web browser because
of the intentional resemblance to Java (which was popular at the time); it
then carried on (even beyond Web browsers).

Through an agreement in December 1995 (1995-12 CE), Sun Microsystems, Inc.,
now acquired by Oracle Corp., formally acquired the rights to the
â??JavaScriptâ? trademark, while Netscape was granted a license to use it; this
was strengthened with LiveConnect introduced in Netscape Navigator 4.0, to
further the use of Java technology in Web browsers². JavaScript (1.0)
(formerly â??Mochaâ?, the codename for the script engine that lasted up to
including JavaScript 1.1; then â??LiveScriptâ?) was then introduced to the
general public with Netscape Navigator 2.0 in March 1996 (1996-03).

The name carried on (without proper licensing; CMIIW) to other, different
implementations of ECMAScript such as Google V8 JavaScript (since 2008), but
it was not before Internet Explorer 9 (2011) that Microsoftâ??s implementation
was *externally* renamed, apparently for marketing reasons only (and without
proper licensing, too; CMIIW), to â??JavaScript (for Internet Explorer)â? (the
real name of that language still is â??JScriptâ?, as can be seen in the return
value of the ScriptEngine() function available there).

See the ECMAScript (ES) (Support) Matrix (URI in signature below) for
details and references.

______
¹ I have just installed

<https://www.eclipse.org/downloads/packages/eclipse-php-developers/...

Give Eclipse JSDT (contained in the â??Eclipse for PHP Developersâ? packages)
as your JS/ES IDE a try, and please donate to the cause. Thank you in
advance. (I am a Friend of Eclipse, but not affiliated.)

² Java technology in Web browsers, as we know now, is not going to survive
for much longer because support for the Netscape Plugin API (NPAPI) is
going to be terminated everywhere soon (Chromium already did on Linux
with version 35, other platforms will follow in 2015; Firefox has reduced
support since version 30). This also affects ECMAScript/JavaScript
developers because of LiveConnect/XPConnect.

<https://en.wikipedia.org/wiki/NPAPI#Browser_s...

(Likewise, please donate to Wikipedia to keep it ad-free.
[not affiliated either])
--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.

emilbaek

12/22/2014 10:15:00 AM

0

Hi Varun

Even though this is a javascript and your code is Java, I believe I can i answer you question.

The most obvious error is that your main method should be defined as such:
public static void main(String[] args)
or
public static void main(String... args)

Good luck

Evertjan.

12/22/2014 12:21:00 PM

0

Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote on 21 dec 2014 in
comp.lang.javascript:

> Evertjan. wrote:
>
>> Thomas 'PointedEars' Lahn [? Ý]:
>>> Evertjan. wrote:
>>>> Javascript is *NOT* a script version of Java.

>>> *There* *is* *no* *Javascript*.
>>
>> And also if so it cannot be a script version of Java.
>
> Yes, about something that does not exist there is a countably infinite
> number of true statements about what it is not, including this one

However, wether your statement that Javascript does not exist is true or not
true, the OP is OT on this NG in both cases.

So I would suggest that your primary response did not add to that at all,
but just showed that you did not address the issue at hand.

And even it confuses the issue when you hold to outsiders of this NG,
that this NG is only on topic on a topic that does not exist.

The question comes to mind that there should be no reason for you to post on
comp.lang.javascript at all, given your above mental ideosyncrasy.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Evertjan.

12/22/2014 12:26:00 PM

0

emilbaek@gmail.com wrote on 22 dec 2014 in comp.lang.javascript:

> Even though this is a javascript and your code is Java, I believe I can
> i answer you question.
>
> The most obvious error is that your main method should be defined as
> such: public static void main(String[] args)
> or
> public static void main(String... args)

This may be showing off some intelligence on your part.

However you are severely OT,
which is detrimentel to the functioning of a NG.

Please use email for such responses to the OP
if you want to help him or her.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

John Harris

12/23/2014 7:08:00 PM

0

On Sun, 21 Dec 2014 23:15:33 +0100, Thomas 'PointedEars' Lahn
<PointedEars@web.de> wrote:

>Evertjan. wrote:
>
>> Thomas 'PointedEars' Lahn [?]:
>>> Evertjan. wrote:
>>>> Javascript is *NOT* a script version of Java.
>>> *There* *is* *no* *Javascript*.
>>
>> And also if so it cannot be a script version of Java.
>
>Yes, about something that does not exist there is a countably infinite
>number of true statements about what it is not, including this one (which is
>similar to ?rainbow unicorns with a jewel on their horn cannot survive on
>Mars?¹); excluding, of course, all statements to the effect that it would be
>not something that does not exist.

If Java had a scripting language it would be called JavaScript. But it
doesn't, which is what Evertan said.


>However, such statements do not add to
>the knowledge base and are therefore best avoided.
<snip>

People who say 'wrong news group' without saying why are not adding to
anyone's knowledge base. They should be severely discouraged.

John

M. Strobel

12/24/2014 1:48:00 PM

0

On 22.12.2014 13:26, Evertjan. wrote:
> emilbaek@gmail.com wrote on 22 dec 2014 in comp.lang.javascript:
>
>> Even though this is a javascript and your code is Java, I believe I can
>> i answer you question.
>>
>> The most obvious error is that your main method should be defined as
>> such: public static void main(String[] args)
>> or
>> public static void main(String... args)
>
> This may be showing off some intelligence on your part.
>
> However you are severely OT,
> which is detrimentel to the functioning of a NG.
>
> Please use email for such responses to the OP
> if you want to help him or her.
>

Thank you guys for this nice thread, I give it five Christmas fun stars.

One golden sentence (of several):

"And even it confuses the issue when you hold to outsiders of this NG,
that this NG is only on topic on a topic that does not exist." (Evertjan. 2014)

I may add:

<script language="javascript">
alert("I do not exist!");
</script>
<h1>q.e.d.<h1>

Well, pedants among themselves..
/Str.