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

Create a simple Java class for a Month object with the following requirements:  This program...
Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
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 language This is your first homework on objects and classes, and the basics of object-oriented...
Java language This is your first homework on objects and classes, and the basics of object-oriented programming. For each exercise, your task is to first write the class that defines the given object. Compile it and check it for syntax errors. Then write the “demo class” with the main program that creates and uses the object. a)You are planning to purchase a new motor boat for cool cruises on Porter’s Lake this summer, but you want to simulate it before...
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT