Part I:
Part II
Part 1
public class Source {
public static void main(String[] args) {
int[] arr = new int[10];
for (int i = 0; i < 10; i++) {
arr[i] = (i + 1) * 5;
}
int sum = arr[1] + arr[4] + arr[6];
System.out.println("Sum of second, fifth and seventh element : " + sum);
arr[3] = 86;
arr[8] -= 9;
for(int x : arr){
System.out.print(x + " ");
}
}
}
Output
Sum of second, fifth and seventh element : 70
5 10 15 86 25 30 35 40 36 50
Process finished with exit code 0
Part 2
class Vehicle {
int basePrice, additionalFeatures;
Vehicle() {
}
Vehicle(int base, int add) {
basePrice = base;
additionalFeatures = add;
}
public String toString() {
return "Base price : " + basePrice + ", " + "Additional Features : " + additionalFeatures;
}
}
public class Source {
public static void main(String[] args) {
Vehicle[] v = new Vehicle[7];
for (int i = 0; i < 4; i++) {
v[i] = new Vehicle();
}
Vehicle v5 = new Vehicle(37000, 400);
v[4] = v5;
v[5] = new Vehicle(24000, 5500);
v[6] = new Vehicle(53000, 9000);
int price = 0;
for (int i = 4; i < 7; i++) {
price += (v[i].basePrice + v[i].additionalFeatures);
}
System.out.println("Total price of fifth, sixth and seventh vehicles is : " + price);
for (Vehicle vh : v) {
System.out.println(vh.toString());
}
}
}
Output
Total price of fifth, sixth and seventh vehicles is : 128900
Base price : 0, Additional Features : 0
Base price : 0, Additional Features : 0
Base price : 0, Additional Features : 0
Base price : 0, Additional Features : 0
Base price : 37000, Additional Features : 400
Base price : 24000, Additional Features : 5500
Base price : 53000, Additional Features : 9000
Process finished with exit code 0
Part I: Create a program class named TestArrays This class should have a main() method that...
create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...
Java Equals and Copy method activity Implement a Dog class with the following features: + Attributes: age, gender, weight + Method: constructor, copy constructor, equals (if same weight and gender), toString + A main method/driver that create an array of 5 Dog objects (obtain input from user), and then display the objects that are "equal" Equals and Copy method activity Implement a Dog class with the following features: + Attributes: age, gender, weight + Method: constructor, copy constructor, equals (if...
In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....
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...
Write a c# console program called “ArrayOfThings” where you create a class called Staff with private fields for StaffID and StaffName. Create Properties that can write data and retrieve data from these private fields. Create a Staff array that can hold up to ten Staff objects. Create ten objects using a for loop that automatically creates a new (empty) Staff object at each iteration of the loop and adds that object into the Staff array. Write data into the first...
Python programming I need help with the following: Create a class Vehicle. The class should have name, weight, fuel, number of wheels and move attributes/methods. Create child class that are semi, car, sail boat and bicycle. Give the class the ability to have a constructor that sets the name. Have the other attributes hard coded to suit the vehicle. Give each a way of speaking their attributes as well as the type of animal. For example “Hi I am Lightening...
Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...
public class EmployeeDriver public static void main(String[] args) 1/declare create an Employee object named joo. Une no-arg constructor 1/change the attributes for joe as the following: //name to Joe Cool, id to 1111111, hours to 20, pay rate to 15 //dealare & create another Employee oblegt named one using arg-constructor // The name of the new employees Jane Doeid is 2001122. She makes $10.50/hour // change the object Jane's hours to 40. 1/change the object jane's pay rate to $12.00....
Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.Using the Accountclass as a base class, write two derived classes called SavingsAccountand CurrentAccount.ASavingsAccountobject, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. ACurrentAccount object, in addition to the instance variables of an Account object, should have an overdraft limit variable. Ensure...
java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array of 1000 integers. Name the array: x 2. Assign 95 to the ninth element, 25 to the twentieth element of array x. 3. Assign the sum of the ninth and the twentieth element to the sixtieth element of array x. 4. Display the sixtieth element of the array. 5. Use the for statement to generate all indexes to read and display all elements in...