Someone who can help to improve my program .. I need to add an Insert, Display and Delete in my program
but i dont know how to do that.
the sample output just like this :
-~-~-~-CONVERSION CHOICES-~-~-~-
+-------------------------------+
| [1] - Decimal |
| [2] - Binary |
| [3] - Octal |
| [4] - Hexadecimal |
| [5] - Exit |
+-------------------------------+
Select Number: 1
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+-------------------------------+
| [1] - ADD |
| [2] - DELETE |
| [3] - DISPLAY |
| [4] - Back to Choices |
| [5] - Back to Main Menu |
+-------------------------------+
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Enter your choice: 1
Enter Code: 1
Enter a Decimal Number: 200
Successfully added!
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+-------------------------------+
| [1] - ADD |
| [2] - DELETE |
| [3] - DISPLAY |
| [4] - Back to Choices |
| [5] - Back to Main Menu |
+-------------------------------+
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Enter your choice: 1
Enter Code: 2
Enter a Decimal Number: 100
Successfully added!
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+-------------------------------+
| [1] - ADD |
| [2] - DELETE |
| [3] - DISPLAY |
| [4] - Back to Choices |
| [5] - Back to Main Menu |
+-------------------------------+
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Enter your choice: 3
1.The Binary equivalent of 200 is : 11001000
The Octal equivalent of 200 is : 310
The Hex equivalent of 200 is : C8
2.The Binary equivalent of 100 is : 1100100
The Octal equivalent of 100 is : 144
The Hex equivalent of 100 is : 64
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+-------------------------------+
| [1] - ADD |
| [2] - DELETE |
| [3] - DISPLAY |
| [4] - Back to Choices |
| [5] - Back to Main Menu |
+-------------------------------+
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Enter your choice: 2
Enter Code: 1
Successfully Deleted!
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+-------------------------------+
| [1] - ADD |
| [2] - DELETE |
| [3] - DISPLAY |
| [4] - Back to Choices |
| [5] - Back to Main Menu |
+-------------------------------+
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Enter your choice: 3
1.The Binary equivalent of 100 is : 1100100
The Octal equivalent of 100 is : 144
The Hex equivalent of 100 is : 64
Here is my sample code so far.
MainProgram.java
import java.util.Scanner; public class MainProgram { public static int menu() { Scanner in = new Scanner (System.in); int ans = 0; System.out.println("\t\t-~-~-~-CONVERSION CHOICES-~-~-~-"); System.out.println("\t\t+-------------------------------+"); System.out.println("\t\t| [1] - Decimal |"); System.out.println("\t\t| [2] - Binary |"); System.out.println("\t\t| [3] - Octal |"); System.out.println("\t\t| [4] - Hexadecimal |"); System.out.println("\t\t| [5] - Exit |"); System.out.println("\t\t+-------------------------------+"); System.out.println("\t\t-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-"); System.out.print("Select a Number: "); ans = in.nextInt(); while (ans<=0 || ans >5) { System.out.println("\t\tINVALID INPUT"); System.out.println(); System.out.print("Enter Again: "); ans = in.nextInt(); } return ans; } public static void main(String [] args) { Scanner in = new Scanner (System.in); int ans = menu(); while(true) { switch(ans) { case 1: int anscon1 ; System.out.println(); System.out.println("\t\t-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-"); System.out.println("\t\t+-------------------------------+"); System.out.println("\t\t| [1] - ADD |"); System.out.println("\t\t| [2] - DELETE |"); System.out.println("\t\t| [3] - DISPLAY |"); System.out.println("\t\t| [4] - Back to Choices |"); System.out.println("\t\t| [5] - Back to Main Menu |"); System.out.println("\t\t+-------------------------------+"); System.out.println("\t\t-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-"); System.out.print("Enter your choice: "); anscon1 = in.nextInt(); if(anscon1 == 1) { } if(anscon1 == 2) { } if(anscon1 == 3) { } if(anscon1 == 4) { System.out.println("\t\t -o-o-o-Choices-o-o-o-"); } if(anscon1 == 5) { ans = menu(); } break;
Conversion.java
import java.util.Scanner; public class Conversion { /*---------------------DECIMAL---------------------*/ // Decimal to Binary public String DecToBin() { Scanner in = new Scanner (System.in); String numDec = " "; System.out.print("Enter a Decimal Number: "); numDec = in.nextLine(); int binDec = Integer.parseInt(numDec,10); String decBin = Integer.toBinaryString(binDec); System.out.println("The Binary equivalent is: " + decBin); System.out.println("-------------------------------------"); return decBin; } //Decimal to Octal public String DecToOct() { Scanner in = new Scanner (System.in); String numDec = " "; System.out.print("Enter a Decimal Number: "); numDec = in.nextLine(); int octDec = Integer.parseInt(numDec,10); String decOct = Integer.toOctalString(octDec); System.out.println("The Octal equivalent is: " + decOct); System.out.println("-------------------------------------"); return decOct; } //Decimal to Hexadecimal public String DecToHex() { Scanner in = new Scanner (System.in); String numDec = " "; System.out.print("Enter a Decimal Number: "); numDec = in.nextLine(); int hexDec = Integer.parseInt(numDec,10); String decHex = Integer.toHexString(hexDec); System.out.println("The Octal equivalent is: " + decHex.toUpperCase()); System.out.println("-------------------------------------"); return decHex; } }