Question

In: Computer Science

Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....

Please Use your keyboard (Don't use handwriting) Thank you..

I need new and unique answers, please. (Use your own words, don't copy and paste)

Q1:

Your team is 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.

Q2:

Write a complete Java program that prints out the following information:

  1. Declare String object and a variable to store your name and ID.
  2. DisplayYour Name and Student ID.
  3. Display Course Name, Code and CRN
  4. Replace your first name with your mother / father name.
  5. Display it in uppercase letter.

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.

_____

Q3:

Write a tester program to test the given class definition.

Create the class named with your id with the main method.

  1. Create two mobiles M1 and M2 using the first constructor.
  2. Print the characteristics of M1 and M2.
  3. Create one mobile M3 using the second constructor.
  4. Change the id and brand of the mobile M3. Print the id of M3.

Your answer should be supported with the screenshot of the output, else zero marks will be awarded.

public class Mobile

{

int id;

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;

          }

}

___

Q4:

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.

Your answer should be supported with a screenshot of the program with output.

Solutions

Expert Solution

Here is the omplete code for partA with proper comment:

1.

Code:

public class CarTravel
{
//method which select trip with minimum travel time
public static void selectTrip(double dist_A, double dist_B, double carSpeed)
{
//travel time to destination A
double travelTimeA = dist_A / carSpeed;
double travelTimeB = dist_B / carSpeed;
  
//print data
System.out.println("Car Take total time to travel destination A: " + travelTimeA + " hrs");
System.out.println("Car Take total time to travel destination B: " + travelTimeB + " hrs");
  
System.out.println("Car Decided: ");
  
//choose the destination Decided by car
if(travelTimeA < travelTimeB)
{
System.out.println("Car will travel to destination A because it will take less time");
}
else
{
System.out.println("Car will travel to destination B because it will take less time");
}
}
  
//execution of program starts from here
   public static void main(String[] args) {
      
      
       //provide the destination of both roadtrips in kms
       double trip_A_dest = 200 ; //200km
       double trip_B_dest = 450 ; //450km
      
       //provide the car speed
       double car_speed = 80; //80kmph
      
       //method to choose the trip by car
       selectTrip(trip_A_dest, trip_B_dest, car_speed);
      
   }
}

-----------------------------------------------------------------------------------------------------

Output:

----------------------------------------------------------------------------------------------------------------------

2. Code for Second Part:

Code:

public class Main
{
  
//execution of program starts from here
   public static void main(String[] args) {
      
      
       //declaring String object and storing my name
       String name = new String("Ameera Asiri");
      
       //declaring a variable and storing my id
       int id = 123456789;
      
   //other member variables and storing other required fields
   String courseName = "Conputer Programming";
   String courseCode = "CS140";
   int courseCrn = 12345;
  
   //display all fields
   System.out.println("My Name is : " + name);
   System.out.println("My student ID : " + id);
   System.out.println("My Course Name : " + courseName);
   System.out.println("My Course Code : " + courseCode);
   System.out.println("My Course CRN : " + courseCrn);
  
   //Replace your first name with your mother / father name.
   name = name.replace("Ameera", "Aiysha");
  
   //make it upperCase
   name = name.toUpperCase();
      
       System.out.println(name);
      
   }
}

----------------------------------------------------------------------------------------------------------------------

Output:

-----------------------------------------------------------------------------------------------------------------

3. Complete code:

class Mobile

{

int id;

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;

}

}


//Writing the Tester Code
public class Main //replace this class with yourname + id Example : class Ameera123456789
{
  
//execution of program starts from here
   public static void main(String[] args) {
      
       //Create two mobiles M1 and M2 using the first constructor.
       Mobile M1 = new Mobile();
       Mobile M2 = new Mobile();
      
//Print the characteristics of M1 and M2.
System.out.println("Brand: " + M1.getBrand() + "Id: " + M1.getId());
System.out.println("Brand: " + M2.getBrand() + "Id: " + M2.getId());

//Create one mobile M3 using the second constructor.
Mobile M3 = new Mobile(121, "X3");

//Change the id and brand of the mobile M3.
M3.setId(222);
M3.setBrand("Realme");

//Print the id of M3.
       System.out.println(M3.getId());
      
   }
}

---------------------------------------------------------------------------------------------------------

Output:

---------------------------------------------------------------------------------------------------------

4. Complete Code:


public class Main
{
  
//method two calculate Salary
public static double raiseSalary(int sal1, int sal2)
{
//return sum of sal1 + sal2 multiplied by 15%
double totalSalary = (sal1 + sal2) * 0.15; //15% = 15 / 100 = 0.15
  
return totalSalary;
}
  
//execution of program starts from here
   public static void main(String[] args) {
      
       int sal1 = 200000;
       int sal2 = 34000;

//calculate and print Salary
       System.out.println(raiseSalary(sal1, sal2));
      
   }
}
--------------------------------------------------------------------------------------

Output:


Related Solutions

Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please. (Use your own words, don't copy and paste) IT243 Course name: System Analysis and Design ***********Please i need more details and more Explain********** Q1: What are the roles of a project sponsor and the approval committee during the different SDLC phases? Q2: As the project sponsor, you suggested that your company that runs multiple local supermarkets should provide an online shopping service to increase...
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please. (Use your own words, don't copy and paste) IT243 Course name: System Analysis and Design ***********Please i need more details and more Explain********** Q2: As the project sponsor, you suggested that your company that runs multiple local supermarkets should provide an online shopping service to increase sales during COVID-19 pandemic. Write a system request to propose this project. System request Project Sponsor Business Need...
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please. (Use your own words, don't copy and paste) HCI 314 Write a page and a half (400-600 words) in an essay style answer to respond to the following question: Disruptive innovation is a driver for change in public health informatics. As a Health Informatics professional which innovation do you think has the greatest impact during COVID-19 pandemic and why? _____ please re -write my...
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please. (Use your own words, don't copy and paste) IT243 Course name: System Analysis and Design Q2: As the project sponsor, you suggested that your company that runs multiple local supermarkets should provide an online shopping service to increase sales during COVID-19 pandemic. Write a system request to propose this project. System request Project Sponsor Business Need Business Requirements Business Value Special Issues or Constraints...
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please. (Use your own words, don't copy and paste) PHC151 Illustrate the adverse effects of the foodborne diseases, foodborne infections and foodborne outbreaks on the human health.
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please. (Use your own words, don't copy and paste) PHC 312 If you were the head of health communication unit at Saudi MOH, how will you improve the health communication strategies used now during COVID-19 Give suggestions and/or recommendations Briefly discuss the importance of citizen engagement in health communication
Please Use your keyboard (Don't use handwriting) CS141 I need new and unique answers, please. (Use...
Please Use your keyboard (Don't use handwriting) CS141 I need new and unique answers, please. (Use your own words, don't copy and paste) Q1: Show all the steps of the following data set when it being sorted with Insertion, Selection, and Merge Sort Algorithms. Then, calculate the performance of each one of them.(Big –O Notation) 18 4 26 9 21 15 20 10 Q2: Write a program using LinkedList and ListIterator to obtain the following statements: 1. Create a linked...
Please Use your keyboard (Don't use handwriting) MGT211 I need new and unique answers, please. (Use...
Please Use your keyboard (Don't use handwriting) MGT211 I need new and unique answers, please. (Use your own words, don't copy and paste) TOPIC: EMPLOYEE HEALTH AND SAFETY IN THE ORGANIZATION Organization officials have a legal and moral responsibility to ensure that the workplace is free from unnecessary hazards. Employers hold responsibility for understanding what is necessary to keep workers safe from harm. Conditions surrounding the workplace must be secure for employee’s physical and mental health. As many organizations have...
Please Use your keyboard (Don't use handwriting) Econ I need new and unique answers, please. (Use...
Please Use your keyboard (Don't use handwriting) Econ I need new and unique answers, please. (Use your own words, don't copy and paste) Q: how supply, demand, and prices affect the auto industry. includes: supply and demand, public spending and the outcome.
Please Use your keyboard (Don't use handwriting) MGT211 I need new and unique answers, please. (Use...
Please Use your keyboard (Don't use handwriting) MGT211 I need new and unique answers, please. (Use your own words, don't copy and paste) TOPIC:   EMPLOYEE HEALTH AND SAFETY IN THE ORGANIZATION Organization officials have a legal and moral responsibility to ensure that the workplace is free from unnecessary hazards. Employers hold responsibility for understanding what is necessary to keep workers safe from harm. Conditions surrounding the workplace must be secure for employee’s physical and mental health. As many organizations have...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT