i just finished my first year in software engineering so I'm a noobie
What do you think about my code (for my level of course), is the way I think about development and design ok?
(is just that I need some opinions to know if what I'm doing it's alright or not,
public class Converter {
public static void main(String[] args) {
char choice;
do{
System.out.println("Choose a converter: ");
System.out.println("1 - for kilo to pounds");
System.out.println("2 - for pounds to kilo");
choice = UserInput.readChar();
while (choice!='1' && choice!='2'){
System.out.println("Invalid Character!");
System.out.println("1 - for kilo to pounds");
System.out.println("2 - for pounds to kilo");
choice = UserInput.readChar();
}//end while(choice!='1' && choice!='2') statement
switch (choice){
case '1': kiloToPounds();//call kiloToPounds method
break;
case '2': poundsToKilo();//call poundsToKilo method
break;
}//end switch statement
System.out.println("Restart Converter?");
System.out.println("Y/N");
choice = UserInput.readChar();
while (choice!='Y' && choice!='y' && choice!='N' && choice!='n'){
System.out.println("Invalid Character!");
System.out.println("Restart Converter?");
System.out.println("Y/N");
choice = UserInput.readChar();
}//end while(choice!='Y' || choice!='y' && choice!='N' || choice!='n') statement
}while (choice=='Y' || choice=='y');//end do-while statement
}//end main
private static void kiloToPounds() {
double kg;
System.out.println("Input the number of kg:");
kg = UserInput.readDouble();
System.out.println(kg+" kg = "+kg*2.2+" pounds");
}//end kiloToPounds method
private static void poundsToKilo() {
double pound;
System.out.println("Input the number of pounds :");
pound = UserInput.readDouble();
System.out.println(pound+" pounds = "+pound/2.2+" kg");
}//end poundsToKilo method
}//end Converter class
cheers

New Topic/Question
Reply


MultiQuote




|