4 Replies - 480 Views - Last Post: 20 January 2012 - 09:46 AM Rate Topic: -----

#1 Befigard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-November 11

Do not know what I'm doing wrong...

Posted 19 January 2012 - 10:46 PM

I am a java-greenhorn and I am working on this assignment it is due tomorrow, and I am so lost at the moment. Here is what I have so far...but I do not understand my errors, can someone please help me sort them.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.week7;

/**
 *
 * @author Bert
 */

import gui.week7.WeightCalclator.WeightCalculator;
import java.util.*;
import javax.swing.JOptionPane;

public class GUIWeek7 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        WeightCalclator[] wc = {new WeightCalculator()};
        
        
            int i =1;
            double  d;
            String str;
            Scanner s = new Scanner(System.in);
            
            for(WeightCalclator var:wc){
                d = Double.parseDouble (JOptionPane.showInputDialog("Enter weight of object " +i+" "));
                
                str=JOptionPane.showInputDialog("Enter the description of the object" +i+ " ");
                i++;
                var.setWeight(d);
                var.setDescription(str);
            }
                i=1;
                for(WeightCalclator var:wc){
                    
                    JOptionPane.showMessageDialog(null,"The description of the object is: " +var.getDescription()
                            +"\n The Weight of the object " +i+ "on Earth is: " +var.earthWeight(),JOptionPane.PLAIN_MESSAGE
                            +"\n The weight of the object " +i+ "on Mercury is:" +var.MercuryWeight(),JOptionPane.PLAIN_MESSAGE
                            +"n\ The weight of the object" +i+ "on Jupiter is:" +var.JupiterWeight(),JOptionPane.PLAIN_MESSAGE
                            +"n\ The weight of the object" +i+ "on the Moon is:" +var.MoonWeight(),JOptionPane.PLAIN_MESSAGE;                  
                            
   }}}

package gui.week7;

/**
 *
 * @author Bert
 */
class WeightCalclator {

    void setWeight(double d) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    void setDescription(String str) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    String getDescription() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    String earthWeight() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    String MercuryWeight() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public WeightCalclator() {
    }

    String JupiterWeight() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    String MoonWeight() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public class  WeightCalculator {
        private static final long serialVersionUID = 1L;

        private double weight = 0.0;
        private String description = null;

        public double earthWeight() {
            return weight;
        }

        public double mercuryWeight() {
            return weight * .378;
        }

        public double moonWeight() {
            return weight * .166;
        }

        public double jupiterWeight() {
            return weight * 2.364;
        }

        public String getDescription() {
            return description;
        }

        public void setWeight(double weight) {
            this.weight = weight;
        }

        public void setDescription(String description) {
            this.description = description;
        }
    }
}



These are the errors I'm getting:

C:\Users\Bert\Documents\NetBeansProjects\GUI Week7\src\gui\week7\GUIWeek7.java:44: error: illegal escape character
+"n\ The weight of the object" +i+ "on Jupiter is:" +var.JupiterWeight(),JOptionPane.PLAIN_MESSAGE
C:\Users\Bert\Documents\NetBeansProjects\GUI Week7\src\gui\week7\GUIWeek7.java:45: error: illegal escape character
+"n\ The weight of the object" +i+ "on the Moon is:" +var.MoonWeight(),JOptionPane.PLAIN_MESSAGE;
C:\Users\Bert\Documents\NetBeansProjects\GUI Week7\src\gui\week7\GUIWeek7.java:45: error: ')' expected
+"n\ The weight of the object" +i+ "on the Moon is:" +var.MoonWeight(),JOptionPane.PLAIN_MESSAGE;
C:\Users\Bert\Documents\NetBeansProjects\GUI Week7\src\gui\week7\GUIWeek7.java:49: error: class, interface, or enum expected
package gui.week7;
4 errors
C:\Users\Bert\Documents\NetBeansProjects\GUI Week7\nbproject\build-impl.xml:603: The following error occurred while executing this line:
C:\Users\Bert\Documents\NetBeansProjects\GUI Week7\nbproject\build-impl.xml:245: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)

Is This A Good Question/Topic? 0
  • +

Replies To: Do not know what I'm doing wrong...

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Do not know what I'm doing wrong...

Posted 19 January 2012 - 10:58 PM

* Moved to the Java forum *
Was This Post Helpful? 0
  • +
  • -

#3 cfoley  Icon User is online

  • Cabbage
  • member icon

Reputation: 2066
  • View blog
  • Posts: 4,297
  • Joined: 11-December 07

Re: Do not know what I'm doing wrong...

Posted 20 January 2012 - 04:12 AM

Newline is \n not n\

The way you have it on lines 44 and 45 is causing you problems, which is what the first couple of error messages are trying to tell you.

When debugging Java, look at the first error message and fix that problem. The ones that follow are often knock-on effects which might go away after the original syntax error is fixed.
Was This Post Helpful? 0
  • +
  • -

#4 civicdude95  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 40
  • Joined: 18-January 12

Re: Do not know what I'm doing wrong...

Posted 20 January 2012 - 07:27 AM

Also, line 45 needs a ')' right before the semicolon and line 49 is not needed since you already have that line of code on line 5.
Was This Post Helpful? 0
  • +
  • -

#5 Befigard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-November 11

Re: Do not know what I'm doing wrong...

Posted 20 January 2012 - 09:46 AM

Thanks everyone, will try and fix from everyone's advise. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1