Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1103377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:20:05+00:00 2026-05-17T01:20:05+00:00

package javaapplication1; import java.io.*; /** * * @author simon */ public class Main {

  • 0
package javaapplication1;
 import java.io.*;
/**
 *
 * @author simon
 */
public class Main {


    /**
     * @param args the command line arguments
     */
       public static void main(String[] args) throws IOException {
            NotSimple[] objArray;
               BufferedReader stdin = new BufferedReader(
                                   new InputStreamReader( System.in ) );
            System.out.println( "Enter a number of objects:" );

            int size;
            size = Integer.parseInt( stdin.readLine() );

            //Initialize objArray
            objArray = new NotSimple[size];

            //TODO: Implement following functions

            initializeObj(objArray);
            increaseData(objArray);
            printObjData(objArray);

            //TODO: Explain all outputs of the below function
            explainOutputs();
            return;

                                                                 }

      //TODO
      //initialize every Notsimple object in the array 'a'
      //to NotSimple()
      //Hint: using the for loop, assign a[i] = new NotSimple();
      static void   initializeObj(NotSimple[] a){
      //TODO: FILL ME

          for (int i = 0; i < a.length; i++)
          {
          a[i] = new NotSimple();
          }

  }

  //TODO:
  //Increase the ‘data’ member of every NotSimple object
  //in the array ‘a’ by 1
  static void increaseData(NotSimple[] a) {
       //TODO: FILL ME

      for (int i = 0; i < a.length; i++)
      {
           a[i].setData(a[i].getData()+1);
      }

  }

  //TODO:
  //Print the data of every NotSimple object in the array ‘a’
  static void printObjData(NotSimple[] a) {
       //TODO: FILL ME
       for (int i = 0; i < a.length; i++)
          {
          System.out.println (a[i].getData());
          }

  }

  //TODO explain all the outputs 1a-1f
  static void explainOutputs() {
    NotSimple nsObj1 = new NotSimple();
    //1a
    System.out.println( "nsObj1.data is\t" + nsObj1.getData() );
    System.out.println( "nsObj1.str is \t" + nsObj1.getStr() );

    NotSimple nsObj2 = new NotSimple( 50,
                         "Another immutable string!" );
    //1b
    System.out.println( "nsObj2.data is\t" + nsObj2.getData() );
    System.out.println( "nsObj2.str is \t" + nsObj2.getStr() );

    nsObj2 = nsObj1;

    nsObj2.setData(10);
    nsObj1.setData(100);
    //1c
    System.out.println( "nsObj2.data is\t" + nsObj2.getData() );
    System.out.println( "nsObj2.str is \t" + nsObj2.getStr() );

    nsObj1 = new NotSimple();
    //1d
    System.out.println( "nsObj1.data is\t" + nsObj1.getData() );
    System.out.println( "nsObj1.str is \t" + nsObj1.getStr() );
    System.out.println( "nsObj2.data is\t" + nsObj2.getData() );
    System.out.println( "nsObj2.str is \t" + nsObj2.getStr() );

    nsObj2 = new NotSimple();
    //1e
    System.out.println( "nsObj2.data is\t" + nsObj2.getData() );
    System.out.println( "nsObj2.str is \t" + nsObj2.getStr() );

    nsObj2.setData(10);
    //1f
    System.out.println( "nsObj1.data is\t" + nsObj1.getData() );
    System.out.println( "nsObj1.str is \t" + nsObj1.getStr() );
    System.out.println( "nsObj2.data is\t" + nsObj2.getData() );
    System.out.println( "nsObj2.str is \t" + nsObj2.getStr() );
  }

}


class NotSimple
{
  NotSimple()
  {
    data = 5;
    str = new String( "Initialized!" );
  }

  NotSimple( int i, String str1 )
  {
    data = i;
    str = str1;
  }

  void setData( int i )
  {
    data = i;

    return;
  }

  int getData()
  {
   return data;
  }

  void setStr( String str1)
  {
    str = str1;

    return;
  }

  String getStr()
  {
    return str;
  }

  private int data;
  private String str;
}

I want to add 1 to the array but it doesn’t work. I get the following compilation error:

operator ++ cannot be applied to javaapplication1.NotSimple
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:20:06+00:00Added an answer on May 17, 2026 at 1:20 am

    Use

      for (int i = 0; i < a.length; i++)
      {
           a[i].setData(a[i].getData()+1);
      }
    

    Since Java does not support operator overloading, you’ll need to retrieve the old value (i.e. the getData() call), add 1 to it, and set it as the new value (i.e. the setData() call).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package javaapplication1; import java.io.*; public class Main { /** * @param args the command
package GC; import java.util.Scanner; public class main { public static void main(String args[]) {
package src; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Command { public static
package org.study.algos; public class Study { public static void main(String[] args) { A a
package macroreader; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class MacroReader { public static
package com.test01; public class test01 { public static void main(String[] args) { System.out.println(hi); }
package matlab; import com.mathworks.toolbox.javabuilder.*; import com.eigenface.Eigenface; public class Test { public static void main(String[]
package jtextareatest; import java.io.FileInputStream; import java.io.IOException; import javax.swing.*; public class Jtextareatest { public static
package javaLearning; import java.util.Arrays; import java.util.Collections; public class myarray { public static void name()
package threadwork; public class WorkingWithThreads implements Runnable { public static void main(String[] args) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.