Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: simple java console program, need help recalling commands

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default simple java console program, need help recalling commands

    i wanna do this

    http://www.google.com/url?sa=t&sourc...yYKNmQ&cad=rja

    but on windows and in this java program

     
     
    //page 359 # 7 / lab 2
    //a "shell" that uses Circle.class
     
    import java.util.Scanner;
     
    public class circle_main
    {
     
    	public static void main(String[] args)
    	{
    		boolean rerun = true;
    		//char rerunc;//rerun as a char
     
    		Scanner keyboard = new Scanner(System.in);//declairing scanner class
     
    		String input = "";
    		String prompt = "Prompt";
    		Circle circle1 = new Circle(0);
     
    		System.out.print("Circle calculator v.90"  + "\n\n\n" + "use \"help\" for help" + "\n\n");
     
    		while(rerun)
    		{	
     
    			System.out.print(prompt + ": ");
    			input = keyboard.nextLine();//eats ur input
    			//System.out.print(input.substring(0,input.length()) + "\n");
    			//System.out.print(input.length() + "\n");
     
    			if(input.matches("(?i)help.*") == true)
    			{
    				System.out.print("\ncommands are:\nprompt <string>\nsetRadius <double>\ngetRadius\ngetArea\ngetDiameter\ngetCircumference\nexit\n\n");
    			}
     
    			else if(input.matches("(?i)prompt.*") == true)
    			{
    				prompt = input.substring(7,input.length());
    			}
     
    			else if(input.matches("(?i)setradius.*") == true)	
    			{
    				circle1.setRadius(Double.parseDouble(input.substring(10,input.length())));			
    			}
     
    			else if (input.matches("(?i)getradius.*") == true)
    			{
    				System.out.print("The radius is: " + circle1.getRadius() + "\n");
    			}
     
    			else if (input.matches("(?i)getarea.*") == true)
    			{
    				System.out.print("The area is: " + circle1.getArea() + "\n");
    			}
     
    			else if (input.matches("(?i)getdiameter.*") == true)
    			{
    				System.out.print("The diameter is: " + circle1.getDiameter() + "\n");
    			}
     
    			else if (input.matches("(?i)getcircumference.*") == true)
    			{
    				System.out.print("The circumference is: " + circle1.getCircumference() + "\n");
    			}
     
    			else if (input.matches("(?i)exit.*") == true)
    			{
    				rerun = false;
    			}
     
    			else
    			{
    				System.out.print("error, invalid command." + "\n");
    			}	
     
     
     
    		//System.out.print("\n" + "The area is: " + circle1.getArea() + "\n");//putput from circle
    		//System.out.print("The diameter is: " + circle1.getDiameter() + "\n");
    		//System.out.print("The circumference is: " + circle1.getCircumference() + "\n\n\n");
     
    		//System.out.print("Would you like to rerun the program? (Y/N): ");//rerun?
    		//rerunc = keyboard.next().charAt(0);//next char becomes rerunc
     
    		//if (rerunc == 'y' || rerunc == 'Y')//if yes
    		//{
    			//rerun = true;
    			//System.out.print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    		//}
     
    		//else//if n e thing besides 'y' || 'Y'
    		//{
    			//rerun = false;
    		//}
     
     
    		}	
    	}
    }

    and this class

     
    //page 359 # 7
    //a class storing gets sets and calculations for circle.java
     
    public class Circle 
     
    {
     
    			private double radius;
     
     
    			public Circle()//no arg const
    			{
    				radius = 0.0;
    			}
     
    			public Circle(double radiusMain)//radius const
    			{
    				radius = radiusMain;
    			}
     
     
     
    			public void setRadius(double radiusMain)//didnt know a better way to do this
    			{										//since i didnt use a radius variable in main
    				radius = radiusMain;
    			}
     
    			public double getRadius()//returns radius
    			{
    				return radius;
    			}
     
    			public double getArea()//returns area
    			{
    				return Math.PI * (radius * radius);
    			}
     
    			public double getDiameter()//returns diam
    			{
    				return radius * 2;
    			}
     
    			public double getCircumference()//returns circum
    			{
    				return Math.PI * (radius * 2);
    			}
     
    		}


    basically what i wanna do, is simulate what windows does in the command.exe, where u can use the up and down arrows to recall and edit previous commands...

    thanks ^^


  2. #2
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple java console program, need help recalling commands

    oh and heres the other link cuz it can be hard to find from the first link

    The GNU Readline Library

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: simple java console program, need help recalling commands

    Im not sure if this is possible
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. Need simple JAVA program fixing ASAP
    By theviper in forum Paid Java Projects
    Replies: 1
    Last Post: April 14th, 2010, 10:59 AM
  2. Executing Linux Commands with Java GUI
    By linuxrockers in forum AWT / Java Swing
    Replies: 2
    Last Post: February 15th, 2010, 09:57 PM
  3. PLEASE HELP!!!! simple java program...
    By parvez07 in forum Object Oriented Programming
    Replies: 5
    Last Post: August 26th, 2009, 06:38 AM
  4. help with simple java program
    By parvez07 in forum Java Theory & Questions
    Replies: 4
    Last Post: August 25th, 2009, 07:19 AM
  5. Simple java program to calculate wall covering of a room
    By parvez07 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 22nd, 2009, 03:31 PM

Tags for this Thread