Hi everyone, I just registered with Java Forums and it looks fantastic. I just started studying java and I please need your help with a project I need to hand in.
The project I need to do is: (everything inside the quotation marks)...
"""Create a console calculator applicaion that:
* Takes one command line argument: your name and surname. When the
program starts, display the date and time with a welcome message for the
user.
* Display all the available options to the user. Your calculator must include
the arithmetic operations as well as at least five scientific operations of the
Math class.
-Your program must also have the ability to round a number and
truncate it.
-When you multiply by 2, you should not use the '*' operator to perform the
operation.
-Your program must also be able to reverse the sign of a number.
* Include sufficient error checking in your program to ensure that the user
only enters valid input. Make use of the String; Character, and other
wrapper classes to help you.
* Your program must be able to do conversions between decimal, octal and
hex numbers.
* Make use of a menu. You should give the user the option to end the
program when entering a certain option.
* When the program exits, display a message for the user, stating the
current time, and calculate and display how long the user used your
program.
* Make use of helper classes where possible.
* Use the SDK to run your program."""
I have already started to code this project, but I'm not sure if I am on the right track...
Here is my code so far...
Please have a look through my code and let me know where I have gone wrong.Code:import java.io.*;
import java.util.*;
import java.text.*;
public class Project {
static String nameSurname = "";
static String num = null;
static String num2 = null;
static int checkNumber = 0;
static String choice = null;
public static void main(String[] args) {
SimpleDateFormat format1 = new SimpleDateFormat("EEEE, dd MMMM yyyy");
Date now = new Date();
SimpleDateFormat format2 = new SimpleDateFormat("hh:m a");
Date now2 = new Date();
try {
BufferedReader inStream = new BufferedReader (
new InputStreamReader(System.in)
);
System.out.println("Please enter your name and surname :");
nameSurname = inStream.readLine();
System.out.println("\nA warm welcome to you " + nameSurname + " ,todays date is : " + format1.format(now));
System.out.println("and the time is now exactly " + format2.format(now2) + ".");
System.out.print("\nPlease enter a number and hit <ENTER>: ");
num = inStream.readLine();
checkNumber = (int) Double.parseDouble(num);
System.out.println("\nThe number you have entered is: " + num);
System.out.print("\nPlease enter another number and hit <ENTER>: ");
num2 = inStream.readLine();
checkNumber = (int) Double.parseDouble(num2);
System.out.println("\nThe number you have entered is: " + num2);
} catch (NumberFormatException nfe) {
System.out.println("You did not enter a valid number: " + "\""+ num + "\" is not a number!!");
return;
} catch (IOException e) {
System.out.println("IOException: " + e);
return;
}
System.out.println("\nThe two numbers you entered was: " + num + " and " + num2);
System.out.println("Please select an option of what you would like to do with these numbers: ");
System.out.println("\n*********************************************");
System.out.println("---------------------------------------------");
System.out.println("Please select an option from the list below: ");
System.out.println("---------------------------------------------");
System.out.println("1 - Add");
System.out.println("2 - Subtract");
System.out.println("3 - Multiply");
System.out.println("4 - Divide");
System.out.println("5 - Maximum value of two numbers");
System.out.println("6 - Minimum value of two numbers");
System.out.println("7 - Absolute value of number");
System.out.println("8 - Rounded number");
System.out.println("9 - Exit");
System.out.println("**********************************************");
try {
BufferedReader inStream2 = new BufferedReader (
new InputStreamReader(System.in)
);
System.out.println("Please enter your option:");
choice = inStream2.readLine();
checkNumber = (int) Integer.parseInt(choice);
System.out.println("\nYou have entered choice number: " + choice);
} catch (NumberFormatException nfe) {
System.out.println("You did not enter a valid choice number: " + "\""+ choice + "\" is not on the list!!");
return;
} catch (IOException e) {
System.out.println("IOException: " + e);
return;
}
}
}
Much appreciated.
Smirre

