Car.java Car.java public class Car{ //Variable Declarations private int year; private String make; private String model; private String colour; private double speed; //Default Constructor...

Need 2,3,4 done in tasks PDF


Car.java Car.java public class Car{     //Variable Declarations     private int year;     private String make;     private String model;     private String colour;     private double speed;          //Default Constructor     public Car(){         year = 0;         make = "";         model = "";         colour = "";         speed = 0.0;     }          //Constructor receiving arguments     public Car(int initYear, String initMake, String initModel, String initColour, double initSpeed){         year = initYear;          make = initMake;          model = initModel;         colour = initColour;         speed = initSpeed;     }          public void setYear(int initYear){ //Set year of car         year = initYear;     }          public void setMake(String initMake){ //Set Make of car         make = initMake;     }             public void setModel(String initModel){ //Set Model of car         model = initModel;     }             public void setColour(String initColour){ //Set Colour of car         colour = initColour;     }             public void setSpeed(double initSpeed){ //Set initial Speed of car         speed = initSpeed;     }          public void increaseSpeed(){ //Set speed of car by increasing by 10         speed = speed + 10;      }           public double getSpeed(){ //Return speed of car         return speed;      }           public String getMake(){ //Return make of car         return make;      }           public String getModel(){ //Return model of car         return model;     }          public String getColour(){ //Return colour of car         return colour;     }          public int getYear(){return year;}//Return year of car          }//end class CarProgram.java CarProgram.java import java.util.Scanner;  // this is needed only if you need input from keyboard class CarProgram{      public static void main(String[] args){                   //Create new car object         Car myCar = new Car(1973,"Holden","Monaro","Mandarine Red",160.0);                   Car yourCar = new Car(2020, "BMW", "XL5", "silver", 300.0);                  Car herCar = new Car();                  //Print properties of myCar object to screen         System.out.println("\n");         //System.out.println("Car Year:   "+myCar.getYear());          //System.out.println("Car Year:   "+ year);                            System.out.println("My Car Make:   "+myCar.getMake());          System.out.println("Car Model:  "+myCar.getModel());         System.out.println("Car Colour: "+myCar.getColour());         System.out.println("Car Speed:  "+myCar.getSpeed());                   System.out.println("Your Car Make:   "+yourCar.getMake());          System.out.println("Your Car Model:  "+yourCar.getModel());         yourCar.setModel("LM100");         System.out.println("Your Car Model:  "+yourCar.getModel());                  //Calls to set the speed of the car object         myCar.increaseSpeed();          myCar.increaseSpeed();                           //Print properties of Car object to screen         System.out.println("\n");         System.out.println("Car Year:   "+myCar.getYear());          System.out.println("Car Make:   "+myCar.getMake());          System.out.println("Car Model:  "+myCar.getModel());         System.out.println("Car Colour: "+myCar.getColour());         System.out.println("Car Speed:  "+myCar.getSpeed());                   System.out.println("Her Car Make:   "+herCar.getMake());          System.out.println("Her Car Model:  "+herCar.getModel());         System.out.println("Her Car Colour: "+herCar.getColour());         System.out.println("Her Car Speed:  "+herCar.getSpeed());                   Scanner input = new Scanner(System.in);           System.out.print("Please enter the speed of her car: ");         double herSpeed;         herSpeed = input.nextDouble();         herCar.setSpeed(herSpeed);         System.out.println("Her Car Speed:  "+herCar.getSpeed());               } //end main }//end class CircleDefinitionsMethods.java CircleDefinitionsMethods.java //insert here author and date // this program calculates diameter, circumference and area of a circle of a given radius //it uses methods import java.util.Scanner;  // this is needed only if you need input from keyboard public class CircleDefinitionsMethods{    public static void main( String args[] )    {     Scanner input = new Scanner(System.in);    // this is needed only if you need input from keyboard            //variable declarations     double radius;     double diameter;     double area;     double circumference;     double baseRadius;               //constants declarations          //code     System.out.print("Please enter the radius of the circle: ");     radius = input.nextDouble();          //calculate diameter     //diameter = radius * 2;          //calculate diameter using a method     diameter = diameterCalculation(radius);             //method call     System.out.printf("The diameter is %.2f", diameter);          System.out.print("Please enter the base radius of the cylinder: ");     baseRadius = input.nextDouble();          diameter = diameterCalculation(baseRadius);             //method call     System.out.printf("The diameter is %.2f", diameter);          //circumference = 2 * Math.PI * radius;     circumference = circumferenceCalculation(radius);     System.out.printf("\nThe circumference of the circle is %.2f", circumference);          circleInfo(radius, circumference);          circumference = circumferenceCalculation(baseRadius);     System.out.printf("\nThe circumference of the base of the cylinder is %.2f", circumference);     //calculate area              }          //method to display a circle's characteristics: radius, circumference     //input: value of radius - double; value of circumference - double     //output - no      public static void circleInfo(double r, double c)    {       System.out.printf("The radius is %.2f", r);       System.out.printf("\nThe circumference of the is %.2f", c);    }         //method to calculate the diameter of a circle    //input: a double to represent radius    //output: the value of the diameter, which is a double    public static double diameterCalculation(double r)    {        double d;        d = r * 2;        return d;    }         //method to calculate the circumference of a circle    //input: a double to represent radius    //output: the value of the circumference, which is a double    public static double circumferenceCalculation(double r)    {        double c;        c = 2 * Math.PI * r;        return c;    }                 } ClassTemplateSource.java ClassTemplateSource.java //insert here author and date // insert here a description of the program public class NameOfClass {     //data members          //constants          //constructors          //setters and getters          //other methods      } Employee.java Employee.java //    Employee.java //    Employee class public class Employee {    private String firstName;           // Employee's First Name    private String lastName;            // Employee's Last Name    private double monthlySalary;       // Employee's Monthly Salary // Employee constructor    public Employee( String initFirstName, String initLastName, double initMonthlySalary )     {       firstName = initFirstName;       lastName = initLastName;       if (initMonthlySalary > 0)           monthlySalary = initMonthlySalary;       else           monthlySalary = 0;    }     public Employee( )     {         firstName = "";         lastName = "";         monthlySalary = 0;     } // Method to assign the employee's First Name    public void setFirstName( String newFirstName )                       {       firstName = newFirstName;    } // Method to retrieve the employee's First Name    public String getFirstName()                                          {       return firstName;    } // Method to assign the employee's Last Name    public void setLastName( String newLastName )                         {       lastName = newLastName;    } // Method to retrieve the employee's Last Name    public String getLastName()                                           {       return lastName;    } // Method to assign the employee's Monthly Salary    public void setMonthlySalary( double newMonthlySalary )               {       if (newMonthlySalary > 0) monthlySalary = newMonthlySalary;    } // Method to retrieve the employee's Monthly Salary    public double getMonthlySalary()                                      {       return monthlySalary;    } // Method to obtain the employee's calculated Annual Salary    public double getAnnualSalary()                                       {       return monthlySalary * 12;    } // Method to display the employee's details    public void displayEmployeeDetails()                                  {       System.out.printf( "   %s %s's salary is $%.2f per year.\n", getFirstName(), getLastName(), getAnnualSalary() );    } }//end class Employee EmployeeTest.java EmployeeTest.java //    EmployeeTest.java //    Employee class test program public class EmployeeTest {     public static void main( String[] args ){         // Create 2 Employee objects         Employee employee1 = new Employee( "Jane", "Doe", 5000 );         Employee employee2 = new Employee( "John", "Bloggs", 4500 );         double salary;                  System.out.println();         // Show Employee 1's data         System.out.printf( "Employee 1's details as set by the constructor:\n" );              employee1.displayEmployeeDetails();         System.out.println();         // Show Employee 2's data         System.out.printf( "Employee 2's details as set by the constructor:\n" );              employee2.displayEmployeeDetails();         // Increase both employee's salaries by 10%.         salary = employee1.getMonthlySalary() * 1.1;         employee1.setMonthlySalary(salary);          salary = employee2.getMonthlySalary() * 1.1;         employee2.setMonthlySalary(salary);                      System.out.println();         System.out.println();         // Show Employee 1's data         System.out.printf( "Employee 1's details after pay rise:\n" );                         employee1.displayEmployeeDetails();    }//end main }//end class EmployeeTest MainTemplateSource.java MainTemplateSource.java //insert here author and date // insert here a description of the program import java.util.Scanner;  // this is needed only if you need input from keyboard public class NameOfClass {    public static void main( String args[] )    {     Scanner input = new Scanner(System.in);    // this is needed only if you need input from keyboard            //variable declarations          //constants declarations          //code    } } Tasks.pdf TAFE SA Associate Degrees in Engineering COMPUTING FOR ENGINEERING https://tafesaedu-my.sharepoint.com/personal/antoaneta_barbulescu_tafesa_edu_au/Documents/Desktop/Computing for Engineering/2020 materials/Topic 4 Classes and Objects/Practical4_ Programming Tasks.docx Page 1 of 3 (Revised: 16/10/20) PRACTICAL 4 - PROGRAMMING TASKS Aim The aim of this practical is to design, write, test and debug programs in Java using methods, classes and objects. Resources NOTE: before you start this, make sure that you follow the indicated Study Sequence. For all the reference materials, see the Learn site. Programming Tasks 1. Save the program CircleDefinitionsMethods.java from the code examples in your myCode folder. a. Add to the code a method to calculate the area (Note: just to calculate it, do not display it from the method). Then in main( ), call the method and display on the screen the value of the area. Submit: - the code b. Add to the code above a method to check that a double value is in a given range: checkRange. If it is, it returns a 1 if it is not, it returns a 0. Use this method to read the radius and check that it is in the range 5 to 100. If it is not in the range, keep asking the user to enter the value. Hint: see the lecture recordings. Then call the method in main( ) to see if the value entered for the radius is in a certain range or not. An example of how the method call could look like: Submit: - the code c. Add code to main( ) to call the method checkRange above to see if the value of the circumference calculated for a certain radius is smaller than 100 and larger than 0. If it is not, display a message to say the circumference is over 100. Submit: - the code TAFE SA Associate Degrees in Engineering COMPUTING FOR ENGINEERING https://tafesaedu-my.sharepoint.com/personal/antoaneta_barbulescu_tafesa_edu_au/Documents/Desktop/Computing for Engineering/2020 materials/Topic 4 Classes and Objects/Practical4_ Programming Tasks.docx Page 2 of 3 (Revised: 16/10/20) 2. Based on the example Employee.java and EmployeeTest.java (see lecture video and the code in the code folder), make the following additions: a. At the end of the EmployeeTest application, add code to change the first name of employee1 to Ann and the salary of employee2 to 6000 and then display the details of the 2 employees. Submit: - the code of the modified EmployeeTest b. Continue from the exercise at a. and add code to the EmployeeTest application to change the first name of employee2 to a name input from the keyboard and its salary to a value input from the keyboard. Display the details of the employee. Submit: - the code of the modified EmployeeTest c. Continue from the exercise at b. and add code to the EmployeeTest application to create a third employee by using the no-parameter (default) constructor. Then, add code to read from the user the employee’s first name, surname and monthly pay and set the employee’s fields to the values given by the user from the keyboard. Display the details of the employee. Submit: - the code of the modified EmployeeTest 3. For the Car class, make the following additions: a. Add a data member (field) to represent the registration number. b. Modify the constructors to reflect this addition c. Add the corresponding setter and getter. d. In the CarProgram class, modify the code so that it reflects this addition. Submit: - the code (2 files, one for the modified Car class and one for the modified CarProgram) 4. Write the code for the following task. Civil and Structural students ONLY Design a class to represent the category Paint (think of characteristics of paint as it is sold. For example, colour, price per square meter, paint coverage, manufacturer). Then write a program that shows the cost for the user for the 3 paint products. This code should be in an application class (a class with a main). Here you need to declare 3 objects of type Paint from 3 different manufacturers, with different characteristics, and then write code to do the following: The program should ask the user to indicate the area to be painted and then it displays the total cost for each one of the paint products. Submit: - the code (2 files, one for the Paint class and one for the TotalCost program) TAFE SA Associate Degrees in Engineering COMPUTING FOR ENGINEERING https://tafesaedu-my.sharepoint.com/personal/antoaneta_barbulescu_tafesa_edu_au/Documents/Desktop/Computing for Engineering/2020 materials/Topic 4 Classes and Objects/Practical4_ Programming Tasks.docx Page 3 of 3 (Revised: 16/10/20) Electrical students ONLY Design a class to represent the category Resistor (think of characteristics of resistors. For example: value, tolerance, power, manufacturer). Then write a program to display resistor characteristics. This code should be in an application class (a class with a main). Here you need to declare 3 objects of type Resistor with different characteristics, and then write code to do the following: Ask the user to indicate the voltage through each of the 3 resistors and calculate the nominal current (voltage/ resistor value) and the minimum and maximum current (depending on the tolerance), that is current = voltage /(resistor value at the min/max limit as affected by the tolerance) Submit: - the code (2 files, one for the Resistor class and one for the Current program) Submission NOTE: Put all the files into a .zip file and make sure that the name of the .zip file includes your student id number and name of submission - for example: 000112233Prac4.zip Aim Resources Programming Tasks Submission
Oct 20, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here