Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #26367 > unrolled thread

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

Started byVarun <k.varunshastry@gmail.com>
First post2014-12-20 18:22 -0800
Last post2014-12-24 14:48 +0100
Articles 11 — 7 participants

Back to article view | Back to comp.lang.javascript


Contents

  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 Varun <k.varunshastry@gmail.com> - 2014-12-20 18:22 -0800
    Re: 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 "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-12-21 10:14 +0100
      Re: 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 Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-21 14:21 +0100
        Re: 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 "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-12-21 19:02 +0100
          JavaScript (was: 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) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-21 23:15 +0100
            Re: JavaScript (was: 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) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-12-22 13:21 +0100
            Re: JavaScript (was: 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) John Harris <niam@jghnorth.org.uk.invalid> - 2014-12-23 19:08 +0000
        Re: 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 Tim Streater <timstreater@greenbee.net> - 2014-12-21 20:05 +0000
    Re: 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 emilbaek@gmail.com - 2014-12-22 02:14 -0800
      Re: 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 "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-12-22 13:26 +0100
        Re: 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 "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-12-24 14:48 +0100

#26367 — 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

FromVarun <k.varunshastry@gmail.com>
Date2014-12-20 18:22 -0800
Subjectcould 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
Message-ID<225e6bec-9335-469c-840c-6e314703b64e@googlegroups.com>
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

[toc] | [next] | [standalone]


#26368

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-12-21 10:14 +0100
Message-ID<XnsA40A681DDE4B1eejj99@194.109.133.133>
In reply to#26367
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)

[toc] | [prev] | [next] | [standalone]


#26369

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-12-21 14:21 +0100
Message-ID<1697767.ygQdfQ1551@PointedEars.de>
In reply to#26368
Evertjan. wrote:

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

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

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

[toc] | [prev] | [next] | [standalone]


#26370

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-12-21 19:02 +0100
Message-ID<XnsA40AC19E83F98eejj99@194.109.133.133>
In reply to#26369
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)

[toc] | [prev] | [next] | [standalone]


#26372 — JavaScript (was: 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)

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-12-21 23:15 +0100
SubjectJavaScript (was: 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)
Message-ID<2459574.qumALSk5U6@PointedEars.de>
In reply to#26370
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/marsm4>

  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_support>

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

[toc] | [prev] | [next] | [standalone]


#26374 — Re: JavaScript (was: 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)

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-12-22 13:21 +0100
SubjectRe: JavaScript (was: 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)
Message-ID<XnsA40B87D8D4F1Feejj99@194.109.133.133>
In reply to#26372
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)

[toc] | [prev] | [next] | [standalone]


#26377 — Re: JavaScript (was: 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)

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2014-12-23 19:08 +0000
SubjectRe: JavaScript (was: 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)
Message-ID<q9fj9al6th5tbvq2olf3ghh2ak8ckj8jdd@4ax.com>
In reply to#26372
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

[toc] | [prev] | [next] | [standalone]


#26371

FromTim Streater <timstreater@greenbee.net>
Date2014-12-21 20:05 +0000
Message-ID<211220142005251013%timstreater@greenbee.net>
In reply to#26369
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

[toc] | [prev] | [next] | [standalone]


#26373

Fromemilbaek@gmail.com
Date2014-12-22 02:14 -0800
Message-ID<44168e00-7159-44a9-a024-bb1418569066@googlegroups.com>
In reply to#26367
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

[toc] | [prev] | [next] | [standalone]


#26375

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-12-22 13:26 +0100
Message-ID<XnsA40B88ACDE96Aeejj99@194.109.133.133>
In reply to#26373
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)

[toc] | [prev] | [next] | [standalone]


#26379

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2014-12-24 14:48 +0100
Message-ID<cfvuhbFsu5rU1@mid.uni-berlin.de>
In reply to#26375
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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web