December 22, 2009 at 12:16 PM
Hi Friend,
Try the following code:
import java.util.*;
public class Computer{
static String name;
static int size;
static int speed;
static String make;
static double price;
static int quantity;
public Computer(String n,int s,int sp,String m,double p,int q){
name=n;
size=s;
speed=sp;
make=m;
price=p;
quantity=q;
}
public String getName(){
return name;
}
public int getSize(){
return size;
}
public int getSpeed(){
return speed;
}
public String getMake(){
return make;
}
public double getPrice(){
return price;
}
public int getQuantity(){
return quantity;
}
public void valid(){
if((price==0)||(price<0)){
System.out.println("Please enter price");
System.exit(0);
}
else if((quantity==0)||(quantity<0)){
System.out.println("Please enter quantity ");
System.exit(0);
}
else{
displayData();
}
}
public void displayData(){
List<Computer> list = new ArrayList<Computer>();
list.add(new Computer(name,size,speed,make,price,quantity));
for (Computer s : list){
System.out.println("Computer Name: "+s.getName()+ "\nRAM Size :"+s.getSize()+"\nProcessor Make: "+s.getMake()+"\nProcessor Speed: "+s.getSpeed()+"\nQuantity: "+s.getQuantity()+"\nTotal Price of Computers: "+s.getPrice());
}
}
public static void main(String[]args){
System.out.println("Enter details");
Scanner input=new Scanner(System.in);
name=input.next();
size=input.nextInt();
speed=input.nextInt();
make=input.next();
price=input.nextDouble();
quantity=input.nextInt();
Computer c=new Computer(name,size,speed,make,price,quantity);
c.valid();
}
}
Thanks
Related Tutorials/Questions & Answers:
creating class and methods - Java Beginnerscreating class and methods Create a
class Computer that stores... of the Computers.
This
class contains following
methods,
- Constructor method... ( ) method that creates array of 4 objects of Computer
class and that takes input
java object class methodsjava object
class methods What are the
methods in Object
class? There are lots of
methods in object
class.
the list of some
methods are as-
clone
equals
wait
finalize
getClass
hashCode
notify
notifyAll
Advertisements
to create a java class and methodsto create a java
class and methods How to create a java
class without using the library
class to represent linked lists of integers and also provide it with
methods that can be used to reverse a list & append two lists.Also
Creating methods in servlets - JSP-ServletCreating methods in servlets I created servlet and jsp file.I Instantiated 3 objects and Defined 2
methods in my servlet, first method should write...;
/**
*
* @author mihael
*/
public
class mlNewServlet3 extends HttpServlet
PHP list class methods
Function get_
class_
methods gives the all
methods names of the given
class.
It takes input as
class name and returns the array of the
methods name
PHP LIst
Class Methods Example
<?php
class myclass{
function aa
Abstract class,Abstract methods and classes or the base
class. Subclasses are derived to implement the
methods inherited from...
Abstract
methods and classes
... is used
with
methods and classes.
Abstract MethodADS_TO_REPLACE_1
Creating Class in JRuby
Creating Class in JRuby
...
that how one can define a
class in JRuby and can define
methods in
class as well
as can call them. This example is a small program that defines a simple
class "
using class and methods - Java Beginnersusing
class and methods Sir,Plz help me to write this below pgm. here is the question:
Assume a table for annual examination results for 10... the following code:
import java.util.*;
public
class Student{
int rollNo
Object Class Methods in JavaWe are going to discus about Object
Class Methods in Java... or indirectly. There are many
methods defined in java.lang.Object
class...(), wait(), etc
Java object
class methods are:-
finalize()
clone()
equals
Getting Methods Information of a class
Getting
Methods Information of a
class
... to retrieve information of all
methods of a
class (that included
in the program... of the getMethods() method in
more detail.
Create an object of
class. Now retrieve all
Writing code with multiple Class Methods and String ArraysWriting code with multiple
Class Methods and String Arrays So what I... input.
It has to have multiple classes so I will have a main
class, and a
class....
That's all I need it to do but I'm getting stuck on what to put in the main
class methodsmethods PrintStream
class has two formatting
methods,what
methodsmethods PrintStream
class has two formatting
methods,what
methodsmethods PrintStream
class has two formatting
methods,what
Creating Volume Bar Using Gauge Class Creating Volume Bar Using Gauge
Class
This example is all about
creating a volume bar using Gauge
class. We are
creating the
object of Gauge
class that contains
Java :Thread MethodsJava :Thread
Methods
This section explains
methods of Thread
class.
Thread
Methods :
Thread
class provides many method to handle different thread... the temporal executing thread object.ADS_TO_REPLACE_4
Some other
methods Call class methods Call
class methods
This Example shows you
how
to call
class method in velocity... through method init().
2: Create object of VelocityContext
Class.
3
creating new file with File class - JSP-Interview Questionscreating new file with File class I have a file uploading concept in my project. For that, while
creating a new file is it necessary to give... of FileOutputStream
class. If we give the path as from the file uploading location will it work
Class, Object and MethodsClass, Object and
Methods
Class : Whatever we can see in this world all
the things are a object...
methods. Constructor is the method which name
is same to the
class Java - Class, Object and Methods in Java Java -
Class, Object and
Methods in Java
... will see how to use the
class, object and it's
methods.
This program uses... of a
class . An object is a software bundle of variables and related
methods Creating Bean Class In JSF using NetBeans Creating Bean
Class In JSF using NetBeans
... illustrates how to create the Bean
Class. This is also called
the Backing Bean
Class. This bean
class is used to store the values of the form
components
String toLowerCase and toUppercase methods example()
methods example:-
String
class provides
methods toUpperCase() and toLowerCase... to
lowercase. We have used these two
methods in this example. user can see how to
use these
methods.
Example:-ADS_TO_REPLACE_1
<?xml
Class techniques. A
class defines
the properties of objects and
methods used... classes. A
class defines the
properties of the objects and the
methods used... together with
its
class.
Now
we will learn, how to define a
class having
methods Java call method from another class;
methods of another
class. For this we have created two java files...
methods inside the
class MainClass, an
object of the CallingMethod
class... to access
the
methods of the
class CallingMethod. With just the object name along
Creating Menu Using Canvas Class Creating Menu Using Canvas
Class
This example shows how to create the menu and call the canvas
class to show
the toggle message. The Toggle message will appear when
Access Static Member Of The Class Through Object that work
without any object of the
class. Static
methods are limited to calling other static
methods in the
class and to using only static variables...
Access Static Member Of The
Class Through Object
class
medals. In this
class, you should also define constructors, and assessor, mutator
methods.
Task 2
MedalTally.java is a
class to model a medal tally, containing... is a
class to represent a country in medal tally. It has an attribute of
country
Class Class, Object and
Methods
... the
class,
object and it's
methods. This program uses the several values...
methods of the special
class. In the above
example the sq is the object of square
classclass Is a
class a subclass of itself
creating a own interceptor - Struts of defining the interceptor
methods in the bean
class.
For more information...
creating a own interceptor
i want to create own interceptor
how i will create and which
class i want implement Hi friend
Using Abstract Class class. This
class must be inherited. Unlike interface the abstract
class may implement some
of the
methods defined in the
class, but in this
class at least one...Using Abstract
Class