LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 359 users online 225521 members 304 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
agerask
Favs: Oscar Wilde, Power of One (book)
Mood: Plain
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
1 online / 63 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Adding Reply

Adding Reply
Archived Topic: It will not be bumped to the top of the forum.
Topic JAVA help please
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
crazyjenn791 Posted at 4:56 pm on Sep. 15, 2008
this is the end of my program...:
import java.util.Scanner;

public class EnglishLanguage

{
public static void main(String[]args)
{
Scanner kb = new Scanner(System.in);

//Prompt user for a single digit, an operand and another simgle digit combination.
System.out.println("Enter an operation: ");

int operand1 = kb.nextInt();
// validate operand1
// if operand1 is not a single digit display an error message and exit
if( operand1 < 0 || operand1 > 9)
{
System.out.println("Error: Operand must be a single digit");
System.exit(0);
}
// operand1 is valid

// read an operator
String operatorStr = kb.next();
char operator = operatorStr.charAt(0);
// validate the operator
if( operator != '+' && operator != '-' && operator != '*' && operator != '/' && operator != '^')
{
System.out.println("Error: illegal operator");
System.exit(0);
}

int operand2 = kb.nextInt();

// validate operand2
// if operand2 is not a single digit display an error message and exit
if( operand2 < 0 || operand1 > 9)
{
System.out.println("Error: Operand must be a single digit");
System.exit(0);
}
// operand1 is valid

//Translate each operator and operand into the english language.

String operand1English = "unknown number";
switch(operand1)
{
case 0: operand1English = "zero";  break;
case 1: operand1English = "one";   break;
case 2: operand1English = "two";   break;
case 3: operand1English = "three"; break;
case 4: operand1English = "four";  break;
case 5: operand1English = "five";  break;
case 6: operand1English = "six";   break;
case 7: operand1English = "seven"; break;
case 8: operand1English = "eight"; break;
case 9: operand1English = "nine";  break;
default: System.out.println("Error: Operands must be single digits and positive.");
System.out.println("Try again later");
System.exit(0);
}

String operatorEnglish = "unknown number";
switch(operator)
{
case '+': operatorEnglish = " plus ";            break;
case '-': operatorEnglish = " minus ";           break;
case '*': operatorEnglish = " times ";           break;
case '/': operatorEnglish = " divided by ";      break;
case '^': operatorEnglish = " to the power of "; break;
default: System.out.println("Error: Illegal operator");
System.out.println("Try again later");
System.exit(0);
}

String operand2English = "unknown number";
switch(operand2)
{
case 0: operand2English = "zero";  break;
case 1: operand2English = "one";   break;
case 2: operand2English = "two";   break;
case 3: operand2English = "three"; break;
case 4: operand2English = "four";  break;
case 5: operand2English = "five";  break;
case 6: operand2English = "six";   break;
case 7: operand2English = "seven"; break;
case 8: operand2English = "eight"; break;
case 9: operand2English = "nine";  break;
default: System.out.println("Error: Operands must be single digits and positive.");
System.out.println("Try again later");
System.exit(0);
}

if (operand2 == 0 && operator == '/')
{
System.out.println("Error. Operation cannot be divided by zero.");
System.exit(0);
}

int result = -999;
switch(operator)
{
case '+': operatorEnglish = " plus ";            break;
case '-': operatorEnglish = " minus ";           break;
case '*': operatorEnglish = " times ";           break;
case '/': operatorEnglish = " divided by ";      break;
case '^': operatorEnglish = (int) Math.pow(operand1, operand2) ; break;
default: System.out.println("Error: Illegal operator");
System.out.println("Try again later");
System.exit(0);
}

// compute results of the operation
System.out.println((operand1English + operatorEnglish + operand2English) + "= " + result);


}

}

when i compile it, it says:  

incompatible types  
found : int
required: java.lang.String
case '^': operatorEnglish = (int) Math.pow(operand1, operand2) ; break;

what do i do,

Replies
crazyjenn791 Posted at 5:03 pm on Sep. 15, 2008
dude if you dont know what i`m talking about, bud out!
fizzle123 Posted at 5:02 pm on Sep. 15, 2008
Post from this position was omitted due to content violations
h a t t Posted at 4:58 pm on Sep. 15, 2008
nevermind.

change

case '^': operatorEnglish = (int) Math.pow(operand1, operand2) ; break;

to

case '^': operatorEnglish = Integer.toString( (int) Math.pow(operand1, operand2) ) ; break;

steven7 Posted at 4:57 pm on Sep. 15, 2008
go to w3schools.com
best help anywhere
draino Posted at 4:57 pm on Sep. 15, 2008
Post from this position was omitted due to content violations
All 5 previous replies displayed.