object oriented program..

object oriented program..

View Answers

October 21, 2009 at 10:39 AM

Hi Friend,

Try the following code:

import java.util.*;

public class RaceCar{
double hw;
double weight;
double milesPerGal;
double zeroTo60;
public RaceCar(double hw,double weight,double milesPerGal,double zeroTo60){
this.hw=hw;
this.weight=weight;
this.milesPerGal=milesPerGal;
this.zeroTo60=zeroTo60;
}
public void setHw(double hw){
this.hw=hw;
}
public double getHw(){
return hw;
}
public void setWeight(double weight){
this.weight=weight;
}
public double getWeight(){
return weight;
}
public void setMilesPerGal(double milesPerGal){
this.milesPerGal=milesPerGal;
}
public double getMilesPerGal(){
return milesPerGal;
}
public void setZeroTo60(double zeroTo60){
this.zeroTo60=zeroTo60;
}
public double getZeroTo60(){
return zeroTo60;
}
public double calculateTime(){
double acceleration=0.167/zeroTo60;

return Math.sqrt(2 * 0.25 / acceleration);

}

public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.println("Enter horse power for car 1 between the range 200 to 700 hp");
double hw1=input.nextDouble();
System.out.println("Enter weight for car 1 between the range 1000 to 3000 pounds.");
double w1=input.nextDouble();
System.out.println("Enter horse power for car 2 between the range 200 to 700 hp");
double hw2=input.nextDouble();
System.out.println("Enter weight for car 2 between the range 1000 to 3000 pounds.");
double w2=input.nextDouble();

double zeroTo60CarA=w1/hw1/0.7;
double zeroTo60CarB=w2/hw2/0.7;

RaceCar car1=new RaceCar(hw1,w1,0.25,zeroTo60CarA);
double time1=car1.calculateTime();
System.out.println("Time taken by car 1= "+time1);
RaceCar car2=new RaceCar(hw2,w2,0.25,zeroTo60CarB);
double time2=car2.calculateTime();
System.out.println("Time taken by car 2= "+time2);
}
}

Thanks









Related Tutorials/Questions & Answers:
object oriented program.. - Java Beginners
object oriented program..  Write a class called RaceCar.java that contains instance variables horsepower, weight, zeroTo60, and milesPerGal. The value of zeroTo60 (in second) is determined by the formula zeroTo60 = weight
Object oriented program - Java Beginners
Object oriented program  Write a class called RaceCar.java that contains instance variables horsepower, weight, zeroTo60, and milesPerGal. The value of zeroTo60 (in second) is determined by the formula zeroTo60 = weight
Advertisements
Object Oriented
Object Oriented  C++ is Purely object oriented or not .Then why java called purely object oriented
object oriented programming protocol
object oriented programming protocol  What is object oriented programming protocol? Is it different from objective c protocol programming?? Thanks
Is Java object oriented?
Is Java object oriented?  Hi, Is Java object oriented? Thanks   Hi, Java is object oriented programming language. It is supports OPPS concepts: Object Class Inheritance Polymorphism Abstraction Encapsulation All
Object Oriented Programming in PHP
Object Oriented Programming in PHP  Hi, Which version of PHP supports OOPS. How can I learn Object Oriented Programming in PHP? Thanks (adsbygoogle = window.adsbygoogle || []).push
java is pure object oriented
java is pure object oriented  java is pure object oriented or not.? reason.?   Java is not pure object oriented language because... are not object 2)It does not support operator overloading multiple inheritance. 3
object oriented programming - Java Beginners
object oriented programming  sir, i read in the book tat object oriented program exhibits recurring structures. i want to know "what is meant by recurring structures?"  Hi Friend, Any structure to be occurred over
Object Oriented Programming II
Object Oriented Programming II  Instructions: ->each class to be created must have encapsulated fields, setters and getters methods, and constructors Create a class named "Paper" with the following attributes
java : object oriented
java : object oriented   (a) Write a class named CarRental... the user for the data needed for a rental and creates an object of the correct... an object of the correct type. Display the total rental fee
Is Java a pure object oriented language?
Is Java a pure object oriented language?   Hi, Is Java a pure object oriented language? thanks   Hi No, Java is an object oriented programming language but not purely a object oriented language. In OOPs programming
Object-Oriented programming - Java Beginners
Object-Oriented programming  Write a program to display the names and salaries of 5 employees.Make use of a class and an array.The salary of each employee should increase by 5% and displayed back.  Hi friend, Code
object oriented programming data science
object oriented programming data science  Hi, I am beginner in Data...: object oriented programming data science Try to provide me good examples or tutorials links so that I can learn the topic "object oriented programming
What are the features and advantages of OBJECT ORIENTED PROGRAMMING?
What are the features and advantages of OBJECT ORIENTED PROGRAMMING?  What are the features and advantages of OBJECT ORIENTED PROGRAMMING
Object Oriented concepts
OOP stands for Object Oriented Programming. This is a technique used... on the following links Object Oriented concepts..., every real life object has properties and behavior. which is achieved through
fully object oriented language - Java Beginners
fully object oriented language  Is java is a fully object oriented language?if no,why?  Hi Friend, Java is not a fully object oriented... int,float which are not object 2)It does not support operator overloading
Java using Netbeans Object Oriented Programming
Java using Netbeans Object Oriented Programming   I am trying to make a program that uses a main class and a separate class with one public method and one private method. The main method in the main class asks the user for 2
Object Oriented Programming in Java
OOPS acronym for Object Oriented Programming is a model or concept that works... is an instance of a class. For a language to be an Object Oriented Programming... world. Every object has a certain behavior, properties, type, and identity
JavaScript Object Oriented Feature
in scope increasing the risk of name collisions. The Object-Oriented program...  JavaScript Object Oriented Feature  ... the basics of JavaScript and create your first JavaScript program. What is Object
Object oriented design - Java. - Design concepts & design patterns
Object oriented design - Java.  Hi, Everyone.Pls help me to develope my project of Object oriented design, as I have to submit it on thursday,3rd Dec. 2009.Nowadayz I am suffering from fever and not able to concentrate
core java code in object oriented manner - Java Interview Questions
core java code in object oriented manner   hi this is komali .i want small code for this question .its very urgent .please send me as soon as possible . i am waiting for code Sports Associations in India
An Overview of Java      Java is a programming language      Java is Object Oriented Programming
; Java as a programming language Java is an Object oriented...; Java as an Object Oriented Language In this section, we will discuss the OOPs... are in an object-oriented form of C which are being provided by javah , but they are still
Java Object
Java Object         Object is the basic entity of object oriented programming language. Object.../java/master-java/java-object-oriented-language.shtml  
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.  (Aim:- The main aim of this experiment is reusability of code and getting idea about classifying objects , identifying
Is it modify Object data? Generally Object data can't modify............but in this program it modifies.......... Why?
Is it modify Object data? Generally Object data can't modify............but in this program it modifies.......... Why?   import java.io.*; public... to Object conversion System.out.println("Before fundamental to object
Java as an Object Oriented Language
Java as an Object Oriented Language   ... applications and programs. OOP stands for Object Oriented Programming.... There are four main pillars of an Object Oriented Programming Language
Byte ? Oriented Stream and Character- Oriented Stream
Byte ? Oriented Stream and Character- Oriented Stream  difference between Byte ? Oriented Stream and Character- Oriented Stream
Byte ? Oriented Stream and Character- Oriented Stream
Byte ? Oriented Stream and Character- Oriented Stream  Difference between Byte ? Oriented Stream and Character- Oriented Stream
object
object  is it possible to create object in the same class..?.   Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args
ModuleNotFoundError: No module named 'goal_oriented'
ModuleNotFoundError: No module named 'goal_oriented'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'goal_oriented' How to remove the ModuleNotFoundError: No module named
Java example program to get the object's ID
Java example program to get the object's ID       java get Object id In java there is no any specific method that provides us the object's ID. But each object has its own unique
Object-Oriented Language: Java / APIs, Java OOPs
Java OOPs In this section we will learn Object Oriented (OOPs) Concepts .... Java is one of the useful Object Oriented programming language. Other Object..., Lasso, Perl 5,PHP5, VBScript, VBA etc. Java is popular object oriented programming
What is attribute oriented programming?
What is attribute oriented programming?  Hi, What is attribute oriented programming? Thanks
Introduction
Java as an Object Oriented Language   ... the java applications and programs. OOP means Object Oriented Programming.... To be an Object Oriented language, any language must follow at least the four
PHP Class Object
PHP Class Object: In object oriented programming a class can be an abstract... apple, orange are the object of this class. Object is the instantiate..._TO_REPLACE_1 PHP Object Class Example: <?php class AADS_TO_REPLACE_2
What is Service-Oriented Architecture?
Service Oriented Architecture or SOA for short is a new architecture for the development of loosely coupled distributed applications. In fact service-oriented... service coordination. Earlier SOA was based on the DCOM or Object Request Brokers
OOP
; Object Oriented Programming which was totally based on the real life entities and scenerios. OOPs enables to program the real world objects and easily play... for Object oriented  Programming. Previously we used to follow
object of object class
object of object class  what do u mean by "object of object class
Html tag inside out implicit object
on the browser. To make this program run use out object inside which define some html...Html tag inside out implicit object          In this program we are going to use
Java - Class, Object and Methods in Java
creation and implementation of the object, Inheritance etc. In this Program you will see how to use the class, object and it's methods. This program uses...);   } } Descriptions of the program: Object
Object
are the basic units of the object-oriented programming. Objects are the part of our day... to begin thinking in terms of object-oriented programming. Objects are key to understanding object-oriented programming. Just look around and you'll find a lot
program
program  any program of hotel or school management
program
program  program of jdbc using ms access for creating table
program
program  write a javascript program to create a application form with validation
program
program  write a html program in show table and this word in box
program
program  write a program different between to dates in terms of days in java
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
program
program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
program
program  write a program reversee a string. input-hi this is roseindia output-roseindia is this hi
program
program  develop a servlet to insert the data in the database from our program in the table stored in the database

Ads