Pages

සීමාවන් නොමැති අදහස් වලට පණ දෙන්න.....
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, February 25, 2010

Programming best practices

good programming practices 
using best practices when developing a program/project will help to make successful product without bugs. here are some best practices which needs to follow when developing a project.


Omit needless codes

Needless codes will make the codes unreadable and hard to understand. It will make hard to find the errors when any error has occur. Needless codes will add “lines of code” to the project and will support to earn more money to the developer. But when he/she needs to troubleshoot, needless codes will make hard to find the errors. Sometimes the needless codes will make some critical/hard to identify errors.

Identify duplicate codes
Identifying duplicate codes will helps to remove unnecessary “lines of codes” and will ease the debugging process. Editing the same code at several places will waste some time and delays the deployment of the project. So, it's better if the developer could identify duplicate codes and use that particular code at one place and linking that code to everyplace that needed. It will ease the editing/debugging process because developer no need to find everyplace to edit/debug and editing/debugging a single place will affects to the everyplace which the code is linked.

Using less number of “lines of codes”
When lines of code increased , the project will become large/heavy in size and hard to troubleshoot. So,the developer should use less number of “lines of codes”. Then the project will be smaller in size and will ease the troubleshooting process.

Commenting the codes
When developing a project, it's better if the developer could “comment” the every part of the program. It will helps to identify the usage of that particular “lines of code” and will ease the management/troubleshooting/update process of the program at later time.

Plan Development Process/Life-cycle
Planning the development process/life-cycle helps to determine every part of the development according to a structured plan. Then developer will not forget to do something important on his/her development process.

Plan the time line
Planning the time line will help to identify every work which have to do according to the time and developer could identify what should do in particular day and he/she could predict the development process according to the time.

Gathering Requirements.
Gathering requirements helps to develop the exact program which needs to built. If not programmer will end up with missing some requirements and will be unsuccessful. If the programmer didn't develop the program to fulfill the needs/requirements then developing the program will be useless.

Design
Selecting a suitable design will ease to use program by the user.

Coding separate parts and integrate them in to the main program.
It will ease troubleshoot and testing process as well as the coding process.

Testing
Without testing the developer can't identify the errors. If the developer didn't test his/her codes till the end of the development process, when he/she find any error will make him to edit/code many “lines of code” and it will make many errors. Editing many “lines of code” at the last time will make the programmer unsuccessful.

Performance testing
programmer should develop the program to give the actual performance to the user. So, performance testing will help to identify the missing parts and several errors which leads to minimize the performance.

Deployment
This is the last stage of the development process. This is the stage that user gets the project. Sometimes it will be failed due to some reasons and if it failed , user can't use the project as expected. Before deployment, developer should check a “deployment checklist” to ensure that user could use the product as expected.

System operations and support
There should be a method to identify errors when running the program. So, if there is a method to collect/identify the errors/bugs when running the program will be ease the work of “debugging”

Data migration
It's better if the program could support to the files/data which used in older/other programs. It will help to save the time to enter data into the new program because if there is an older program, user could use the data which associated with that old program inside the new program.

Project Management
Project management is the main part of the development process and it ensures that the existence programming best practices and follows the best practices.


Measuring success
checking the final project meets the industry standards.


Source:
Best practices for software development projects
http://www.ibm.com/developerworks/websphere/library/techarticles/0306_perks/perks2.html
Accessed on 02/24/2010 07:16 AM

Monday, October 19, 2009

hiring System program in java ( Command Line Interface )

Equiphire pvt. Ltd supplies 3 major equipments for hire.

Program which created for this company which runs on Command Line Interface. It
could handle using the main menu.

No ---|--- Item ---|--- Daily Rental ---|--- Deposit Value
1 ---|--- Electric Drill - --|--- 800 ---|--- 15000
2 ---|--- Water Pump ---|--- 500 ---|--- 7500
3 ---|--- Electric Jigsaw ---|--- 400 ---|--- 8000


main CLI interface of the program



______________________________________
How it works.
  • This program is a platform independent program. So, it could run on any operating system which has Java installed.
  • It runs on command line interface.
  • It saves data in files and retrieves data from them.
  • Program asks a choice as a numerical input from the keyboard. As mentioned
  • here, we can choose the appropriate value as our need.
_________________________________________________________________________

How could we use the program

Choice 1 brings the user to the Hiring System.
◦ We can add hire details via the program.
◦ Program will calculate the deposit value needed and the default deposit as well as the return value from the deposit.
◦ Transactions will be saved in a file for future use.

• Choice 2 brings the user to the Daily report.
◦ User could view the daily transactions of the company.
◦ User need to enter appropriate date on the YYYYMMDD format.
◦ System will automatically show every transaction which done in particular day.

• Choice 3 brings the user to the History of the hires of individual customer.
◦ User could easily find the hiring history of a customer using the customer ID.
◦ User need to enter appropriate customer ID in to the system.
◦ System will automatically show every transaction which done by particular customer.

• Choice 4 brings the user to the History of the hires of individual equipment.
◦ User could easily find the hiring history of an equipment using the equipment ID.
◦ User need to enter appropriate Equipment ID in to the system.
◦ System will automatically show a history of the hirings which done on the particular equipment.

• Choice 5 brings the user to the History of the hires of the Company
◦ User could easily find the full hiring history of the Company.

• Choice 6 brings the user to the Customer database.
◦ User could easily find the full list of the Customer database.

• Choice 7 provides the facility to add Customers to the system.
◦ User could easily add Customers to the system.
◦ User need to add the customers name and the email address. Customer ID and registered date will be added automatically to the system.
◦ It will saved in a file for future use.

• Choice 8 provides the facility to add Equipments to the system.
◦ User could easily add a Equipments to the system.
◦ User need to add Equipment ID, Name, daily rental and the Deposit value.
◦ It will saved in a file for future use.


//////////////////////////////////////////////////////////////////////////////////////////////////
// //
// //
// hiringSystem //
// //
// K.W.Roshan Herath //
// //
// //
// //
// //
// //
//______________________________________________________________________________________________//
// created on opnSUSE 11.0 with //
// java version "1.6.0_06" //
// Java(TM) SE Runtime Environment (build 1.6.0_06-b02) //
// Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode) //
// //
//////////////////////////////////////////////////////////////////////////////////////////////////


import java.util.*;

import java.io.*;

import java.lang.*;
import java.lang.String.*;



class hiringSystem
{

private InputStreamReader ir=new InputStreamReader(System.in);


private BufferedReader br;

private FileOutputStream fos;

private PrintStream ps;

private FileReader frs;


//function to check the existence for a file

private boolean checkFile(String filename)

{

File myFile=new File(filename);

boolean b=myFile.exists();



return b;

}
//////////////////////////////////////////////////////////////////////////////////////////////////
// function to get date //
//////////////////////////////////////////////////////////////////////////////////////////////////

private String fdate()

{
String date;
int month,day,year;
GregorianCalendar calendr;

calendr=new GregorianCalendar();
day=calendr.get(calendr.DATE);
month=calendr.get(calendr.MONTH);
month+=1;//to add january as 1 instead of 0
year=calendr.get(calendr.YEAR);

date = year +""+ month +""+ day;

return date;

}


//////////////////////////////////////////////////////////////////////////////////////////////////
// function to make a hire //
//////////////////////////////////////////////////////////////////////////////////////////////////

private void hire()throws IOException

{
//////////////////////////////////////////////////////////////////
/* String chkcustID,chkcustName,chkemail,chks,chkdateRegd;
long datenow,duration,chkdateReg;

String cline[]=new String[5];


frs=new FileReader("ITE1101As2OctE091041007Customers.txt");

br=new BufferedReader(frs);


while((chks=br.readLine()) != null)

{

cline=chks.split(",");

chkcustID=cline[0];

chkcustName=cline[1];

chkemail=cline[2];

chkdateRegd=cline[3];

}
datenow=(long)fdate();
chkdateReg=(long)chkdateRegd;

duration=datenow-chkdateReg;
*/
//////////////////////////////////////////////////
String custID,datehired,msg,s="y";
String equipID,cuID;
int days,type;
double deposit=0,deposit1=0,rental,returnval;


while(s.equals("y")) {
try{
br=new BufferedReader(ir);

System.out.println("\nEnter Equipment Type");
System.out.println("\n1 FOR ELECTRIC DRILL");
System.out.println("2 FOR WATER PUMP");
System.out.println("3 FOR ELECTRIC JIGSAW ");
System.out.print("\nEnter Equipment Type 1,2,3: ");
type=Integer.parseInt(br.readLine());
System.out.print("\nEnter Equipment ID: ");
equipID=br.readLine();

System.out.print("\nEnter Customer ID: ");
cuID=custID=br.readLine();

System.out.print("\nEnter no of days hired for: ");
days=Integer.parseInt(br.readLine());
datehired=fdate();

System.out.print("\n registered date :"+datehired+"\n\n");

br=new BufferedReader(ir);

if(type==1)
{ deposit=800*days;if(deposit<=15000) deposit1=15000; else deposit1=deposit;} else if(type==2) { deposit=500*days;if(deposit<=15000) deposit1=7500; else deposit1=deposit;} else if(type==3) { deposit=400*days; if(deposit<=15000) deposit1=8000; else deposit1=deposit;} System.out.println("\ndeposit must : "+deposit1); System.out.println("\ndeposit need : "+deposit); returnval=deposit1-deposit; System.out.println("\nretrun value must : "+returnval); fos=new FileOutputStream("ITE1101As2OctE091041007Transaction.txt",true); ps=new PrintStream(fos); ps.println(equipID+","+custID+","+datehired+","+days+","+deposit1+","+deposit+","+returnval); fos.close(); System.out.println("Hire successfull"); } catch(Exception ex) { System.out.println("Error in accepting specifications..."); } } } ////////////////////////////////////////////////////////////////////////////////////////////////// // to view daily report // ////////////////////////////////////////////////////////////////////////////////////////////////// private void dailyReport()throws IOException { String equipID,custID,datehired,days,deposit1,deposit,returnval,s,searchDate; String cline[]=new String[7]; InputStreamReader Ir=new InputStreamReader(System.in); BufferedReader Br=new BufferedReader(Ir); System.out.print("\nEnter date YYYYMMDD: "); searchDate=Br.readLine(); try { frs=new FileReader("ITE1101As2OctE091041007Transaction.txt"); br=new BufferedReader(frs); System.out.println("daily report for : "+searchDate); System.out.println("Equip \tby \thired \t\tforDays \tdeposit\tpayable\treturn"); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); equipID=cline[0]; custID=cline[1]; datehired=cline[2]; days=cline[3]; deposit1=cline[4]; deposit=cline[5]; returnval=cline[6]; if(datehired.equals(searchDate)){ System.out.println(datehired+"\t"+equipID+"\t"+custID+"\t"+days+"\t\t"+deposit1+"\t"+deposit+"\t"+returnval); } }} catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the Customer report...!"); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // to view hire history for individual customer // ////////////////////////////////////////////////////////////////////////////////////////////////// private void indCust()throws IOException { String equipID,custID,datehired,days,deposit1,deposit,returnval,s,customerID; String cline[]=new String[7]; InputStreamReader Ir=new InputStreamReader(System.in); BufferedReader Br=new BufferedReader(Ir); System.out.print("\nEnter Customer ID: "); customerID=Br.readLine(); try { frs=new FileReader("ITE1101As2OctE091041007Transaction.txt"); br=new BufferedReader(frs); System.out.println("Hire history for : "+customerID); System.out.println("Equip \tby \thired \t\tforDays \tdeposit\tpayable\treturn"); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); equipID=cline[0]; custID=cline[1]; datehired=cline[2]; days=cline[3]; deposit1=cline[4]; deposit=cline[5]; returnval=cline[6]; if(custID.equals(customerID)){ System.out.println(custID+"\t"+equipID+"\t"+datehired+"\t"+days+"\t\t"+deposit1+"\t"+deposit+"\t"+returnval); } }} catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the Customer report...!"); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // to view hire history for equipments // ////////////////////////////////////////////////////////////////////////////////////////////////// private void indEquip()throws IOException { String equipID,custID,datehired,days,deposit1,deposit,returnval,s,equipmentID; String cline[]=new String[7]; InputStreamReader Ir=new InputStreamReader(System.in); BufferedReader Br=new BufferedReader(Ir); System.out.print("\nEnter Equipment ID: "); equipmentID=Br.readLine(); try { frs=new FileReader("ITE1101As2OctE091041007Transaction.txt"); br=new BufferedReader(frs); System.out.println("Hire history for : "+equipmentID); System.out.println("Equip \tby \thired \t\tforDays \tdeposit\tpayable\treturn"); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); equipID=cline[0]; custID=cline[1]; datehired=cline[2]; days=cline[3]; deposit1=cline[4]; deposit=cline[5]; returnval=cline[6]; if(equipID.equals(equipmentID)){ System.out.println(equipID+"\t"+custID+"\t"+datehired+"\t"+days+"\t\t"+deposit1+"\t"+deposit+"\t"+returnval); } }} catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the Customer report...!"); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // displayReport() // ////////////////////////////////////////////////////////////////////////////////////////////////// private void displayReport() { String equipID,custID,datehired,days,deposit1,deposit,returnval,s; String cline[]=new String[7]; try { frs=new FileReader("ITE1101As2OctE091041007Transaction.txt"); br=new BufferedReader(frs); System.out.println("Equip \tby \thired \t\tforDays \tdeposit\tpayable\treturn"); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); equipID=cline[0]; custID=cline[1]; datehired=cline[2]; days=cline[3]; deposit1=cline[4]; deposit=cline[5]; returnval=cline[6]; System.out.println(equipID+"\t"+custID+"\t"+datehired+"\t"+days+"\t\t"+deposit1+"\t"+deposit+"\t"+returnval); } } catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the daily transaction report...!"); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // to view customer details // ////////////////////////////////////////////////////////////////////////////////////////////////// private void viewCust() { String custID,custName,email,dateRegd,s; String cline[]=new String[4]; try { frs=new FileReader("ITE1101As2OctE091041007Customers.txt"); br=new BufferedReader(frs); System.out.println("Customer ID \tCustomer Name \temail \t\tDate registered "); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); custID=cline[0]; custName=cline[1]; email=cline[2]; dateRegd=cline[3]; System.out.println(custID+"\t\t"+custName+"\t\t\t"+email+"\t"+dateRegd); } } catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the Customer report...!"); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // function to add a customer // ////////////////////////////////////////////////////////////////////////////////////////////////// //function for auto-generating the customer id private String generate_id() { String id=" "; String thisLine; String[] fullText = new String[200]; String[] lastLine=new String[5]; int counter=0,nid=0,l=0,z=0; boolean b=checkFile("ITE1101As2OctE091041007Customers.txt"); if(b==false) { id="00001"; } else { try { frs=new FileReader("ITE1101As2OctE091041007Customers.txt"); br=new BufferedReader(frs); while((thisLine=br.readLine()) != null) { counter=counter+1; fullText[counter] = thisLine; } frs.close(); lastLine=fullText[counter].split(","); nid=Integer.parseInt(lastLine[0]); nid=nid+1; l=(String.valueOf(nid)).length(); z=5-l; for(int i=1;i<=z;i++) { id=id+"0"; } id=id+String.valueOf(nid); id=id.substring(1); } catch(Exception ex) { System.out.println("Could not generate the Customer ID...!"); } } return id; } //function to add new Customer private void addCustomer() { String desc; String cust,email,regd; String id; try { id=generate_id(); System.out.print("\n Customer ID :"+id+"\n"); br=new BufferedReader(ir); System.out.print("\n Customer Name : "); cust=br.readLine(); System.out.print("\n Email : "); email=br.readLine(); regd=fdate(); System.out.print("\n registered date :"+regd+"\n\n"); br=new BufferedReader(ir); fos=new FileOutputStream("ITE1101As2OctE091041007Customers.txt",true); ps=new PrintStream(fos); ps.println(id+","+cust+","+email+","+regd); fos.close(); System.out.println("Successfully added one Customer..."); } catch(Exception ex) { System.out.println("Error in accepting Customer specifications..."); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // function to add an Equipment // ////////////////////////////////////////////////////////////////////////////////////////////////// private boolean checkFile1(String filename) { File myFile1=new File(filename); boolean b1=myFile1.exists(); return b1; } boolean b1=checkFile1("ITE1101As2OctE091041007Equipments.txt"); //function to add new equipment private void addEquipment() { String equip; double drent=0; double deposit=0; String id; int availability=1; try { br=new BufferedReader(ir); System.out.print("\n Equipment ID :"); id=br.readLine(); System.out.print("\n Equipment Name : "); equip=br.readLine(); System.out.print("\n Daily rental :"); drent=Double.parseDouble(br.readLine()); System.out.print("\n Deposit :"); deposit=Double.parseDouble(br.readLine()); fos=new FileOutputStream("ITE1101As2OctE091041007Equipments.txt",true); ps=new PrintStream(fos); ps.println(id+","+equip+","+drent+","+availability+","+deposit); fos.close(); System.out.println("Successfully added one Equipment"); } catch(Exception ex) { System.out.println("Error in accepting specifications..."); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // HELP // ////////////////////////////////////////////////////////////////////////////////////////////////// /*private void help() { System.out.println(" HIRING SYSTEM HELP "); }*/ ////////////////////////////////////////////////////////////////////////////////////////////////// // MAIN Method // ////////////////////////////////////////////////////////////////////////////////////////////////// public static void main(String args[]) throws IOException { hiringSystem inv=new hiringSystem(); int ch=0; String s; InputStreamReader ir=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(ir); System.out.println("\n\n\n"); System.out.println("--------------------------------------------------"); System.out.println(" EquipHire Pvt. Ltd "); System.out.println(" උපකරණ කුලියට දීම "); System.out.println("--------------------------------------------------\n"); System.out.println("1. HIRE AN EQUIPMENT"); System.out.println("2. TO VIEW THE DAILY REPORT"); System.out.println("3. TO VIEW HIRE HISTORY OF A CUSTOMER"); System.out.println("4. TO VIEW HIRE HISTORY OF AN EQUIPMENT"); System.out.println("5. VIEW FULL HIRING REPORT"); System.out.println("6. VIEW ALL CUSTOMERS"); System.out.println("7. ADD NEW CUSTOMER"); System.out.println("8. ADD AN EQUIPMENT"); System.out.println("---------------------------------"); System.out.println("9. Exit"); begin: while(ch!=9) { System.out.print("\n"); System.out.print("\n Enter a choice and Press ENTER to continue[1-9]:"); ch=Integer.parseInt(br.readLine()); if(ch>9||ch<1)

{

System.out.println("This doesn't appear to be a valid option...!");

continue begin;

}



////////////////////////////////////////////////////////////////////////////////////////////

if(ch==1)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.hire();

System.out.print("\n Hire another[y/n]:");

s=br.readLine();

}

}

////////////////////////////////////////////////////////////////////////////////////////////
else

if(ch==2)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.dailyReport();
System.out.print("\n View again ?[y/n]:");

s=br.readLine();




}

}
////////////////////////////////////////////////////////////////////////////////////////////
else

if(ch==3)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.indCust();
System.out.print("\n View again ?[y/n]:");

s=br.readLine();


}

}
///////////////////////////////////////////////////////////////////////////////////////////
else

if(ch==4)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.indEquip();
System.out.print("\n View again ?[y/n]:");

s=br.readLine();



}

}
////////////////////////////////////////////////////////////////////////////////////
else

if(ch==5)

{

inv.displayReport();

}
/////////////////////////////////////////////////////////////////////////////////////
else

if(ch==6)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.viewCust();
System.out.print("\n View again ?[y/n]:");

s=br.readLine();



}

}
////////////////////////////////////////////////////////////////////////////////////////
else
if(ch==7)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.addCustomer();

System.out.print("\n Add another[y/n]:");

s=br.readLine();

}

continue begin;

}
////////////////////////////////////////////////////////////////////////////////////////

else
if(ch==8)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.addEquipment();

System.out.print("\n Add another[y/n]:");

s=br.readLine();

}

}
////////////////////////////////////////////////////////////////////////////////////////


}

System.out.println("Thanks for using this program...!");

}

}


__________________________________________________________________________________

  1. there are some errors in my program.
  2. it needs 3 text files to store data.
  3. before add a customer, it should have atlest 00000 as the1st data in the customer file.
  4. can hire w/o registering as a customer.
  5. can hire equipment which isn't in the equipment file.
  6. cant find the equipment is available to hire or not.
  7. .cant calculate delays.
i'l try to solve these problems as i get free time from my studies. please help me if you can.

Tuesday, October 6, 2009

a program that would read a number and the base of the number system and print the equivalent decimal value ( for many bases) using Integer.pasrseInt

a program that would read a number and the base of the number system
and print the equivalent decimal value ( for many bases ) using Integer.pasrseInt

01# import java.util.Scanner;
02#
03# public class javaprog{
04#
05# public static void main(String[] args){
06#
07# System.out.println("\n\n\tProgram using Integer.parseInt \n");
08# System.out.println("\t tested with many digits and bases like base 2 to base 10 and base 16 \n");
09#
10# //ask the value to convert
11# System.out.print("Enter the value which you want to convert in to decimal:");
12# Scanner parseint = new Scanner(System.in);
13# String parseintVal=parseint.next();
14#
15# //ask for the base of the value which enterd
16# System.out.print("\nEnter the base of the value which you entered first:");
17# Scanner parseintScan = new Scanner(System.in);
18# int parseintBase = parseintScan.nextInt();
19#
20# //calculation using Integer.parseInt
21# int i= Integer.parseInt(parseintVal,parseintBase);
22#
23# //prints the decimal value
24# System.out.println("\n\t Decimal Value of " +parseintVal+ " ( base "+ parseintBase+ " ) is "+i+"\n");
25#
26# }
27# }
28#


output:
Program using Integer.parseInt
tested with many digits and bases like base 2 to base 10 and base 16
Enter the value which you want to convert in to decimal:123ACD
Enter the base of the value which you entered first:16
Decimal Value of 123ACD ( base 16 ) is 1194701

a program that would read a number and the base of the number system and print the equivalent decimal value

a program that would read a number and the base of the number system
and print the equivalent decimal value ( for bases less than 10 ) using Math.pow

01# import java.util.Scanner;
02#
03# public class javaprog{
04#
05# public static void main(String[] args){
06#
07# //base of the value which enterd
08# System.out.print("Enter the base of the value which you wish to enter :");
09# Scanner scan = new Scanner(System.in);
10# double base = scan.nextInt();
11#
12# //value to convert
13# System.out.println("\n You need to add zero '0' in front of the value, if itdoesn't have 8 digits \n");
14# System.out.print("Enter the value which you want to convert in to decimal:");
15# Scanner value = new Scanner(System.in).useDelimiter("");
16#
17# //scans the value by nextInt(); and saves them as int
18# int d0=value.nextInt();
19# int d1=value.nextInt();
20# int d2=value.nextInt();
21# int d3=value.nextInt();
22# int d4=value.nextInt();
23# int d5=value.nextInt();
24# int d6=value.nextInt();
25# int d7=value.nextInt();
26#
27# //calculates the powers using Math.pow(base,exp);
28# int v7=(int)Math.pow(base,7)*d0;
29# int v6=(int)Math.pow(base,6)*d1;
30# int v5=(int)Math.pow(base,5)*d2;
31# int v4=(int)Math.pow(base,4)*d3;
32# int v3=(int)Math.pow(base,3)*d4;
33# int v2=(int)Math.pow(base,2)*d5;
34# int v1=(int)Math.pow(base,1)*d6;
35# int v0=(int)Math.pow(base,0)*d7;
36#
37# //calculates the sum of v0 to v7
38# int decimalValue=v0+v1+v2+v3+v4+v5+v6+v7;
39#
40# //casting base to int
41# int base1=(int)base;
42#
43# //prints the result
44# System.out.println("\n\tYou entered : " +d0+d1+d2+d3+d4+d5+d6+d7 + " with base : " +base1 );
45# System.out.println("\n\tdeciaml value for : " +d0+d1+d2+d3+d4+d5+d6+d7 +" using Math.pow is :"+ decimalValue);
46#
47# }
48# }




output:

Enter the base of the value which you wish to enter :8
You need to add zero '0' in front of the value, if it doesn't have 8 digits
Enter the value which you want to convert in to decimal:45454545
You entered : 45454545 with base : 8
deciaml value for : 45454545 using Math.pow is :9853285
Related Posts with Thumbnails