Reading in information

I'm trying to key in some information but i keep gettng a null ret

Page 1 of 1

5 Replies - 542 Views - Last Post: 23 March 2009 - 01:44 PM Rate Topic: -----

#1 grifter8875  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 09-February 09

Reading in information

Posted 23 March 2009 - 12:46 PM

This is what I have so far
public class Paycheck {
//member varible
  private String name;
  private double hourlywage;
  private double hoursworked;
//constructor
  public Paycheck(){
  
  }//end Paycheck

  
  
//methods

//returns name
  public String getName(){
   return name;
  }//end getName()

//returns hourly wage
  public double getHwage(){
  return hourlywage;
  }//end getHwage()

//returns hours worked
  public double getHworked(){
  return hoursworked;
  }//end getHworked
  
//compute wage
  public double computeWage(){
  if (hoursworked <= 40.0)
	return hoursworked*hourlywage;
  else
	return (hourlywage*40.0)+((hoursworked-40.0)*(hourlywage*1.5));
  }//end compute wage
//toString method
  public String toString(){
  return "Name "+name+" Hours worked "+hoursworked+" Rate of pay "+hourlywage+" Amount of Paycheck "+computeWage();
  }//end toString
}//end PayCheck




and this is my test class
import java.util.Scanner;


public class PaycheckTest{
  public static void main (String [] args) {
  //create new paychecka
	Paycheck paychecka = new Paycheck();
	// instantiate a Scanner object  
	Scanner in = new Scanner(System.in);
//add name to paycheck
	System.out.print("Workers Name: ");
	String name = in.next();

//add hourly wage to paycheck
	System.out.print("hourly wage: ");
	double hourlywage = in.nextDouble();

//add hours worked to paycheck
	System.out.print("hours worked: ");
	double hoursworked = in.nextDouble();

//print out worker info
	paychecka.toString();
	System.out.println(paychecka.toString());


  
  }//end main ()
}//end PaycheckTest


i'm pretty sure i'm missing something after String name = in.next();[ but i've allready spent a couple hours on it and can't figure out what. When I run it as is I can key in the info but it the string returns null, 0.0, 0.0
I would apprecaite any pointers someone could give me.

This post has been edited by grifter8875: 23 March 2009 - 01:16 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Reading in information

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Reading in information

Posted 23 March 2009 - 12:53 PM

You alreayd have naother Thread which i have posted in, make you constructor need a string name, double wage, double hoursworked. In the constructor, assign each value. When you are reading it, read in the name, then the wage, then the hoursworked, THEN make paycheck object with those 3 items as a parameter. It is return null, 0.0, 0.0 right now because you dont assign any values to the variables what so ever.
Was This Post Helpful? 0
  • +
  • -

#3 grifter8875  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 09-February 09

Re: Reading in information

Posted 23 March 2009 - 01:22 PM

View PostFuzzyness, on 23 Mar, 2009 - 11:53 AM, said:

You alreayd have naother Thread which i have posted in, make you constructor need a string name, double wage, double hoursworked. In the constructor, assign each value. When you are reading it, read in the name, then the wage, then the hoursworked, THEN make paycheck object with those 3 items as a parameter. It is return null, 0.0, 0.0 right now because you dont assign any values to the variables what so ever.


The problem with that though is I need to read 3 diffrent employees information in from the keyboard. From what my instuctor told me that means he wants us to scan in information in.
Was This Post Helpful? 0
  • +
  • -

#4 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Reading in information

Posted 23 March 2009 - 01:24 PM

make an array list or Employees, then just use a do while loop of getting their info from user input, and add each employee to the array list.
Was This Post Helpful? 0
  • +
  • -

#5 grifter8875  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 09-February 09

Re: Reading in information

Posted 23 March 2009 - 01:36 PM

I'm really new to Java, this is the first class I've ever taken on it so can you elaborate on what you just said.
Was This Post Helpful? 0
  • +
  • -

#6 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Reading in information

Posted 23 March 2009 - 01:44 PM

Thats a lot to explain, you would have to look stuff up at Sun tutorials or ask your teacher for a hint in right direction if its too complicated and you havent learned it yet
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1