In: Computer Science
1/Your team was asked to program a self-driving car that reaches its destination with minimum travel time.
Write an algorithm for this car to choose from two possible road trips. You will calculate the travel time of each trip based on the car current speed and the distance to the target destination. Assume that both distances and car speed are given.
2/
Write a complete Java program that do the following:
Note:Your program output should look as shown below.
My Name: Ameera Asiri
My student ID: 123456789
My Course Name: Computer Programming
My Course Code: CS140
My Course CRN: 12345
AIYSHA ASIRI
Note: Include the screenshot of the program output as a part of your answer.
3/
Write a tester program to test the mobile class defined below.
Create the class named with your id (for example: Id12345678) with the main method.
Your answer should include a screenshot of the output. Otherwise, you will be marked zero for this question.
public class Mobile {
private int id;
private String brand;
public Mobile() {
id = 0;
brand = "";
}
public Mobile(int n, String name) {
id = n;
brand = name;
}
public void setBrand(String w) {
brand = w;
}
public void setId(int w) {
id = w;
}
Public int getId() {
return id;
}
public String getBrand() {
return brand;
}
}
4/
Write a method named raiseSalary that accepts two integers as an argument and return its sum multiplied by 15%. Write a tester program to test the method. The class name should be your ID (for example: Id12345678).
Your answer should include a screenshot of the output. Otherwise, you will be marked zero for this question.
1.
Answer :
import java.util.Scanner;
public class selfDrivingCar {
double minimumTravelTime(double
timeTakenByFirstRoadTrip, double timeTakenBySecondRoadTrip) {
return
Math.min(timeTakenByFirstRoadTrip,
timeTakenBySecondRoadTrip);
}
double timeTakenInRoadTrip(double speed, double
distance) {
return distance / speed;
}
public static void main(String args[]) {
selfDrivingCar selfDrivingCar = new
selfDrivingCar();
Scanner scanner = new
Scanner(System.in);
System.out.println("Enter speed and
distance in first road trip:");
double timeTakenInFirstRoadTrip =
selfDrivingCar.timeTakenInRoadTrip(scanner.nextDouble(),
scanner.nextDouble());
System.out.println("Enter speed and
distance in second road trip:");
double timeTakenInSecondRoadTrip =
selfDrivingCar.timeTakenInRoadTrip(scanner.nextDouble(),
scanner.nextDouble());
scanner.close();
double minimumTravelTime =
selfDrivingCar.minimumTravelTime(timeTakenInFirstRoadTrip,
timeTakenInSecondRoadTrip);
System.out.println("Minimum travel
time: "+minimumTravelTime);
}
}
Screenshot:
2.
Answer : Please change class name as per your Id.
import java.util.Scanner;
public class Id12345677 {
public static void main(String args[]) {
Scanner scanner = new
Scanner(System.in);
System.out.println("Enter your
firstName,lastName,
studentId,courseName,courseId,courseCRN,fatherOrMotherFirstName:
");
String firstName =
scanner.nextLine();
String lastName =
scanner.nextLine();
String studentId =
scanner.nextLine();
String courseName =
scanner.nextLine();
String courseId =
scanner.nextLine();
String courseCRN =
scanner.nextLine();
String fatherOrMotherFirstName =
scanner.nextLine();
System.out.println("My Name:
"+firstName+ " "+lastName);
System.out.println("My student ID:
"+studentId);
System.out.println("My Course Name:
"+courseName);
System.out.println("My Course Code:
"+courseId);
System.out.println("My Course CRN:
"+courseCRN);
System.out.println(fatherOrMotherFirstName.toUpperCase()+"
"+lastName.toUpperCase());
}
}
Screenshot:
3.
Answer: Please change class name as per your Id.
public class Id12345679 {
public static void main(String args[]) {
Mobile M1 = new Mobile();
System.out.println("Characteristics
of M1 :");
System.out.println("Id :"+
M1.getId());
System.out.println("Brand :"+
M1.getBrand());
Mobile M2 = new Mobile();
System.out.println("Characteristics
of M2 :");
System.out.println("Id :"+
M2.getId());
System.out.println("Brand :"+
M2.getBrand());
Mobile M3 = new Mobile(1,
"M3");
System.out.println("Characteristics
of M3 :");
System.out.println("Id :"+
M3.getId());
System.out.println("Brand :"+
M3.getBrand());
}
}
4.
Answer : Please change class name as per your Id.
import java.util.Scanner;
public class Id12345678 {
double raiseSalary (int firstArgument,int
secondArgument) {
return
((firstArgument+secondArgument)*0.15);
}
public static void main(String args[]) {
Scanner scanner = new
Scanner(System.in);
System.out.println("Enter two
arguments:");
int firstArgument =
scanner.nextInt();
int secondArgument =
scanner.nextInt();
Id12345678 id12345678 = new
Id12345678();
double raisedSalary =
id12345678.raiseSalary(firstArgument, secondArgument);
System.out.println("Raised Salary :
"+raisedSalary );
}
}
Screenshot: