Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners computer configuration

Have Programming Question? Ask it here!
 
 
 


RAJWINDER
computer configuration
1 Answer(s)      4 years and 4 months ago
Posted in : Java Beginners


someone posted a code but tha is not working and i am totaly new to java and i hae to submit my project
kindly help and send a working code


Create a class Computer that stores information about different types of Computers
available with the dealer. The information to be stored about a single computer is,
- Company Name
- RAM size.
- Hard Disk Capacity.
- Processor Speed.
- Processor Make.
- Price .
- Quantity of the Computers.

This class contains following methods,
- Constructor method that assigns user input values to above
mentioned variables.

- main ( ) method that creates array of 4 objects of Computer
class and that takes input for all above details from the user and
calls method to check validity of Quantity and Price values.
If all values are valid then create the objects and display the details
for all 4 toys.

- Method that checks validity of quantity and price.
If the quantity is 0 or negative then method should throw user defined
exception with appropriate message and come out of program.
Similarly if the price is 0 or negative then it should throw user defined
exception with appropriate message and come out of program.

- Method that displays all details about a single instance of Computer in the
following
Format.

Computer Name : IBM
RAM Size : 512 MB
Processor Make : Intel
Processor speed : 300
Quantity : 50
Total Price of Computers : 150,0000/-
*/

Advertisement
View Answers

April 27, 2010 at 11:50 AM


Hi Friend,

Try the following code:

import java.util.*;
import java.text.*;

public class Computer{
String name;
int size;
int speed;
String make;
double price;
double quantity;

DecimalFormat f = new DecimalFormat("##,###");
public Computer(String n,int s,int sp,String m,double p,double q){
this.name=n;
this.size=s;
this.speed=sp;
this.make=m;
this.price=p;
this.quantity=q;
}
public void valid(){
if((price==0)||(price<0)){
System.out.println("Please enter valid price");
System.exit(0);
}
else if((quantity==0)||(quantity<0)){
System.out.println("Please enter valid quantity ");
System.exit(0);
}
else{
displayData();
}
}
public void displayData(){
StringBuffer buff = new StringBuffer();
buff.append("Computer Name : "+name);
buff.append("\nRAM Size : "+size);
buff.append("\nProcessor Make : "+make);
buff.append("\nProcessor speed : "+speed);
buff.append("\nQuantity : "+quantity);
buff.append("\nTotal Price of Computers : "+f.format(quantity * price));
buff.append("\n");
System.out.println(buff.toString());
}
public static void main(String[]args){
String name;
int size;
int speed;
String make;
double price;
double quantity;
System.out.println("Enter details");
Computer data[]=new Computer[2];
Scanner input=new Scanner(System.in);
for(int i=0;i<2;i++){
System.out.print("Computer Name: ");
name=input.next();
System.out.print("RAM Size: ");
size=input.nextInt();
System.out.print("Processor Speed: ");
speed=input.nextInt();
System.out.print("Processor Make: ");
make=input.next();
System.out.print("nQuantity: ");
quantity=input.nextDouble();
System.out.print("Price: ");
price=input.nextDouble();
Computer c=new Computer(name,size,speed,make,price,quantity);
data[i]=c;
System.out.println("\n*************************************");
}
for(int i=0;i<2;i++){
data[i].valid();
}
}
}

Hope that it will be helpful for you.
Thanks


Related Tutorials/Questions & Answers:
computer configuration - Java Beginners
computer configuration  someone posted a code but tha is not working... a working code Create a class Computer that stores information about... about a single computer is, - Company Name - RAM size. - Hard Disk Capacity
Advertisements
Computer Networks
Computer Networks  The IPV4 packet has arrived wtih first few hexadecimal digits as 0X45000028000100000102. How many hopes will this packet travel before being dropped
invalid configuration
configuration Exception in thread "main" java.lang.ExceptionInInitializerError... configuration at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2241
computer science
computer science  Objective:Work with hash tables by creating a hash table using linear probing. I need this code in java. "LinearProbingHashTable.java" Description:Create a generic class called LinearProbingHashTable<K,V>
Computer Networking
Computer Networking   ... a commercial activity where you were using a computer along with a printer... the sharing and exchanging facilities among the computer machines is called
MySQL Configuration
MySQL Configuration      ... . The mysql configuration is included with The mysql 5.0 server and mysql also available for only window users. Introduction of configuration wizard The MySQL
Configure the configuration file
Configure the configuration file  How do I configure the configuration file
configuration files are used in Struts
configuration files are used in Struts  What configuration files are used in Struts
Computer Terminology Bug
Computer Terminology Bug  What is mean by bug in computer terminology
basic function of computer system
basic function of computer system  What is the basic function of computer system
Computer Terminology Bug
Computer Terminology Bug  What is mean by bug in computer terminology
Define computer software.
Define computer software.  How to define a computer software?   A computer software is a set of instruction that tell the computer what to do
Computer forensic application
Computer forensic application  how to write computer forensic application using java for recovering deleted files and deleted partitions
Action Configuration - Struts
Action Configuration  I need a code for struts action configuration in XML
Form Tag library configuration
In this section, you will learn about Spring form tag library and its configuration
Computer shop mangerment
Computer shop mangerment   Part A You are supposed to write a class Computer to stores the computer id, description, brand, price, speed and another... of it. Part B Develop array based java program to help a local computer shop
configuration files - Java Beginners
configuration files  i have to use configuration file in my program "listing of number of files and their modified time of directory",but problem... by user, tell me what exactly is this configuration file , what are its uses and how
Hibernate dialect configuration
Hibernate dialect configuration  How to configure hibernate dialect in the Hibernate configuration file? Thanks
Steps to log4j configuration in Struts2
Steps to log4j configuration in Struts2  Hi... any tel me each step for configure log4j in struts2 application
computer manufacture case study
computer manufacture case study  Computer Manufacturer Case Study BNM is an upcoming computer manufacturer. The company was making a mark... with standard configuration and Windows 7 as OS. The customers can also go
List of Computer Software
List of Computer Software  Hi, I am looking for the list of Computer programming languages. Provide me the list of Computer Software used these days... for different purposes. See the List of Computer software. Thanks
MySQL Configuration
MySQL Configuration      ... . The MySQL server configuration normally started during  installation process .  MySQL server configuration wizard window  The MySQL configuration wizard
Connected Limited Device Configuration
Connected Limited Device Configuration  (Q) One of the most common... the J2ME, is the Connected Limited Device Configuration. What type of device is this most suitable for, what are main limitations of this configuration and what
The input device used by computer is
The input device used by computer is  The input device used by computer is 1. Motherboard 2. Central Processing Unit 3. Keyboard 4. System Unit 5. All of the above   Answer: 2. Central Processing Unit
a computer network is referred as
a computer network is referred as  The structure of interconnecting of nodes of --- a computer network is referred as 1. Network topology 2. Internet 3. Local Area network 4. Wide Area network 5. All of these   Answer
computer - Swing AWT
computer  What is a Computer and why we should use it? I am new to this technologies so please let me know the benefits of using computer.   What you what to know about computers?Is it a software or hardware related
xml configuration file - JDBC
xml configuration file  Hi, Could you please tell me how to write a xml configuration file . We have mysql database in some other system. I have to access the data from different system. For this jdbc connectivity how
computer management - Java Beginners
computer management  Create a class Computer that stores information... to be stored about a single computer is, - Company Name - RAM size... array of 4 objects of Computer class and that takes input for all above
@configuration annotation in Spring 3
@configuration annotation in Spring 3  doesn't make code tight coupling..? if we keep that in IOC in XML form, its deployment free for some kind of change management right?.   Please visit the following link: http
JDBC Configuration in Ubuntu 10.04
JDBC Configuration in Ubuntu 10.04  Hi everybody, Am using Linux Ubuntu 10.04, java jdk 1.6 and mysql 5.1 and I have trouble to load mysql connector and i have no such driver found for dbtest.java. pleas guide me to solve
Could not parse configuration: hibernate.cfg.xml
Could not parse configuration: hibernate.cfg.xml  Hi, I am getting... configuration: hibernate.cfg.xml at org.hibernate.cfg.Configuration.doConfigure... version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration
ALU Computer Term
ALU Computer Term  What is ALU? Please define and explain ALU in simple language.   ALU stands for Arithmetic logic unit is a brain of CPU, which is used for the processing of data and information provided
characteristics of a modem computer
characteristics of a modem computer  Which of the following describe one or more characteristics of a modem computer? 1. An electronic device 2. A mechanical device 3. A Electro-mechanical device 4. All of these 5. None
Computer security - Security
computer security advice  Can any one give me a computer security advice? Thanks!  Please take care whenever you are formatting your hard drive as when you format a hard drive, you erase all its files and prepare
ldap configuration for SVN on linux
ldap configuration for SVN on linux  I want to set up ldap and normal file authentication for my SVN in linux. I should i do that? Here basically i need to read file which contains several user name and passwd values and LDAP
java with computer network
java with computer network  i feel it's very difficult to use java for network programming. how can i recover this problem?give me any simple example with explanation.   hi, if you want to make carrier in software
Getting Computer Date in java
Getting Computer Date in java  Hi , I want to get the PC Date and insert it to a DB, specifically MSSQL.. Everything in my scriptlet works but this.. String strDate = new Date(); I get this server error, "The type Date
Hibernate configuration file
This tutorial helps you in understanding the configuration file of Hibernate
Configuration issues with tomcat5
Configuration issues with tomcat5  i have copied a tomcat5 zip file and unzit it in my system C:/ drive....i am folowing every standard and my directory structure is given below:-               Demo(Project Name
Tomcat Configuration For Eclipse Server
Tomcat Configuration For Eclipse Server  How to configure Eclipse Tomcat Server? I am using Tomcat 6.0v Thanks In Advance   Install tomcat on eclipse 1)First download the tomcat and install it on your hard drive. 2
Configuration issues with tomcat5
Configuration issues with tomcat5  i have copied a tomcat5 zip file and unzit it in my system C:/ drive....i am folowing every standard and my directory structure is given below:-               Demo(Project Name
different types of storage devices of a computer
different types of storage devices of a computer  What are the different types of storage devices of a computer?   Magnetic disks, Tapes and DVDs are few examples of storage devices of a computer
How to Find PHP version and configuration?
How to Find PHP version and configuration?  Find PHP version and configuration   If you want to find the version of PHP, you can just run...: http://www.phpzag.com/find-php-version-and-configuration
Hibernate Configuration File
Hibernate Configuration File In this tutorial you will learn about the hibernate configuration file. To define a Hibernate Configuration info a resource file named hibernate.cfg.xml is used. Using this configuration file various
WAS server configuration from JAVA program
WAS server configuration from JAVA program  How to get web sphere server status like heap,connection pool properties,stall counts etc. from a java applciation
Computer dealer management - Java Beginners
Computer dealer management  Create a class Computer that stores.... The information to be stored about a single computer is, - Company Name - RAM size... ( ) method that creates array of 4 objects of Computer class and that takes input for all
Computer Scince 1015 - Java Beginners
Computer Scince 1015  Write a SavingsAccount class to store the following information related to a bank account: Account number, Password, Branch name, Surnames, First names, Balance The account balance should be able
Hibernate Configuration File
Hibernate Configuration File In this section we will read about the hibernate configuration file. In this file we will see how we can provide the database connection information to a file. Hibernate Configuration file i.e.
Get computer name in java
Get computer name in java       We can get the computer name by the java code program. For getting computer name we have used java.net.InetAddress class. We will use static
 

 

 

DMCA.com