Results 1 to 3 of 3
  1. #1
    Steineronie is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Question how to make a resource class

    hi, instead of typing something like System.out.print(""); over and over again i wanted to make a resource class so i could just use a short reference instead of writing a long line of code each time you wanted to do something like write something onto the screen.

    I have tried to do this with the scanner but it isnt working:
    Java Code:
    import java.util.Scanner;
    
    class apples {
    	static String Input;
    	
    	public static void main(String args[]){
    		Scanner input = new Scanner(System.in);
    		Res Res = new Res();
    		
    		System.out.println("type");
    		Res.Input(input);
    		System.out.println("hello " + Input);
    	}	
    }
    and:
    Java Code:
    import java.util.Scanner;
    
    public class Res {
    	
    	private String Input;
    	
    	public void Var(String Input){
    		this.Input = Input;
    	}
    	
    	public String vInput(){
    		return Input;
    	}
    	
    	public void Input(Scanner input){
    		String Input = input.nextLine();
    	}
    }
    can anyone tell me why this isn't working please.
    and could you tell me how i would make a reference for the System.out.print(""); please.

  2. #2
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: how to make a resource class

    Your code doesn't really make any sense. First you should never call an instance the same name as the class ie: Res Res = new Res(); Second it is a VERY good habit to Explicitly define your default constructor. What exactly are your methods supposed to do? You are better off making a static class and method for what your are trying to do. You are doing a lot of typing trying to reduce your typing. Also Scanner is not a static class. You cannot invoke a non-static method from a static context. You need to instantiate a Scanner object to take input.

    hope this helps!

  3. #3
    Steineronie is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

Similar Threads

  1. How can I make this class immutable?
    By fatabass in forum New To Java
    Replies: 6
    Last Post: 12-18-2011, 10:08 PM
  2. Make JVM use My Own Class Loader
    By rajyshubeita@gmail.com in forum Advanced Java
    Replies: 1
    Last Post: 11-18-2011, 09:41 PM
  3. Can't make a java .class to a .jar
    By TheDarkMagician in forum New To Java
    Replies: 4
    Last Post: 02-19-2011, 11:45 PM
  4. Deleted Class template code. Now I cant make class.
    By AcousticBruce in forum IntelliJ IDEA
    Replies: 0
    Last Post: 01-11-2011, 10:52 PM
  5. Replies: 0
    Last Post: 07-01-2008, 09:06 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
  •