import java.util.Scanner;
import java.util.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
public class Account{
private int id;
private String bc;
private String bd;
private String customerName;
private String customerAddress;
private String customerNumber;
private String periodT;
private String periodF;
private double presentR;
private double previousR;
private double previousB;
private double dueTotal;
public Account(int id,String bc,String bd,String customerName,String customerAddress,String customerNumber,String periodT,String periodF,double presentR,double previousR,double previousB,double dueTotal){
this.id = id;
this.bc = bc;
this.bd = bd;
this.customerName = customerName;
this.customerAddress = customerAddress;
this.customerNumber = customerNumber;
this.periodT = periodT;
this.periodF = periodF;
this.presentR = presentR;
this.previousR = previousR;
this.previousB = previousB;
this.dueTotal = dueTotal;
}
public int getId(){
return id;
}
public String getBc(){
return bc;
}
public String getBd(){
return bd;
}
public String getCustomerName(){
return customerName;
}
public String getCustomerAddress(){
return customerAddress;
}
public String getCustomerNumber(){
return customerNumber;
}
public String getPeriodT(){
return periodT;
}
public String getPeriodF(){
return periodF;
}
public double getPresentR(){
return presentR;
}
public double getPreviousR(){
return previousR;
}
public double getPreviousB(){
return previousB;
}
public double getDue(){
return dueTotal;
}
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
Account[] accounts = new Account[50];
int user_choice;
int x = 0;
String temp[] = {" "};
do{
System.out.println();
System.out.println("1) New Billing");
System.out.println("2) Add Existing Billing");
System.out.println("3) View Billing Account ID");
System.out.println("4) View By Date");
System.out.println("5) Update Existing Billing");
System.out.println("6) Delete Billing Account");
System.out.println("7) Display All Account");
System.out.println("8) Exit");
System.out.println();
System.out.print("Enter choice [1-8]: ");
user_choice = scanner.nextInt();
if(user_choice == 1){
int min = 1000;
int max = 9999;
int randomStr = (int)(Math.random() * (max - min + 1) + min);
int id = randomStr;
System.out.println("Your Account Number is : " + id);
System.out.print("Enter Billing Code: ");
String bc = scanner.next();
System.out.print("Enter Billing Date(dd/mm/yyyy): ");
String bd = scanner.next();
System.out.print("Enter Customer Name: ");
String customerName = scanner.next();
System.out.print("Enter Customer Address: ");
String customerAddress = scanner.next();
System.out.print("Enter Customer Number: ");
String customerNumber = scanner.next();
System.out.print("Enter Period To: ");
String periodT = scanner.next();
System.out.print("Enter Period From: ");
String periodF = scanner.next();
System.out.print("Enter Present Reading: ");
double presentR = scanner.nextDouble();
System.out.print("Enter Previous Reading: ");
double previousR = scanner.nextDouble();
System.out.print("Enter Previous Balance: ");
double previousB = scanner.nextDouble();
double dueTotal = getTotalDue(presentR,previousR,previousB);
Account user = new Account(id,bc,bd,customerName,customerAddress,customerNumber,periodT,periodF,presentR,previousR,previousB,dueTotal);
accounts[x] = user;
x++;
}else if(user_choice==2){
System.out.print("Input Account ID: ");
int b = scanner.nextInt();
for(int i=0; i < x;i++)
{
Account user = accounts[x];
if(b == user.getId())
{
}
}
}else if(user_choice==3){
System.out.print("Enter Account Number: ");
int a = scanner.nextInt();
for(int i = 0; i<x;i++){
Account user = accounts[i];
if(a == user.getId())
{
System.out.println("Account ID: " + user.getId());
System.out.println("Customer Name: " + user.getCustomerName());
System.out.println("Customer Address: " + user.getCustomerAddress());
System.out.print("Customer Number: " + user.getCustomerNumber());
}
}
System.out.println("nBilling CodettBilling DatettAmount Due");
for(int i = 0; i<x;i++){
Account user = accounts[i];
if(a == user.getId())
{
System.out.println(user.getBc()+"ttt"+user.getBd()+"ttt"+user.getDue());
}
}
}else if(user_choice == 4 ){
}else if(user_choice == 5 ){
}else if(user_choice == 6){
System.out.print("Enter Account Number to be deleted: ");
int a = scanner.nextInt();
for(int i = 0; i<x;i++){
Account user = accounts[i];
if(a == user.getId())
{
user.remove(i); \this remove part is the one im trying to work on but i cant seem to make this work, i wouldve wanted this one to delete everything underr the same account id including the name and details .
}
}
}else if(user_choice == 7){
System.out.println("Account IDttBilling CodettAccount NamettTotal DuettPresent RttPrevious R");
for(int i=0; i<x;i++){
Account user = accounts[i];
System.out.println(user.getId() + "ttt"+user.getBc()+ "ttt"+user.getCustomerName()+ "ttt"+user.getDue()+"ttt"+user.getPresentR()+ "ttt"+user.getPreviousR());
}
}
}while(user_choice!=8);
}
public static double getTotalDue(double presR,double prevR,double prevB){
double answer = 0;
double gc = 0;
double tc = 0;
double slc = 0;
double dc = 0;
double sc = 0;
double mc = 0;
double totalDue = 0;
answer = presR - prevR;
gc = 4.4397 * answer;
tc = 0.4122 * answer;
slc = 0.7956 * answer;
dc = 1.6902 * answer;
sc = 0.3829 * answer;
mc = 0.5424 * answer;
totalDue = gc + tc + slc + dc + sc + mc + prevB;
return totalDue;
}
}
Я новичок в программировании на Java и практикую биллинговую систему, поскольку в моей программе есть опция, которая позволяет пользователю удалить указанную учетную запись с использованием идентификатора acc. Я пробовал .remove()
Но это не работает. Да, в моем программном коде есть проблемы, которые я изо всех сил пытаюсь понять.