Im having trouble getting the input from one file to another.
Main file:
[CODE=java]package assigment3;
/**
*
* @author mguer017
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
}
public static void main(String[] args) {
Cashier c = new Cashier();
c.add ("Bread", 2.99); //adds string and double
c.add ("Chicken", 6.79); // adds string and double
c.add ("Egg", 3.07); // adds string and double
c.average(); // calculate the average price
c.tendered(20); // Twenty dollars were tendered
System.out.prin tln(c); // print Cashier()
}
}
[/CODE]
Cashier file: (Calculations file)
[CODE=java]package assigment3;
/**
*
* @author mguer017
*/
public class Cashier {
/* Working on it
private static final double DOLLAR = 1.00;
private static final double QUARTER = 0.25;
private static final double DIME = 0.10;
private static final double NICKEL = 0.05;
private static final double PENNY = 0.01;
*/
private String Item;
private int Total_Items, Tendered;
private double Price, average, Total;
/** Creates a new instance of Cashier */
public Cashier() {
System.out.prin tln(getItem() + " ......... $" + getPrice() + "\n" + "----------" + "\n" + getTotal());
System.out.prin tln("Amount tendered: $" + getTendered());
System.out.prin tln("The change is: $" + getChange());
System.out.prin tln("There were " + getTotal_Items( ) + " items");
System.out.prin tln("Average price is: $" + average);
System.out.prin tln("Your change: $" + getChange());
}
public void add(String It, double Prc) {
this.Item = It;
this.Price = Prc;
}
public void tendered(int Amount) {
Tendered = Amount;
}
public double average() {
return average = Total_Items / Total;
}
public String getItem() {
return Item;
}
public double getPrice() {
return Price;
}
public double getTotal() {
return Total = Total + Price;
}
public double getTendered() {
return Tendered;
}
public int getTotal_Items( ) {
return Total_Items;
}
public double getChange() {
return Tendered - Total;
}
}
[/CODE]
The output comes with 0's and null on the strings.
Any idea what I am doing wrong?
The assignment gave me the code of the main file, so I only need to mess with the Cashier file.
Thanks,
Miguel Guerin
Main file:
[CODE=java]package assigment3;
/**
*
* @author mguer017
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
}
public static void main(String[] args) {
Cashier c = new Cashier();
c.add ("Bread", 2.99); //adds string and double
c.add ("Chicken", 6.79); // adds string and double
c.add ("Egg", 3.07); // adds string and double
c.average(); // calculate the average price
c.tendered(20); // Twenty dollars were tendered
System.out.prin tln(c); // print Cashier()
}
}
[/CODE]
Cashier file: (Calculations file)
[CODE=java]package assigment3;
/**
*
* @author mguer017
*/
public class Cashier {
/* Working on it
private static final double DOLLAR = 1.00;
private static final double QUARTER = 0.25;
private static final double DIME = 0.10;
private static final double NICKEL = 0.05;
private static final double PENNY = 0.01;
*/
private String Item;
private int Total_Items, Tendered;
private double Price, average, Total;
/** Creates a new instance of Cashier */
public Cashier() {
System.out.prin tln(getItem() + " ......... $" + getPrice() + "\n" + "----------" + "\n" + getTotal());
System.out.prin tln("Amount tendered: $" + getTendered());
System.out.prin tln("The change is: $" + getChange());
System.out.prin tln("There were " + getTotal_Items( ) + " items");
System.out.prin tln("Average price is: $" + average);
System.out.prin tln("Your change: $" + getChange());
}
public void add(String It, double Prc) {
this.Item = It;
this.Price = Prc;
}
public void tendered(int Amount) {
Tendered = Amount;
}
public double average() {
return average = Total_Items / Total;
}
public String getItem() {
return Item;
}
public double getPrice() {
return Price;
}
public double getTotal() {
return Total = Total + Price;
}
public double getTendered() {
return Tendered;
}
public int getTotal_Items( ) {
return Total_Items;
}
public double getChange() {
return Tendered - Total;
}
}
[/CODE]
The output comes with 0's and null on the strings.
Code:
null ......... $0.0 ---------- 0.0 Amount tendered: $0.0 The change is: $0.0 There were 0 items Average price is: $0.0 Your change: $0.0
The assignment gave me the code of the main file, so I only need to mess with the Cashier file.
Thanks,
Miguel Guerin
Comment