Ian Dudek

Greenhorn
+ Follow
since Feb 03, 2006
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ian Dudek

I have been working on this project for a bit now and I had a few questions because I am stumped.

I have it set up as a loop. Every time you would not select a one of the proper numbers it would error out. So what I did was create an error box to appear when you don't select the right one (right below). It won't pop up until after you selected and entered in a number then it it will pop up every time you select something. I think it has something to do with my placing of the code. One of my friends was saying it should break before it loops but if it breaks then the loop stops. Is there a way to have it break then start back in the loop?

"if(choice!=1||choice!=2||choice!=3||choice!=4||choice!=5)
JOptionPane.showMessageDialog(null,"Wrong option entered", " error",
JOptionPane.ERROR_MESSAGE);"

Next every time you choose to select a number it will error out. I have no clue how to fix this problem.







// This program is a loop that will calculate the area of shapes
// Written by Ian Dudek

import javax.swing.JOptionPane;

public class app1{


public static void main(String args[])
{
String first,second;
double choice ;
double radius,width,area, length;

//intialize the string

String value=" ";

value =JOptionPane.showInputDialog("Please chose one of the options:"+"\n" +
"a)Enter 1 to calculate the area of the Circle"+ "\n"+
"b)Enter 2 to calculate the area of the Triangle"+ "\n"+
"c)Enter 3 to calculate the area of the Square"+ "\n"+
"d)Enter 4 to calculate the area of the Rectangle"+"\n"+
"e)Enter 5 to calculate the area of the Cube"+"\n"+
"f)Enter 6 to exit the program");
choice=Double.parseDouble(value);

// while option is not 6 continue

while(choice!=6){



//if selected number calculate the area of circle

if(choice==1){
first = JOptionPane.showInputDialog("Enter the value of radius");
radius = Double.parseDouble(first);
area = Math.PI*radius*radius;
//print out the result
JOptionPane.showMessageDialog(null,"The area of the Circle: "+area,"result",
JOptionPane.INFORMATION_MESSAGE);
}

//If selected number is 2 calculate the area of triangle and prints result

else if(choice==2){
first=JOptionPane.showInputDialog("Enter the value of lenght");
second=JOptionPane.showInputDialog("Enter the value of width");
length = Double.parseDouble(first);
width=Double.parseDouble(second);
area= (width*length)/2;
JOptionPane.showMessageDialog(null,"The area of triangle: "+ area,"result",
JOptionPane.INFORMATION_MESSAGE);
}

//If selected number is 3 calculate the area of square and prints result

else if(choice==3){
first = JOptionPane.showInputDialog("Enter the value of length");
length = Double.parseDouble(first);//ge string into integer
area=length*length;
JOptionPane.showMessageDialog(null,"The area of the square: "+ area," result",
JOptionPane.INFORMATION_MESSAGE);
}

//If selected number is 4 calculate the area of rectangle and prints result

else if(choice==4){
first=JOptionPane.showInputDialog("Enter the value of length");
second=JOptionPane.showInputDialog("Enter the value of width");
length=Double.parseDouble(first);
width=Double.parseDouble(second);
area=width*length;
JOptionPane.showMessageDialog(null,"The area of the rectangle: "+ area,"result",
JOptionPane.INFORMATION_MESSAGE);
}

//If selected number is 5 calculat the area of cube and prints result

else if(choice==5) {
first=JOptionPane.showInputDialog("Enter the value of length");
length=Double.parseDouble(first);
area=6*length;
JOptionPane.showMessageDialog(null,"The area of the cube: "+ area,"result",
JOptionPane.INFORMATION_MESSAGE);
}

value =JOptionPane.showInputDialog("Please chose one of the options:"+"\n" +
"a)Enter 1 to calculate the area of the Circle"+ "\n"+
"b)Enter 2 to calculate the area of the Triangle"+ "\n"+
"c)Enter 3 to calculate the area of the Square"+ "\n"+
"d)Enter 4 to calculate the area of the Rectangle"+"\n"+
"e)Enter 5 to calculate the area of the Cube"+"\n"+
"f)Enter 6 to exit the program");

choice=Double.parseDouble(value);


// If choice is not 1-5 a error message will pop up with an error

if(choice!=1||choice!=2||choice!=3||choice!=4||choice!=5)
JOptionPane.showMessageDialog(null,"Wrong option entered", " error",
JOptionPane.ERROR_MESSAGE);


//end of while loop if number selected is 6

}
System.out.println("Program terminated\n");
System.exit(0);
}
}
15 years ago
I have been working on the project for days and I am stuck. I have been trying to clear up problems in each section before going on to the next one but it has not been working too well. I am just so lost I don't even know where to start anymore. I did get down the errors to just 15 but each time I try to change something I get more errors so thats why I am asking for help.

AHH X()
Ian





EDIT by mw: Added Code Tags to original poster's indentation.
[ March 30, 2006: Message edited by: marc weber ]
16 years ago
Crap I am still not getting this section... I could still use some more help.
16 years ago
Well I was messing around with it more and I am getting an error message now that says can not resolve symbol where I have return larger;. Dam I thought I had it there.

Ian

public class Lab13C {
public static void main(String[] args) {
System.out.println("Larger number: " + Calc.larger(7, 3.5));
}
}
class Calc {
public static double larger(double p1,double p2) {
if (p1 > p2) {
System.out.println("1 - the first parameter has the larger value");
}
if (p1 < p2) {
System.out.println("2 - the second parameter has the larger value");
}
else {
System.out.println("0 - the parameters have equal values");
return larger;
}
}
}
[ February 22, 2006: Message edited by: Ian Dudek ]
16 years ago
Well I have been working on loops and I need to count down from 50 to 0 but by counting down by 5s. So 50 45 40 ect. Now I have to use continue or break in this program. I have been fooling around with it but still have no clue on how to have it only display 50 45 40 ect.

This is what I have so far
public class Lab12B {
public static void main(String[] args) {
for (int num = 50; num >= 0; num--) {
if (num == 0)
continue;
else

System.out.println(num);
}
System.out.println("DONE");
}
}

I keep on wanting to put in num%5 ==0 but all that does is skip every 5.

Well as always thanks in advance
Ian
16 years ago
public class Lab10A {
public static void main(String[] args) {
int total = 0;
for (int n = 1; n <= 5; n++) {
total += n;
}
System.out.println("The sum of the digits 1 to 5 is " + total);
}
}

Wow thanks a ton. If I can get it to compile than I can do some trial and error but I just could not do that this time.

Thanks again
Ian
16 years ago
public class Lab10A {
public static void main(String[] args) {
int n = 0;
for (int n = 1; n <= 15; n ++) {
total += n;
}
System.out.println("The sum of the digits 1 to 5 is " + total);
}
}

now it says n is already defined. Maybe there is a problem with
for (int n = 1; n <= 15; n ++).
16 years ago
"What the compiler is trying to tell you is -- you never declared the variable "total". You need to tell the compiler what kind of variable it is -- and to initialize it."


So... hmm I am just really confused on what to write in there. I can only work in the blanks. So do I need to write something like I have no idea.
public class Lab10A {
public static void main(String[] args) {
int n = 0;
for (n = 1; n <= 15; n ++) {
total += n;
}
System.out.println("The sum of the digits 1 to 5 is " + total);
}
}
Maybe n <=5. But this is not going to solve the problem with totals err this is driving me nuts.

I have been looking over all the examples and from what I see I cant find an example on what to write in there. All the examples that he gave to the class has not been helping with this problem.
16 years ago
In my class we have been learning about loops. The problem is I have to fill-in the blanks to make this program display the sum of the integers 1 through 5.

public class Lab10A {
public static void main(String[] args) {
int ________________;
for (________________________________) {
total += n;
}
System.out.println("The sum of the digits 1 to 5 is " + total);
}
}

Now this is what I was working on

public class Lab10A {
public static void main(String[] args) {
int n = 0;
for (n = 1; n <= 15; n ++) {
total += n;
}
System.out.println("The sum of the digits 1 to 5 is " + total);
}
}

This is just after many tries. So I asked the teacher and he told me I need a "broad scope" because you will add to its value inside the loop and display its value after the loop ends(which I have no idea what he means by that). I can't figure out what "broad scope" is.

The problem still wont compile and keeps telling me there is a problem with (total on java line 5 and 7) and how it cannot resolve symbol.

Well I have been working on this program for like 3 hours and its been driving me nuts.

Thanks in advance
16 years ago