java - Print out customer name, id, balance -
i writing java program need:
a method read customer names , id , store them in array. (read sequence of 0 or more lines each containing name , id of 1 customer. instantiate 1 customer
object per line , store each object in array of objects. array need not more 10 elements long. sequence of name
, id
end empty line).
main
import java.util.scanner; public class customertest { public static void main(string[] args) { customer[] customers = new customer[10]; scanner myscanner = new scanner(system.in); int numitem; readcustomer(myscanner, customers); //not sure calling readnameamount(myscanner, customers); ////not sure calling } public static void readcustomer(scanner myscanner, customer[] input) { boolean streamended = false; int numitem = 0; while (!streamended && myscanner.hasnext()) { string name = myscanner.nextline(); string id = myscanner.nextline(); if (name.length() == 0 && id.length() == 0) { streamended = true; } else { input[numitem] = name; //error input[numitem] = id; //error } numitem++; customer customertest = new customer(name, id); } } public static void readnameamount(scanner myscanner, customer[] input) { while (myscanner.hasnext()) { string id = myscanner.nextline(); double amount = myscanner.nextdouble(); int = 0; boolean found = false; while (i <numitem && !found) { //error if (customers[i].equals(id)) { //error changebalance(double value);//error } found = true; i++; } } } public static void print(customer[] input, int numitem) { (int = 0; < numitem; i++) { system.out.println(customers[i].tostring()); //error } } }
can please check if works. dont know whether understood question.and cleared error.
public class customertest { static int numitem = 0; public static void main(string[] args) { customer[] customers = new customer[10]; scanner myscanner = new scanner(system.in); readcustomer(myscanner, customers); //not sure calling readnameamount(myscanner, customers); ////not sure calling } public static void readcustomer(scanner myscanner, customer[] input) { boolean streamended = false; while (!streamended && myscanner.hasnext()) { string name = myscanner.nextline(); string id = myscanner.nextline(); if (name.length() == 0 && id.length() == 0) { streamended = true; } else { input[numitem].getname(); input[numitem].getid(); //error } numitem++; customer customertest = new customer(name, id); } } public static void readnameamount(scanner myscanner, customer[] input) { while (myscanner.hasnext()) { string id = myscanner.nextline(); customer cust = new customer(); double amount = myscanner.nextdouble(); int = 0; boolean found = false; while (i < numitem && !found) { //error if (input[i].equals(id)) { //error cust.changebalance(amount);//error } found = true; i++; } } } public static void print(customer[] input, int numitem) { (int = 0; < numitem; i++) { system.out.println(input[i].tostring()); //error } } }
let me know thoughts.
customer.java
public class customer { private string name; private string id; private double balance; public customer(){ } public customer(string name, string id) { this.name = name; this.id = id; } public string getname() { return name; } public string getid() { return id; } public void changebalance(double value) { balance = balance + value; } public string tostring() { return "name " + name + " id " + id + " balance " + balance; } }
Comments
Post a Comment