Click to See Complete Forum and Search --> : Incompatible Type Error


bigkahuna
03-13-2007, 07:06 PM
Hey everyone,

I am trying to complete a driver class file for a program I am making. The only thing I can't figure out is how to ask the user if he or she wants to calculate another carpet sample, and then have the program scan the next CHAR, store it, and then in the "while" loop, see if the char entered matches the conditions necessary to end the loop. I think the problem is simple, I just can't figure it out. Any help you could offer would be appreciated. Thanks a lot!


//
// RoomDriver.java
// Description: This driver is the main program for these classes
/**
driver for the RoomDimensions program
*/

import java.util.*;

public class RoomDriver
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int feet, inches;
double cost;
char answer;

do{
System.out.println("Enter the room length...");
System.out.print("Feet = ");
feet = input.nextInt();
System.out.print("Inches = ");
inches = input.nextInt();
FeetInches length = new FeetInches(feet, inches);

System.out.println("Enter the room width...");
System.out.print("Feet = ");
feet = input.nextInt();
System.out.print("Inches = ");
inches = input.nextInt();
FeetInches width = new FeetInches(feet, inches);

RoomDimensions room = new RoomDimensions(length, width);

System.out.print("Enter the carpet cost per square foot: ");
cost = input.nextInt();
input.nextLine();

RoomCarpet carpet = new RoomCarpet(room, cost);
carpet.toString();
System.out.println("Would you like to price another room? (Y/N): ");
answer = input.nextLine();

}while((answer = "y") || (answer = "Y"));
}


}

agent_x91
03-14-2007, 06:52 AM
while((answer = "y" || (answer = "Y"));


An immediate mistake I noticed is you are using = instead of ==, and you should use single quote marks for chars. You also appear to have mismatched your parentheses. It should be


while(answer=='y'||answer=='Y');