Question

In: Computer Science

// SET5. Write a Java statement that changes the month of the first object of this...

// SET5. Write a Java statement that changes the month of the first object of this array to be a copy of the month

// of the last object of the array. (Assign the month of the last object to the month of the first object).

// SET6. Write a segment of code to swap the first and the second objects in this array. Declare any additional

// variable you might need.  

Solutions

Expert Solution

Program Code [JAVA]

import java.util.Arrays;

public class Statement {

public static void main(String[] args) {

// SET 5
// First we need to have an array of months

String[] months = {"Jan", "Feb", "March", "April",
"May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec"};

// Showing array before changing first object with last object

System.out.println("**** SET 5 ****");
System.out.println("\nBefore copying last object in first object");
System.out.println(Arrays.toString(months));

// Now Copying - set5

months[0] = months[months.length-1]; // answer of set5

System.out.println("\nAfter copying last object in first object");
System.out.println(Arrays.toString(months));

// Swapping first and second objects

String temp = months[0]; // answer of set6
months[0] = months[1];
months[1] = temp;

System.out.println("\n**** SET 6 ****");
System.out.println("\nAfter swapping the first and second objects");
System.out.println(Arrays.toString(months));
}
}

Sample Output:-

----------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERIES!!!
HIT A THUMBS UP IF YOU DO LIKE IT!!!


Related Solutions

This for Java Programming Write a java statement to import the java utilities. Create a Scanner...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner object to read input. int Age;     Write a java statement to read the Age input value 4 . Redo 1 to 3 using JOptionPane
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date...
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date object, a ClockWithAudio object, a BMI object, a Day object, and a FigurePane object. Then display all elements in the list. Assume that all classes (i.e. Date, Account, etc.) have their own no-argument constructor.
Prepare multiple step income statement and statement of changes in owner's equity for the month Jan-1...
Prepare multiple step income statement and statement of changes in owner's equity for the month Jan-1 The JW-Corp Received $120,000 from Investors in Exchange for 6,000 shares of Common Stock. Jan-2 JW-Corp Borrowed $150,000 from SCHWAB BANK and signed a Note Due in 24 months. Jan-3 JW Corp purchased Office Equipment worth $120,000 (5 year life), with a $40,000 Down payment of Cash and the remainder Due on account to Target-Corp within 9 Months. Jan-4 JW Corp purchased an Office...
CODE IN JAVA: Write a ProductTester class that creates one Product object named "Juicer" with a...
CODE IN JAVA: Write a ProductTester class that creates one Product object named "Juicer" with a price of $50.99, prints the name and price of the product, reduces its price by 4.0, and then prints its price again. public class Product { private String name; private double price; public Product(String productName, double productPrice) { name = productName; price = productPrice; } public String getName() { return name; } public double getPrice() { return price; } public void reducePrice(double amount) {...
Write a program in Java Using object Orientation Design to determine the status of Mini Van...
Write a program in Java Using object Orientation Design to determine the status of Mini Van Doors. A logical circuit receives a different binary code to allow opening different doors. The doors can be opened by a dashboard switch, inside or outside handle. The inside handle will not open the door if the child safety lock is on or the master lock is on. The gear shift must be in the park to open the door. A method must be...
Write a program in Java Using object Orientation Design to determine the status of Mini Van...
Write a program in Java Using object Orientation Design to determine the status of Mini Van Sliding Doors. A logical circuit receives a different binary code to allow opening different doors. The doors can be opened by a dashboard switch, inside or outside handle. The inside handle will not open the door if the child safety lock is on or the master lock is on. The gear shift must be in the park to open the door. A method must...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used to hold the rectangle’s width....
Write a program in Java Using object Orientation Design to determine the status of Mini Van...
Write a program in Java Using object Orientation Design to determine the status of Mini Van Sliding Doors. A logical circuit receives a different binary code to allow opening different doors. The doors can be opened by a dashboard switch, inside or outside handle. The inside handle will not open the door if the child safety lock is on or the master lock is on. The gear shift must be in the park to open the door. A method must...
Use Java (Find the number of days in a month) Write a program that prompts the...
Use Java (Find the number of days in a month) Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, If the user entered month 2 and year 2012, the program should display that February 2012 has 29 days. If the user entered month 3 and year 2015, the program should display that March 2015 has 31 days. Sample Run 1 Enter a month in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT