Page 1 of 2 12 LastLast
Results 1 to 20 of 33
  1. #1
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default Char's questions

    newest questions in last post!!!!!!!!!!!
    Last edited by Char; 08-13-2010 at 01:56 PM.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    In the directory where you downloaded the JDK you should find a src.zip file which you can unzip.

  3. #3
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    okay heres another one..im trying to do somekind of error handling system for my little program
    well its for my school.

    and i want to run a program with arguments like this:

    Java Code:
    java program -s 13
    i want it to print out error message when i do not have 2 arguments given.
    and also if the first argument isnt -s ... for example it is -t
    and then stop program from workin..

    i know i have to stop program with System class..i tried something this:

    Java Code:
    System.err.println("First argument is wrong.");
    but it does not work correctly..or atleast i do not apply it corrently

    need any help i can get.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    The normal technique is to do something like:

    Java Code:
    if (number of args isn't 2, or the first arg isn't "-s") {
        print out a description of useage.
        exit program
    }
    main program bits go here...
    Now, the description of useage format can be found all over the place. You'll see it if you just do "java" from the command line. That's all there is to it, really.

  5. #5
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    yeah tahts pretty much what im doin..i was just askin syntax..
    but i think i got it workin now..maybe needs some optimization though

    thanks for your help :)
    Java Code:
    	
    
    class kaks_argumenti {
    	public static void main(String[] args){
    		if (args.length==2){
    			double a = Double.parseDouble(args[1]);
    			if (args[0].equals("-r")){
    				System.out.println(Math.acos(a)+" radiaani.");
    			}else if(args[0].equals("-d")){
    				System.out.println((int)(Math.toDegrees(Math.acos(a)))+" kraadi.");
    			}else{
    					System.out.println("Etteantud lipud on tundmatud.");
    					System.exit(0);
    			}
    		}else{
    			System.out.println("Argumentide arv on vale.");
    			System.exit(0);
    		}
    	}
    }
    Last edited by Char; 12-06-2009 at 06:50 PM.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    You also want to deal with the situation where they put more or less than 2 arguments to the program...and else, in other words.

  7. #7
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    You also want to deal with the situation where they put more or less than 2 arguments to the program...and else, in other words.

    yea im dealing with it..im saying "Wrong number of arguments"..and exit

    thats all i need :)

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Whoops...missed that!
    :)

  9. #9
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    anyways im reallly really new to java, and doin everything in one class i think can't be too hard, but object oriented is crazy at the moment for me
    i was programming all the basic stuff in python before..but i only did some methods and for,if statements..nothing hard

    so can you guys give me a task with multible classes what is good for beginner, and i mean..like really beginner

  10. #10
    anthrax is offline Member
    Join Date
    Feb 2009
    Posts
    57
    Rep Power
    0

    Default

    you can type into search engines like "java tutorials"
    Last edited by anthrax; 12-20-2009 at 04:45 PM. Reason: x

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    By your statements above and elsewhere in the forum, you don't seem new to programming, just Java. Why not take a favorite program of yours written in whatever language you know, and re-write it from the ground up in Java. For e.g., any programmer worth their salt has attempted one of these: zooming the Mandelbrot set, displaying the game of life or creating a Sudoku solver.

    Have fun!

  12. #12
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    i think this question was already here, but..how i format double

    in python it was float
    XML Code:
    print("Circles area is: %0.2f"%(area))
    how is it here?
    Java Code:
    System.out.printf("Circles area is: %0.2d",circle.area(4));
    tried something this..but not workin
    also i want 2 spots behind coma
    Last edited by Char; 12-20-2009 at 08:39 PM.

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    %.2f can work for floating point numbers, but for me, there are too many unknowns here. What is a the circle variable, what does area(4) return. How are things not working? What errors are being shown? Have you set the locale? etc...

  14. #14
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    well thanks it worked like that %0.2f

    really thank you..you are the most active member in this forum and i see you helping people in all topics...

    biggg ups for youuu :)

    Java Code:
    public class Ring extends Kujund {
    	private int raadius;
    	public Ring(int raadius){
    		this.raadius=raadius;
    	}
    	public int getRaadius() {
    		return raadius;
    	}
    	public void setRaadius(int raadius) {
    		this.raadius = raadius;
    	}
    	public double ümbermõõt(int raadius){
    		return 2*raadius*Math.PI;
    	}
    	public double pindala(int raadius){
    		return Math.pow(raadius, 2)*Math.PI;
    	}
    	
    }
    Java Code:
    public class Test {
    	public static void main(String[] args){
    		Ring ring=new Ring(4);
    		Ruut ruut=new Ruut(5);
    		System.out.printf("Ringi pindala on: %.2f",ring.pindala(ring.getRaadius()));
    	}
    }
    btw there were my classes..ring is a circle class..and it has area and girth of it etc
    Last edited by Char; 12-20-2009 at 08:54 PM.

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    This here bothers me:
    Java Code:
    public class Ring extends Kujund {
    	private int raadius;
    	public Ring(int raadius){
    		this.raadius=raadius;
    	}
    	//..
    
    	public double ümbermõõt(int raadius){
    		return 2*raadius*Math.PI;
    	}
    	public double pindala(int raadius){
    		return Math.pow(raadius, 2)*Math.PI;
    	}
    	
    }
    The last two methods ignore the radius field held by the object here:
    Java Code:
    private int raadius;
    and allow you to pass as a parameter a new radius, that doesn't set the class's raadius field. Better I think would be have these two methods take no parameters, like so:

    Java Code:
    	public double ümbermõõt() {
    		return 2*raadius*Math.PI;
    	}
    	public double pindala() {
    		return Math.pow(raadius, 2)*Math.PI;
    	}
    This would allow the methods to use the raadius field held by the object.

  16. #16
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    humm wait..i didnt exactly get what you mean?
    why shouldnt i use that variable there when im using it inside method?
    im a little confused.because english aint my mother tongue

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Perhaps this is best explained with an example. Say we had a Student class that holds the student's name:

    Java Code:
    public class Student {
      private String name;
    
      public Student(String name) {
        this.name = name;
      }
    
      public String getName() {
        return name;
      }
      
      public void displayInformation(String name) {
        System.out.println("Hi, my name is " + name);
      }
      
      public void displayInformation() {
        System.out.println("Hi, my name is " + name);
      }
      
    }

    There are two displayInformation methods here, one that takes no parameter:
    Java Code:
      public void displayInfo() {
        System.out.println("Hi, my name is " + name);
      }

    and one that takes a String parameter:
    Java Code:
      public void displayInformation(String name) {
        System.out.println("Hi, my name is " + name);
      }

    If you create a test program that uses this Student class like so:
    Java Code:
    public class TestStudent {
      public static void main(String[] args) {
    
        // create a new student whose name is set to "George Bush"
        Student student = new Student("George Bush");
        
        student.displayInformation();
        student.displayInformation("Barak Obama");
      }
    
    }
    You'll see that this is the output
    Java Code:
    Hi, my name is George Bush
    Hi, my name is Barak Obama

    The output from the parameterless method on top is correct since we are seeing the true name of the student. The output from the method that passes a parameter is not correct since its name parameter is "shadowing" the Student's name field; it's covering it over and giving us false information.

    Make sense?
    Last edited by Fubarable; 12-20-2009 at 09:26 PM.

  18. #18
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    yeah its kinda clear now.

  19. #19
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    im trying to use robot class...but why it insists that i must use try and catch
    i have no idea what they are..can someone explain

    well my code is this..simple but even now i have error..

    Java Code:
    import java.awt.Color;
    import java.awt.Robot;
    
    public class Test {
    	public static void main(String[] args){
    		Robot robot1=new Robot();
    		robot1.mouseMove(300, 200);
    	}
    }

  20. #20
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

Page 1 of 2 12 LastLast

Similar Threads

  1. questions for 1yr exp
    By rahaman.athiq in forum Java Servlet
    Replies: 2
    Last Post: 11-26-2008, 01:13 AM
  2. I have Questions -_-
    By ChazZeromus in forum New To Java
    Replies: 5
    Last Post: 09-13-2008, 08:08 PM
  3. Questions About JSP?
    By mtz1406 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-19-2008, 07:56 PM
  4. Just a Few Questions
    By pringle in forum New To Java
    Replies: 21
    Last Post: 01-09-2008, 06:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •