Friday 15 June 2012

Error in Java Constructors (cannot find the symbol) -



Error in Java Constructors (cannot find the symbol) -

i created class named invoice holds invoice number, balance due, , 3 fields representing month, day, , year when balance due. create constructor accepts values 5 info fields. within constructor, assign each argument appropriate field next exceptions:

if invoice number less 1000, forcefulness invoice number 0.

if month field less 1 or greater 12, forcefulness month field 0.

if day field less 1 or greater 31, forcefulness day field 0.

if year field less 2011 or greater 2017, forcefulness year field 0.

in invoice class, include display method displays fields on invoice object.

import java.util.scanner; public class invoice { private int innum; private double baldue; private int m; private int d; private int yy; public void setinnum(int inv) { innum = inv; if(inv < 1000) inv = 0; } public int getinnum() { homecoming innum() } public void setbaldue(double bal) { baldue = bal; } public double getbaldue() { homecoming baldue() } public void setm(int month) { m = month; if(month < 1 || month >12) month = 0; } public int getm() { homecoming m() } public void setd(int days) { d = days; if(days < 1 || days > 31) days = 0; } public int getd() { homecoming d() } public void setyy(int years) { yy = years; if(years < 2011 || years > 2017) years = 0; } public int getyy() { homecoming yy() } public static void main(string[] args) { double innum; int m, d, yy; scanner keyboard = new scanner(system.in); system.out.print("please type invoice number: "); innum = keyboard.nextdouble(); system.out.print("what month balance due?(choose 1-12) "); m = keyboard.nextint(); system.out.print("what day balance due?(choose 1-31) "); d = keyboard.nextint(); system.out.print("what year balance due? (choose 2011-2017) "); yy = keyboard.nextint(); if((innum >= 1000) && (m <= 12 && d <= 31 && yy >= 2011) && yy <= 2017) system.out.print("your invoice number " + innum + " , balance due on " + m + "/" + d + "/" + yy); else if((innum >= 1000) && (m<=12 || m <= 0) && (d <= 31 && yy >= 2011) && yy <= 2017) system.out.println("error! invalid month input."); else system.out.println("error!"); } }

now have logical error, trying forcefulness month output this:

if invoice number less 1000, forcefulness invoice number 0.

if month field less 1 or greater 12, forcefulness month field 0.

if day field less 1 or greater 31, forcefulness day field 0.

if year field less 2011 or greater 2017, forcefulness year field 0.

but don't know how can forcefulness fields 0. output when tried run it:

please type invoice number: 999

what month balance due?(choose 1-12) 12

what day balance due?(choose 1-31) 2012

what year balance due? (choose 2011-2017) 12

your invoice number 999.0 , balance due on 12/2012/12

you seek next code issue

public class invoice { private int innum; private double baldue; private int m; private int d; private int yy; public invoice(int innum, double baldue, int m, int d, int yy) { super(); setinnum(innum); setbaldue(baldue); setm(m); setd(d); setyy(yy); } public int getinnum() { homecoming innum; } public void setinnum(int innum) { if(innum < 1000) this.innum = 0; else this.innum = innum; } public double getbaldue() { homecoming baldue; } public void setbaldue(double baldue) { this.baldue = baldue; } public int getm() { homecoming m; } public void setm(int m) { if(m < 1 || m > 12) this.m = 0; else this.m = m; } public int getd() { homecoming d; } public void setd(int d) { if(d < 1 || d > 31) this.d = 0; else this.d = d; } public int getyy() { homecoming yy; } public void setyy(int yy) { if(yy < 2011 || yy > 2017) this.m = 0; else this.yy =yy; } public static void main(string[] args) { invoice invoice = new invoice (100, 3000, 14, 29, 2016); system.out.println(invoice.getinnum() +" "+ invoice.getbaldue() +" "+ invoice.getm() +" "+ invoice.getd() +" "+ invoice.getyy()); } }

java

No comments:

Post a Comment