LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 376 users online 225622 members 286 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
bella103
Peeves: Cheaters and liers
Mood: Relaxed
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
3 online / 21 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

JAVA help please
Replies: 5Last Post Sep. 15, 2008 5:03pm by crazyjenn791
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( crazyjenn791 )


Dairy Product Addict
Reply
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,

Post edited at 5:02 pm on Sep. 15, 2008 by crazyjenn791


4:56 pm on Sep. 15, 2008 | Joined: Jan. 2008 | Days Active: 118
Join to learn more about crazyjenn791 Canada | Posts: 677 | Points: 1,914
LiveWire Humor
Post from this position was omitted due to content violations
steven7


Connoisseur
Reply
go to w3schools.com
best help anywhere

-------
I have no signature.

4:57 pm on Sep. 15, 2008 | Joined: June 2003 | Days Active: 426
Join to learn more about steven7 Alabama, United States | Straight Male | Posts: 3,558 | Points: 7,812
h a t t



Patron
Reply
nevermind.

change

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

to

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

Post edited at 5:03 pm on Sep. 15, 2008 by h a t t


4:58 pm on Sep. 15, 2008 | Joined: June 2008 | Days Active: 305
Join to learn more about h a t t Ontario, Canada | Straight Male | Posts: 9,365 | Points: 31,968
Post from this position was omitted due to content violations
( crazyjenn791 )


Dairy Product Addict
Reply
dude if you dont know what i`m talking about, bud out!

5:03 pm on Sep. 15, 2008 | Joined: Jan. 2008 | Days Active: 118
Join to learn more about crazyjenn791 Canada | Posts: 677 | Points: 1,914
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic