473,378 Members | 1,384 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,378 software developers and data experts.

Object Oriented counting of classes and summing of totals in created objects

65
Hi All,

Im quite new to java and im a little stuck with something so any help you can provide would be greatly appreciated.

I have 2 classes, a CD class and a CDDriver class.

The CD class has the stored variables and a toString accessor. the CD driver creates 3 instances of a CD object, which holds artist, title and cost.

What i wouldnt like to figure out, and ive spent ages doing it, is to count the number of classes (totalCD's) and sum the total of the cost of each CD.

Id also like to output the most expensive CD object value AND list in order of value (Ascending or Decending, doesnt matter).

Any help would be greatly appreciated. Ive looked through the java stuff, but this is my first brick wall.

Regards

Paul
Expand|Select|Wrap|Line Numbers
  1. public class CD {
  2.  
  3.      private double totalPrice;
  4.      private int totalCDs;
  5.      private String Artist;
  6.      private String Title;
  7.      private double Cost;
  8.  
  9.  
  10.      public CD(String Artist, String Title, double Cost)
  11.     {
  12.         this.Artist = Artist;
  13.         this.Title = Title;
  14.         this.Cost = Cost;
  15.      }
  16.  
  17.  
  18.     public String toString()
  19.     {
  20.         return "CD details: " + Title +" By: " + Artist + "Price:" + Cost;
  21.  
  22.     }
  23.  
  24.  
  25. }
  26.  
Expand|Select|Wrap|Line Numbers
  1. class CDDriver
  2. {
  3.     public static void main(String args[])
  4.     {
  5.  
  6.                 CD cd1 = new CD("Kaiser "," up the khazi ",(double) 9.99);
  7.         CD cd2 = new CD("Oasis "," morning glory ",(double) 3.99);
  8.         CD cd3 = new CD("Bob Dylan "," Alreet Sunna ",(double) 6.99);
  9.  
  10.         System.out.println("Artist \t\tTitle\t\tCost");
  11.         System.out.println("====================================");
  12.         System.out.println(cd1.toString());
  13.         System.out.println(cd2.toString());
  14.         System.out.println(cd3.toString());
  15.  
  16.  
  17.     }
  18. }
Oct 5 '09 #1
2 1346
r035198x
13,262 8TB
Please don't start many threads for the same topic. I'm closing this one now.
Oct 6 '09 #2
Frinavale
9,735 Expert Mod 8TB
Please refer to your other thread for more help on the issue.


-Frinny
Oct 6 '09 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
2
by: CoolPint | last post by:
Standard exception classes in C++ have what() which returns const char * and they have constructors accepting string. Where is that string created and when is the string destroyed? In the...
100
by: E. Robert Tisdale | last post by:
What is an object? Where did this term come from? Does it have any relation to the objects in "object oriented programming"?
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
3
by: notnorwegian | last post by:
i have some confusion over this. sure a class is basically a classification, like for example an animal or flower. and an object/instance of that class is then for example a cat. an object is...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.