I am a Java beginner and I have just started to learn Java classes
I am trying how to figure out how to get user input when using get and set methods
I know how to user input using just a program using main (See below)
import.java.util.Scanner
public class DIC{
public static void main(String []args){
int userInput = 0;
Scanner input = new Scanner(System.in);
userInput - input.nextInt();
}
}
However, I cannot figure out how to get the proper user input using a separate Class and set and get methods.
How can I get the user to enter the values 10 for height and 25 for width
public class Oblong
{
// instance variables
private double height;
private double width;
// 2 getter methods
public double getHeight()
{
return height;
}
public double getWidth()
{
return width;
}
//2 Setter Methods
public void setWidth(double widthIn)
{
width = widthIn;
}
public void setHeight(double heightIn)
{
height = heightIn;
}
//Calculate Method
public double calculateArea()
{
return width * height;
}
}// end of class
public class OblongTester
{
public static void main(String [] args)
{
Oblong myOblong = new Oblong();
myOblong.setHeight(10);
myOblong.setWidth(25);
System.out.println(myOblong.getHeight());
System.out.println(myOblong.getWidth());
System.out.println(myOblong.calculateArea());
}
}

New Topic/Question
Reply



MultiQuote




|