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.
//Q1:
import java.util.*;
public class selfDrivingCar {
public static void main(String[] args) {
int distance1,distance2,speed1, speed2;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter first trip details distance and
car speed: ");
distance1 = sc.nextInt();
speed1 = sc.nextInt();
double time1 = distance1/speed1;
System.out.println("Please enter second trip details distance and
car speed: ");
distance2 = sc.nextInt();
speed2 = sc.nextInt();
double time2 = distance2/speed2;
if(time1 < time2) {
System.out.println("Choose first trip as time taken is less than
second trip ");
}
else if(time2 < time1) {
System.out.println("Choose second trip as time taken is less than
first trip");
}
else {
System.out.println("Choose either trip as time taken is equal in
both trips");
}
}
}
//Q2:
import java.util.*;
public class StudentDetails {
public static void main(String[] args) {
String name;
int id;
String courseName;
String code;
int CRN;
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name");
name = sc.nextLine();
System.out.println("Enter your student ID");
id = sc.nextInt();
System.out.println("Enter Course Name");
sc.nextLine();
courseName = sc.nextLine();
System.out.println("Enter your course Code");
code = sc.next();
System.out.println("Enter your course CRN");
CRN = sc.nextInt();
System.out.println("Enter your mother/father name");
sc.nextLine();
String mother = sc.nextLine();
System.out.println("My Name: "+name);
System.out.println("My student ID: "+id);
System.out.println("My Course Name: "+courseName);
System.out.println("My Course Code: "+code);
System.out.println( "My Course CRN: "+CRN);
String[] arr = name.split(" ");// to get your first name
mother = mother.split(" ")[0];
System.out.println(mother.toUpperCase()+"
"+arr[1].toUpperCase());
}
}
//Q3:
import java.util.*;
public class myid {
public static void main(String[] args) {
// TODO Auto-generated method stub
Mobile M1, M2;
M1 = new Mobile();
M2 = new Mobile();
System.out.println("Characteristics of M1: ");
System.out.println("id: "+M1.getId());
System.out.println("Brand: "+M1.getBrand());
System.out.println("Characteristics of M2: ");
System.out.println("id: "+M2.getId());
System.out.println("Brand: "+M2.getBrand());
Mobile M3 = new Mobile(2,"Micromax");
//Change the id and brand of the mobile M3.
M3.setId(5);
M3.setBrand("Motorola");
System.out.println("Characteristics of M3: ");
System.out.println("id: "+M3.getId());
System.out.println("Brand: "+M3.getBrand());
}
}
//Q4:
import java.util.*;
public class YourID {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int first,second;
System.out.println("Enter two integers");
first = sc.nextInt();
second = sc.nextInt();
System.out.println(raiseSalary(first, second));
}
static double raiseSalary(int a, int b) {
return (a+b)*1.15;
}
}