• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't run the code in command line

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
So I've recently started using Java for a school project. One part of this project is a calculator to calculate the average of a certain amout of marks. I've obviously gotten a few errors the first few times when I tried to run the program, however, after I fixed the errors, the comand prompt just didn't run the code and reset to the standart directory view (C:\Users\MyUsername\Desktop>). There are no errors displayed but since the code should have an output it didn't work. I would appreciate it, if anyone could help me either fix this or recommend another program (expect comand prompt) which helps me see whether the code is working or not.
Thanks a lot.
-Me
Calc.PNG
[Thumbnail for Calc.PNG]
The code
 
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A warm welcome to the Ranch

When posting code, is always better/preferred to post an actual code rather than its picture. So please do.

Could you please tell us:
1. What inputs you have passed
2. What was the expected output
3. What was an actual output
 
Liutauras Vilda
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a suggestion how better is to structure you program.

Try to obtain inputs and add them to some kind of data structure. For instance: an array or list. Once you have it, you can create a method which calculates average.

Example snippet:

Also try to do similarly with taking input(s) from user. For which you could have something along the lines:
 
Istvan Müller
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:A warm welcome to the Ranch

When posting code, is always better/preferred to post an actual code rather than its picture. So please do.

Could you please tell us:
1. What inputs you have passed
2. What was the expected output
3. What was an actual output



Thanks for your answer
I'm sorry, I was told not to post java code, so here it is in my reply.
As mentioned, I was not able to make any inputs, I attached another screenshot showing, what my comand prompt displays (my Username is censored bc it's cringe ). The first expected output should ask me to type in the amount of exams I've had so far.
Thanks for your Help
-Istvan
Screenshot.PNG
[Thumbnail for Screenshot.PNG]
comand prompt
 
Liutauras Vilda
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please check line 16 carefully (up until '{').
 
Istvan Müller
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't get it :3
 
Liutauras Vilda
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Loop has no body due to semi-colon which finishes statement.
 
Istvan Müller
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah I see, thanks for that. The comand prompt displays still the same tho .-.
 
Liutauras Vilda
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So if you'd go back to my first post and answer questions, you might would figure out what the problem is (if there is any) after you removed uneccessary semi-colon.
 
Istvan Müller
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right

1. the only input I could pass to the comand prompt was "javac Calc.java"
2. the expected output was the sentence: "Please enter the amount of exams you've had so far: ". Since that's where I should get the value for the variable "counter".
3. I got no output out of the comand prompt, It just reset to the basic display, that I showed in the threat before with my screenshot.

I hope that's what you were asking for.
 
Liutauras Vilda
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, yes and no

With 'javac Calc.java' you compile the program. What else you need to do, is to execute it with an instruction 'java Calc' so then you can interact with the program in the way you programmed it. Meaning you'd need to enter the amount of exams and then their corresponding grades received which would be used for the average calculation.
 
Istvan Müller
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Damn, I see. we've been handling the wrong issue the whole time
I didn't run the program properly. What exactly do I have to type in the comand prompt to interact with the program? o.0 (sorry, it really is my first java code xD)
 
Liutauras Vilda
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Istvan Müller wrote:What exactly do I have to type in


At this point I think is fair enough to say that you are expected to research yourself and try to figure out. You could find lots of information on Internet already which answers that type of question.

It is a bit weird that you have programming class and those type of things are covered in it.
 
Istvan Müller
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:

Istvan Müller wrote:What exactly do I have to type in


At this point I think is fair enough to say that you are expected to research yourself and try to figure out. You could find lots of information on Internet already which answers that type of question.

It is a bit weird that you have programming class and those type of things are covered in it.


Thanks for your advice . I don't have programing classes in school to be fair, it's more like a free project where you can decide on your own, what you want to do. However thanks for you help again. <3
 
Liutauras Vilda
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I, earlier wrote:you have programming class and those type of things are covered in it.


I meant aren't, not are.

Alright, I see. Then Oracle Java Tutorials might be the good resource for you to read and find some answers. Have a look here. So you could find some more structured and interim information about Java programming language. How to compile, how to execute, what is the class, etc...
 
Istvan Müller
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, thanks for your help, again . I really appreciate your helpful and quick replies. I think this threat is finished and I will certainly try the tutorial you recommended.
 
Liutauras Vilda
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No worries, you are welcome. Once you do some research, I'm sure you'll have some more concrete questions about the problem at hand how to approach it, and this is what we are mainly interested about instead of dry Q and A sessions.
 
reply
    Bookmark Topic Watch Topic
  • New Topic