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



Home Answers Viewqa Java-Beginners object oriented program..
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mar
object oriented program..
1 Answer(s)      5 years and 2 months ago
Posted in : Java Beginners



Advertisement
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 in PHP
Object Oriented Programming in PHP  Hi, Which version of PHP supports OOPS. How can I learn Object Oriented Programming in PHP? Thanks
object oriented programming protocol
object oriented programming protocol  What is object oriented programming protocol? Is it different from objective c protocol programming?? Thanks
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 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
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
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 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
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
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... of a class. For a language to be an Object Oriented Programming Language, it must... world. Every object has a certain behavior, properties, type, and identity
JavaScript Object Oriented Feature
to be reentrant.  Encapsulation The Object-Oriented program using... collisions. The Object-Oriented program Encapsulation supports data hiding...  JavaScript Object Oriented Feature  
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 pure C code, not C++. The function prototypes are in an object-oriented form
Java Object
Java Object         Object is the basic entity of object oriented programming language. Object.../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
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
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
What is attribute oriented programming?
What is attribute oriented programming?  Hi, What is attribute oriented programming? Thanks
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
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
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
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
Advertisements
 

 

 

DMCA.com