1)i cant identify the error for this code.
public CarGetNSet
{
{
public static void main(String []args)
{
Car car = new Car();
car.setModel("BMW");
car.setColor("Red");
car.set(4000.78);
System.out.println("The car color is " + car.getColor());
System.out.printl("The car model is " + car.getModel());
System.out.println("The car mileage is " + car.getMileage());
}
public Class Car
{
private String color;
private String model;
private double mileage;
public void setColor(String color)
{
this.color = color;
}
public String getColor()
{
return color;
}
public void setModel(String model)
{
this.model = model;
}
public String getModel()
{
return model;
}
public void setMileage(double mileage)
{
this.mileage = mileage;
}
public double getMileage()
{
return mileage;
}
}
}
}
2)having the same problem as number 1
import javax.swing JOptionPane;
public WolfGoatCabbageRiddle
{
public static void main(String [] args)
{
String str;
String animal;
System.out.println("A farmer needs to move a wolf, a goat and a cabbage across a river.The boat is");
System.out.println("tiny and can only carry one passenger at a time.If he leaves the wolf and the goat");
System.out.println("alone together,the wolf will eat the goat.If he leaves the goat and the cabbage together,");
System.out.println("the goat will eat the cabbage.");
JOptionPane.showMessageDialog(null,"How can he brings all three safely across the river?", "Question",JOptionPane.Question_Message);
str=JOptionPane.showInputDialog("Which one of these three shall he picks first?","Answer");
animal=String.parseString(str);
if (animal=wolf)
JOptionPane.showDialogMessage(null,"GOAT WILL EAT THE CABBAGE.THEREFORE,YOU HAVE FAILED TO BRING ALL THREE SAFELY!!!!");
else
if (animal=cabbage)
JOptionPane.showDialogMessage(null,"WOLF WILL EAT THE GOAT.THEREFORE,YOU HAVE FAILED TO BRING ALL THREE SAFELY!!!!");
else
JOptionPane.showDialogMessage(null,"YOU HAVE MANAGE TO BRING ALL THESE THREE ACROSS THE RIVES SAFELY.THEREFORE,MISSION ACCOMPLISH!!!!!");
}
}
3)
public TestEmployeeGetNSet
{
public static void main(String [] args)
{
Employee Employee1=new Employee
Employee1.setEmpNo(40.0);
Employee1.setLastName("Abu");
System.out.println(Employee1.getEmpno());
System.out.println(Employee1.getLastName());
}
public class Employee
{
private int empNo;
private String lastName;
public int getEmpNo()
{
return empNo;
}
public void setEmpNo(int newEmpNo)
{
empNo=newEmpNo;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String newLastName)
{
lastName=newLastName;
}
}
}
4)is it possible if i want user to key in input for the case get and set method??how can i do it?Please help me out.Appreciate it.thanks
Edited by farhanyun91, 25 August 2010 - 10:13 AM.


Sign In
Create Account


Back to top









