/*
* 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)

New Topic/Question
Reply



MultiQuote






|