473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to add a print account(name, ID, Balance) to the end of the account's array?

1
Hi,
I'am quite new in java and desperatly need help.
I am trying to implement a studen't print quota.

Printquotaclass:

Expand|Select|Wrap|Line Numbers
  1. public class printQuota{
  2.  
  3. private  String studentName;
  4. private  int studentId;
  5. private  int studentBalance;
  6. private static  int unitCost = 2;//unit cost is 2 roubles
  7.  
  8. //********************************************************
  9. //                   Consttructor   sets standard print acc                                 
  10. //********************************************************
  11. public printQuota(String student, int id, int initialBalance)
  12. {
  13.  
  14.   studentName = student;
  15.   studentId = id;
  16.   studentBalance= initialBalance;
  17. }
  18.  
  19.  
  20.  
  21. //-----------------------------------------------------------------
  22. //  Returns the current unit cost.
  23. //-----------------------------------------------------------------
  24.    public static int getCurrentUnitCost ()
  25.    {
  26.       return unitCost;
  27.    }
  28.  
  29.  public static int setCurrentUnitCost()
  30.  {
  31.    return unitCost;
  32.  }
  33.  
  34.  //****************************
  35.  //Increasing Balence
  36.  //*************************
  37.  
  38.  public int increaseBalance(int amount)
  39.  {
  40.    studentBalance = studentBalance + amount * unitCost;
  41.    return studentBalance;
  42.  }
  43.  
  44.  //****************************
  45.  //Printing
  46.  //*************************
  47.  
  48.  public int print(int amount)
  49.  {
  50.    int studentBalence = studentBalance-(amount * unitCost);
  51.  return studentBalence;
  52.  }
  53. //-----------------------------------------------------------------
  54. //  Returns a one-line description of the account as a string.
  55. //-----------------------------------------------------------------
  56.  public String toString()
  57.    {
  58.    return " " + studentName + "\t" + studentId + "\t" + studentBalance; 
  59.  
  60.    }
  61.  
  62. }
  63.  
I want to implement methodes that add printquota object to an array of size 8.

I started the following
[code]import java.util.Scanner
public class printQuotaSystem{
int numaccount = 8;
printQuota[] accounts;
accounts = new printQuota[10]; // allocates memory for 10 account
accounts[0] = new printQuota("jules", 123, 200);
accounts[1] = new printQuota("Dules", 456, 200);
accounts[2] = new printQuota("Gules", 789, 200);
accounts[3] = new printQuota("Hules", 987, 200);
accounts[4] = new printQuota("Bules", 654, 200);
accounts[5] = new printQuota("Eules", 023, 200);
accounts[6] = new printQuota(NULL, 0, 0);
accounts[7] = new printQuota(NULL,0 , 0);

public class addPrintQuota
{
Scanner sc =new Scanner(System.in);
System.out.println("please enter your name");
studentName sc.nextLine();
Scanner sc =new Scanner(System.in)
System.out.println("please enter student ID");
studentName sc.nextInt();
System.out.println("Enter amount of roubles for quot");
for(i=0; i<account.length; i++)
{
if (accounts[i] == NULL)
{


[\code]
my question are:
how to implement the quotaSytem class so that
it add printQuota object to the array?

Thanks
Feb 25 '11 #1
0 1143

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Randell D. | last post by:
I have a script (below) that can be passed an array and it will dump the contents of the array in to an html table - I use it during development so its nothing sexy. It handles multidimsional...
6
by: Gustaf Liljegren | last post by:
I ran into this problem today: I got an array with Account objects. I need to iterate through this array to supplement the accounts in the array with more data. But the compiler complains when I...
6
by: Moses M | last post by:
I posted this a short while ago , but I don't think I explained the problem clearly. Task Manager lists processes running on a local system, including a "user name" associated with each process...
12
by: Peter Lin | last post by:
Hey, I am just wondering if anyone has got any idea of setting up a new class so that you could just print like the old ways with the printer class, since I am writing a program that really...
13
by: lovecreatesbeauty | last post by:
/* How do free() know how many elements should be freed in a dynamic array? When free a single variable, the amount of byte of memory can be retrieved from the type of variable itself. ...
2
by: lovecreatesbeauty | last post by:
/* How does free() know how many elements should be freed in a dynamic array? When it frees a single variable, the size information about amount of byte of memory can be retrieved from the...
1
by: Steff | last post by:
I am wandering if my code is making sense... I use a lot the print function. Is it weird in this case where I have to display an array ? I thought it would be better to have the entire array in php...
44
by: svata | last post by:
Hello, I wonder how to resize such array of structures using realloc()? #include <stdio.h> #include <stdlib.h> #define FIRST 7 typedef struct { char *name;
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
6
by: sathyashrayan | last post by:
Dear Group, Please look at the following demo link. http://www.itsravi.com/demo/new_pms/admin/addproject.php
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.