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
Code java:
//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
Code java:
//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 ^^
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
Re: simple java console program, need help recalling commands
Im not sure if this is possible :confused: