NEED HOMEWORK HELP!

Space Weight ConversioN!

Page 1 of 1

7 Replies - 756 Views - Last Post: 15 January 2010 - 11:49 AM Rate Topic: -----

#1 Celesteon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 12-January 10

NEED HOMEWORK HELP!

Post icon  Posted 15 January 2010 - 08:31 AM

Hey, me again - with the same problem!!!
I actually hate this. I'm sooooo bad at Java. XD Anyway, here's my code so far. We had to use two files - so I'll give file 1 first, then file 2.

FILE 1
public class SpaceWeights
{
	private double weight;
	final private double Mercury = 0.378;
	final private double Venus = 0.907;
	final private double Earth = 1.000;
	final private double Mars = 0.377;
	final private double Jupiter = 2.360;
	final private double Saturn = 0.916;
	final private double Uranus = 0.899;
	final private double Neptune = 1.120;
	final private double Pluto = 0.059;
	final private double Moon = 0.166;
	
	private double conversion;
	public SpaceWeights()
	{
		weight=0;
		conversion=0;
	}
	
	public void changeweight (double inputweight)
	{
		weight=inputweight;
	}
	public double convToMercury()
	{
		conversion=weight*Mercury;
		return(conversion);
	}
	public double convToVenus()
	{
		conversion=weight*Venus;
		return(conversion);
	}
	public double convToEarth()
	{
		conversion=weight*Earth;
		return(conversion);
	}
	public double convToMars()
	{
		conversion=weight*Mars;
		return(conversion);
	}	
	public double convToJupiter()
	{
		conversion=weight*Jupiter;
		return(conversion);
	}
	public double convToSaturn()
	{
		conversion=weight*Saturn;
		return(conversion);
	}	
	public double convToUranus()
	{
		conversion=weight*Uranus;
		return(conversion);
	}
	public double convToNeptune()
	{
		conversion=weight*Neptune;
		return(conversion);
	}
	public double convToPluto()
	{
		conversion=weight*Pluto;
		return(conversion);
	}
	public double convToMoon()
	{
		conversion=weight*Moon;
		return(conversion);
	}
}



FILE 2
import java.util.Scanner;
public class weightTester
{
	public static void main (String Args[])
	{
		double yourweight;
		double convweight;
		Scanner in = new Scanner(system.in);
		System.out.printf("Please Enter Your Weight on Earth (lbs): %f\n");
		yourweight=in.nextDouble();
		SpaceWeights newweight=new 
		SpaceWeights(yourweight);
		
		convweight=newweight.convToMercury();
		System.out.printf("Your weight on Mercury is: %f\n", convweight);
		
		convweight=newweight.convToVenus();
		System.out.printf("Your weight on Venus is: %f\n", convweight);
		
		convweight=newweight.convToEarth();
		System.out.printf("Your weight on Earth is: %f\n", convweight);
		
		convweight=newweight.convToMars();
		System.out.printf("Your weight on Mars is: %f\n", convweight);
		
		convweight=newweight.convToJupiter();
		System.out.printf("Your weight on Jupiter is: %f\n", convweight);
		
		convweight=newweight.convToSaturn();
		System.out.printf("Your weight on Saturn is: %f\n", convweight);
		
		convweight=newweight.convToUranus();
		System.out.printf("Your weight on Uranus is: %f\n", convweight);
		
		convweight=newweight.convToNeptune();
		System.out.printf("Your weight on Neptune is: %f\n", convweight);
		
		convweight=newweight.convToPluto();
		System.out.printf("Your weight on Pluto is: %f\n", convweight);
		
		convweight=newweight.convToMoon();
		System.out.printf("Your weight on the Moon is: %f\n", convweight);
		
	}
}



On file 2 - I continue to get the errors for:

line 8
Scanner in = new Scanner(system.in);
- Error = cannot find symbol variable system

line 11
SpaceWeights newweight=new 
- Error = cannot find symbol constructor SpaceWeights(double)


Also, I need help figuring out how to format. Please help me!!! D:

Thanks! Also - for all those who posted on the last topic I made, positive feedback/'this post was helpful' messages coming soon - I just haven't had time to work on that....XD

Is This A Good Question/Topic? 0
  • +

Replies To: NEED HOMEWORK HELP!

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10183
  • View blog
  • Posts: 37,596
  • Joined: 27-December 08

Re: NEED HOMEWORK HELP!

Posted 15 January 2010 - 08:38 AM

For your first error, you need to capitalize system so that it reads new Scanner(System.in);. For your second error, you are trying to use a constructor method in your SpaceWeights class that accepts a double as a parameter. However, no such constructor is defined in your SpaceWeights class. Remember, a method cannot be used if it isn't defined.
Was This Post Helpful? 0
  • +
  • -

#3 dorknexus  Icon User is offline

  • or something bad...real bad.
  • member icon

Reputation: 1255
  • View blog
  • Posts: 4,618
  • Joined: 02-May 04

Re: NEED HOMEWORK HELP!

Posted 15 January 2010 - 08:39 AM

for this line
Scanner in = new Scanner(system.in);

system must be capitalized to read System.

for this line
SpaceWeights newweight=new


You can't just use the keyword without a constructor so you have to say something like

SpaceWeights newweight = new SpaceWeights();

Was This Post Helpful? 0
  • +
  • -

#4 joneSi  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 21-August 08

Re: NEED HOMEWORK HELP!

Posted 15 January 2010 - 08:44 AM

Well, for your first problem, Java is case sensitive. I'd look at the right hand side of the '=' as where your error is.

The second problem may be related to the first. I'd fix the error with the scanner first, then see if it works.

j

EDIT:

View PostDark_Nexus, on 15 Jan, 2010 - 07:39 AM, said:

for this line
Scanner in = new Scanner(system.in);

system must be capitalized to read System.

for this line
SpaceWeights newweight=new


You can't just use the keyword without a constructor so you have to say something like

SpaceWeights newweight = new SpaceWeights();



D'oh, you beat me to it. BTW, if you read his code with SpaceWeights newweight...it does continue on the next line. I was thinking that it may have gotten formatted that way when he posted, but in my IDE (eclipse) that works fine.

j

This post has been edited by joneSi: 15 January 2010 - 08:45 AM

Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10183
  • View blog
  • Posts: 37,596
  • Joined: 27-December 08

Re: NEED HOMEWORK HELP!

Posted 15 January 2010 - 08:48 AM

View PostCelesteon, on 15 Jan, 2010 - 11:31 AM, said:

SpaceWeights newweight=new 
SpaceWeights(yourweight);



His call to the constructor was on a separate line.
Was This Post Helpful? 0
  • +
  • -

#6 Simple_Condolences  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 138
  • Joined: 10-January 10

Re: NEED HOMEWORK HELP!

Posted 15 January 2010 - 11:35 AM

View PostCelesteon, on 15 Jan, 2010 - 07:31 AM, said:

Also, I need help figuring out how to format. Please help me!!! D:

Thanks! Also - for all those who posted on the last topic I made, positive feedback/'this post was helpful' messages coming soon - I just haven't had time to work on that....XD


here is a link to the number formatting in Java:
http://www.tech-reci...-custom-output/

Its pretty easy to do. Just make sure you import java.text.*; to save you a headache!

The formatter should look something like this though...
DecimalFormat fmt = new DecimalFormat(##.###+"lbs");

//then to use it, use what ever you have your converted weight double set to...

System.out.println("Weight on"+planet+": "+fmt.format(convWeight));


Should be something like this... someone correct me if I'm wrong. Thanks! As I said though, read the tutorial first so that the code will stick in your head and you won't have to look it up again. Good luck!


And you're welcome for the help earlier. Why does the assignment require multiple classes? Overall, that just results in more code, passing variable, and a better chance for errors whereas you could just do what you'd done earlier... just seems like a bit of a waste of time unless the idea is to learn about objects and passing variables/parameters... I'd have just tossed the values into an array... Who knows. Either way, hope this helped!

EDIT: Also, when you post your threads, be sure to make the title of your thread relate to your problem. Like, "Number Formatting and NullPointerException" so that people who are having issues like yours can search the site and find this thread for help! Just a thought.

- Zach

This post has been edited by Simple_Condolences: 15 January 2010 - 11:48 AM

Was This Post Helpful? 0
  • +
  • -

#7 Celesteon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 12-January 10

Re: NEED HOMEWORK HELP!

Posted 15 January 2010 - 11:37 AM

I don't have time to reply to this fully...but for the record - I am a girl. Hahaha!
Was This Post Helpful? 0
  • +
  • -

#8 Simple_Condolences  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 138
  • Joined: 10-January 10

Re: NEED HOMEWORK HELP!

Posted 15 January 2010 - 11:49 AM

Thats fine... estrogen isn't a big deal ya' know... and besides, I'm not sure what being female has anything to do with anything... this a programing site... haha.

EDIT: Nevermind, just saw where someone saw you a his.. haha. I retract above statement. XD

- Zach

This post has been edited by Simple_Condolences: 15 January 2010 - 11:51 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1