Welcome to Dream.In.Code
Become a Java Expert!

Join 149,522 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,392 people online right now. Registration is fast and FREE... Join Now!




Errors with my code

 
Reply to this topicStart new topic

Errors with my code

sastre06
4 Jul, 2007 - 07:14 AM
Post #1

New D.I.C Head
Group Icon

Joined: 5 Jun, 2007
Posts: 45


Dream Kudos: 50
My Contributions
Hello friends, i have a problems with this one, i don't know if my codes are incorrect or my J2SDK has a problem, I've always receive an error, but i think my codes are correct



import javax.swing.*;
public class grades{
grades(){

int g1=Integer.parseInt(JOptionPane.showInputDialog("Enter grade in Prelim"));
int g2=Integer.parseInt(JOptionPane.showInputDialog("Enter grade in Midterm"));
int g3=Integer.parseInt(JOptionPane.showInputDialog("Enter grade in Prefinal"));
int g4=Integer.parseInt(JOptionPane.showInputDialog("Enter grade in Final"));

int avegrade=(g1+g2+g3+g4*2)/5;

if (avegrade>=95){
JOptionPane.showMessageDialog(null,"A");
}
elseif (avegrade>=90){
JOptionPane.showMessageDialog(null,"B");
}
elseif (avegrade>=85){
JOptionPane.showMessageDialog(null,"C");
}
elseif (avegrade>=80){
JOptionPane.showMessageDialog(null,"D");
}
elseif (avegrade>=75){
JOptionPane.showMessageDialog(null,"E");
}
else{
JOptionPane.showMessageDialog(null,"F");
}

System.exit(0);
}
public static void main(String[] args){
new grades();
}
}




And this is the second one



import javax.swing.*;
public class calling{
calling(){

int time=Integer.parseInt(JOptionPane.messageInputDialog("1 - Day time \n2-Night time"));

double am,aus,eu,as;

switch (time){
case 1:
am=5;
eu=10;
as=10
aus=12.50;
case 2:
am=3.33;
eu=7.50;
as=8.75;
aus=10;
}

int desti=Integer.parseInt(JOptionPane.messageInputDialog("Enter destination\n1-America\n2-Europe\n3-Asia\n4-Australia "));

switch (desti){
case 1: desti=am;
break;
case 2: desti=eu;
break;
case 3: desti=as;
break;
case 4: desti=aus;
break;
}

int mins=Integer.parseInt(JOptionPane.messageInputDialog("Enter duration of calls in minutes"));
double pay=(double)mins*desti;
JOptionPane.messageDialog(null,"Cost of calls"+pay);

System.exit(0);
{

public static void main(String args[]){
new calling();
}
}


Thanks...
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Errors With My Code
4 Jul, 2007 - 08:23 AM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,010



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
hi, in the first program
QUOTE
elseif

is not the way you write it. else if is the right way, with a blank in between them.

in the second program there are more errors.
QUOTE
int time=Integer.parseInt(JOptionPane.messageInputDialog("1 - Day time \n2-Night time"));

shouldn't be
showInputDialog instead *check your first program.
that goes for the rest of the same errors.


here
QUOTE
JOptionPane.messageDialog(null,"Cost of calls"+pay);

= > showMessageDialog

Check the brackets I think there are problems there too.
Yeah and I don't think you can create an object like that in the main.
= > calling obj = new calling();
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:32PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month