help java prog. adding do{ while()
how will i add do{ while() to my program
this is my program
Code :
import java.util.*;
public class Triangle {
Scanner br = new Scanner(System.in);
private double height;
private double base;
public Triangle(double h, double b){
height=h;
base=b;
}
public Triangle(){
System.out.println("Enter Height of the Triangle: ");
double h=br.nextDouble();
height=h;
System.out.println("Enter Base of the Triangle: ");
double b=br.nextDouble();
base=b;
}
public double getHeight() {
return height;
}
public double getBase() {
return base;
}
public void setHeight(double height) {
}
public void setBase(double base) {
}
public double getArea(){
double area=0;
area=0.5*height*base;
return area;
}
public static void main(String[] args){
Triangle tr = new Triangle();
System.out.println("The Area of a Triangle is: "+tr.getArea());
}
}
Re: help java prog. adding do{ while()
Re: help java prog. adding do{ while()
any more other guides??cant seem to make it work because of its many method i do not know where to place it
Re: help java prog. adding do{ while()
That's really going to depend on your exact goal. What do you want the do while to do, exactly?
Re: help java prog. adding do{ while()
after The Area of a Triangle will be output a message that will say DO YOU WANT TO CONTINUE?? if i type Y then the program will reloop to the start where i will input the height etc. again
Re: help java prog. adding do{ while()
Quote:
Originally Posted by
darking123
after The Area of a Triangle will be output a message that will say DO YOU WANT TO CONTINUE?? if i type Y then the program will reloop to the start where i will input the height etc. again
Sounds good to me. So what have you tried? Where are you stuck? After reading the tutorial I posted, what don't you understand?
Re: help java prog. adding do{ while()
what i dont understand is placing the do and while in my program that has many method on it...can you guide me
Re: help java prog. adding do{ while()
Quote:
do {
someMethodCallThatDoesSomeCoolThing();
while(theUserStillWantsToDoSomeCoolThing);
}
There are many examples available through any search engine using the keywords "java do while loop examples"
Re: help java prog. adding do{ while()
yup sir i know how it works..but i do not know where to place it to me program because it has many methods on it
Re: help java prog. adding do{ while()
Quote:
Originally Posted by
darking123
yup sir i know how it works..but i do not know where to place it to me program because it has many methods on it
You would place it where you want it... I don't know how else to say it...
First you have a problem to be solved by a computer program.
Second you decide how a program can solve the problem.
Third you write code to perform the actions described in the solution.
Where the solution says: "Do this thing while this condition" ... that is where it goes. All of the code to "do this" goes inside the loop.
Tell ya what, why don't you just give it a try. Throw it in there where it looks good and see what it does. If it does not work we will help you figure out why.
Sorry but no one is just going to give you the solution in code. (..and if they do it will be deleted)
You just have to work through the problem solving process, trial and error, which will pay off the great rewards of experience and learning as you go.