hi
this is my assignment. i have coded this program and I am wondering how to fix this error.
i hve three class.
I am stuck as to what to do next and how to fix it
any help would do it supposed to run ten time, doh know why it run that length of time. is there anyway i can fix it.
this is the main
public class Project
{
DecimalFormat df = new DecimalFormat("#.00");
public static void main(String[] args) {
createAccount();
}
public static void createAccount()
{
Scanner input = new Scanner(System.in);
int i=0;
double bal=50.0;
Account[] acc = new Account[10];
Person[] p = new Person[i++];
for(i=0; i<acc.length; i++){
System.out.println("Enter first name");
String fn = input.next();
System.out.println("Enter last name");
String ln = input.next();
System.out.println("Enter address");
String ad = input.next();
System.out.println("Enter telephone number");
String tn = input.next();
//p[i]= new Person(fn, ln, ad, tn);
//acc[i]= new Account(i, 50);
}
while(true)
{
System.out.println("Enter your id");
int id = input.nextInt();
while(id < 0 || id > 9)
{
System.out.println("id is incorect, try again");
id = input.nextInt();
}
while(true)
{
displayMenu();
if(!useMenu(acc[id],input))
{
System.out.println();
break;
}
System.out.println("\n");
}
}
}
public static boolean useMenu(Account acc, Scanner input)
{
int userchoice = input.nextInt();
if(userchoice == 4)
{
return false;
}
else if(userchoice == 1)
{
System.out.println("The account balance is: "+ acc.getbalance());
return true;
}
else if(userchoice == 2)
{
System.out.println("Enter the amount to withdraw");
acc.withdraw(input.nextDouble());
if(acc.withdraw(userchoice)> acc.getbalance())
{
System.out.println("Insufficient amount");
}
else
{
acc.withdraw(userchoice);
}
}
else if(userchoice == 3)
{
System.out.println("Enter the amount to deposit");
acc.deposit(input.nextDouble());
return true;
}
else if(userchoice == 4)
{
acc.toString();
}
else
{
System.out.println("invalid choice");
}
return true;
}
public static void displayMenu()
{
System.out.println("Main Menu");
System.out.println("| [1] Check Balance");
System.out.println("| [2] Withdraw");
System.out.println("| [3] Deposit");
System.out.println("| [4] Display User Information");
System.out.println("| [5] Exist ");
System.out.println("Enter a choice");
}
}
this is the account class
package Project;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author USER
*/
public class Account
{
private int ID;// this is the id variable
private double balance;
private Person owner;
public Account()
{
//no arg constructor
}
//constructor method with
public Account(int ID, double balance, Person owner)
{
this.ID = ID;
this.balance = balance;
this.owner = owner;
}
public int getID()
{
return ID;
}
public double getbalance()
{
return balance;
}
public Person getowner()
{
return owner;
}
public void setID(int ID)
{
this.ID = ID;
}
public void setbalance(double balance)
{
this.balance = balance;
}
public void setowner(Person owner)
{
this.owner = owner;
}
public double deposit(double deposit)
{
balance +=deposit;
return(getbalance()+deposit);
}
public double withdraw(double withdraw)
{
balance -=withdraw;
return (getbalance() - withdraw);
}
public String toString()
{
String details = owner.toString()+"/nID: "+ID+""
+ "\nBalance: "+balance;
return details;
}
}
and this is the Person class
* @author USER
*/
public class Person
{
private String FirstName;
private String LastName;
private String address;
private String telephoneNumber;
public Person(String f,String l,String a, String t){
FirstName=f;
LastName=l;
address=a;
telephoneNumber=t;
}
//get first name
public String getFirstName()
{
return FirstName;
}
//get last name
public String getLastName()
{
return LastName;
}
//get address
public String getaddress()
{
return address;
}
//get telephone number
public String getTelephoneNumber()
{
return telephoneNumber;
}
//accessor method with the person name and with parameters
public void setFirstName(String FirstName)
{
this.FirstName = FirstName;
}
//accessor method with the person last name with parameters
public void setLastName(String LastName)
{
this.LastName = LastName;
}
//accessor method the person address with parameters
public void setaddress(String address)
{
this.address = address;
}
//accessor method that take one parameter
public void setTelephoneNumber(String telephoneNumber)
{
this.telephoneNumber = telephoneNumber;
}
@Override
public String toString()
{
String details = "Name: "+FirstName +" "+ LastName
+"\nAddress: "+address+"\nPhone No: "+telephoneNumber;
return details;
}
}
and this here is the output and the error
Enter first name
javon
Enter last name
smith
Enter address
edr
Enter telephone number
2263363
Enter first name
jane
Enter last name
doe
Enter address
valysan
Enter telephone number
4567893
Enter first name
devon
Enter last name
mathews
Enter address
diegomartin
Enter telephone number
7845663
Enter first name
kaisley
Enter last name
doe
Enter address
belmont
Enter telephone number
4459898
Enter first name
jaime
Enter last name
denn
Enter address
belmont
Enter telephone number
2269897
Enter first name
yohan
Enter last name
small
Enter address
maloney
Enter telephone number
2236965
Enter first name
tiffany
Enter last name
hamil
Enter address
laventille
Enter telephone number
6254784
Enter first name
luana
Enter last name
doe
Enter address
edr
Enter telephone number
6236321
Enter first name
dolly
Enter last name
mohan
Enter address
sanjuan
Enter telephone number
7415202
Enter first name
yohan
Enter last name
john
Enter address
b
Enter telephone number
4479696
Enter your id
3
Main Menu
| [1] Check Balance
| [2] Withdraw
| [3] Deposit
| [4] Display User Information
| [5] Exist
Enter a choice
1
Exception in thread "main" java.lang.NullPointerException
at Project.Project.useMenu(Project.java:80)
at Project.Project.createAccount(Project.java:61)
at Project.Project.main(Project.java:24)
Java Result: 1
BUILD SUCCESSFUL (total time: 4 minutes 1 second)


