In Java please create two classes.
Racecar - Should contain:
variables - color (string), id (string), topSpeed (int), and
efficiency (double between 0-1)
getters & setters for each, but getSpeed should return
topSpeed* efficiency
Main - should instantiate 3 car objects (values up to you) and
compare the top speeds.
the 'winner' should be printed out as the following:
"The [color] car, [id], is the winner!"
Program:
import java.util.*;
class Racecar
{
String color,id;
int topSpeed;
double efficiency;
void setColor(String col)
{
color=col;
}
void setID(String id1)
{
id=id1;
}
void setTopSpeed(int ts)
{
topSpeed=ts;
}
void setEfficiency(double eff)
{
efficiency=eff;
}
String getColor()
{
return color;
}
String getID()
{
return id;
}
int getTopSpeed()
{
return topSpeed;
}
double getEfficiency()
{
return efficiency;
}
double getSpeed()
{
return topSpeed * efficiency;
}
}
class TestRaceCar
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String col,id1;
int tpSpd;
double eff;
Racecar rc[]=new Racecar[3];
for(int i=0;i<=2;i++)
{
rc[i]=new Racecar();
System.out.print("\nEnter Details of Racecar "+(i+1)+": ");
System.out.print("\nEnter Color: ");
col=sc.next();
rc[i].setColor(col);
System.out.print("Enter ID: ");
id1=sc.next();
rc[i].setID(id1);
System.out.print("Enter Top Speed: ");
tpSpd=sc.nextInt();
rc[i].setTopSpeed(tpSpd);
System.out.print("Enter Efficiency ( between 0-1): ");
eff=sc.nextDouble();
rc[i].setEfficiency(eff);
}
double top=-1;
int index=-1;
for(int i=0;i<=2;i++)
{
if(i==0)
{
top=rc[i].getSpeed();
}
if(top<rc[i].getSpeed())
{
index=i;
top=rc[i].getSpeed();
}
}
System.out.println("\nThe "+rc[index].getColor()+" car,
"+rc[index].getID()+" is the Winner!\n");
}
}
Output:

In Java please create two classes. Racecar - Should contain: variables - color (string), id (string),...
Need help to create general
class
Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...
Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...
using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...
Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...
JAVA
i need write java program
Object Classes: designing Shopping Cart
1.Shopping Cart , build a checkout system for a shop which sells
items (i.e., products say Bread, Milk, and Bananas). A shopping
cart that can have multiples. Costs of the products are : Bread -
$1, Milk - $0.60 and Banana - $0.40. A system should displays the
order total.
2.The heart of a shopping cart can be represented in three
classes: a cart class an order class, and...
I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...
JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...
Please create two tests classes for the code down below that use all of the methods in the Transaction class, and all of the non-inherited methods in the derived class. Overridden methods must be tested again for the derived classes. The first test class should be a traditional test class named "Test1" while the second test class should be a JUnit test class named "Test2". All I need is to test the classes, thanks! Use a package that contains the...
Answer the following: 1. Create a Class Car with the following instance variables: model (String), Brand (String), maxspeed (double) Note: use encapsulation (all variables are private). (3 Marks) 2. Create a non-default constructor for Class Car which takes 3 parameters. (2 Marks) 3. Create a get and set methods for instance variable model variable only. (2 Marks) 4. Create PrintInfo() method which prints all three instance variables. (2 Marks) 5. Create a subclass GasCar with instance variable TankSize (double).. (2...
Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...