Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello Expert - Please Help Exercise : Write a program in C or C++ or Java to dis

ID: 3559158 • Letter: H

Question

Hello Expert - Please Help

Exercise : Write a program in C or C++ or Java to display the following information.

1. General information. In this section you will assemble some basic facts about the system

a. Machine name (hostname) # get this information from /proc/sys/kernel/hostname

b. System date and time # get this information from /proc/driver/rtc

c. Kernel version # get this information from /proc/version

d. Memory usage (used and free memory) # get this information from /proc/meminfo

2. Time information.

In this section you will print out how long the system has been up and how busy it has been.

a. Duration of uptime # get these information from /proc/uptime

b. Duration of idletime

The skeleton of the program (1) read file "/proc/uptime" to obtain Totaltime and Idletime

(2) read file "/proc/sys/kernel/hostname" to obtain the hostname

(3) read file "/proc/version" to obtain the kernel version

(4) read file "/proc/meminfo" to obtain the amount of used memory and free memory

(5) read file "/proc/driver/rtc" to obtain time and date

NOTE: Proper documentation and comments are required

Explanation / Answer

import java.util.*;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class GetIPAddressAndHostnameFromLocalMachine {
  
   public static void main(String[] args) {
      
       try {
          
           InetAddress inetAddr = InetAddress.getLocalHost();
          
           byte[] addr = inetAddr.getAddress();

           // Convert to dot representation
           String ipAddr = "";
           for (int i = 0; i < addr.length; i++) {
               if (i > 0) {
                   ipAddr += ".";
               }
               ipAddr += addr[i] & 0xFF;
           }
          
           String hostname = inetAddr.getHostName();
          
           System.out.println("IP Address: " + ipAddr);
           System.out.println("Hostname: " + hostname);
      
       }
       catch (UnknownHostException e) {
           System.out.println("Host not found: " + e.getMessage());
       }
      
   }

}


public class Main {
public static void main(String[] args) {


int day, month, year;
int second, minute, hour;
GregorianCalendar date = new GregorianCalendar();

day = date.get(Calendar.DAY_OF_MONTH);
month = date.get(Calendar.MONTH);
year = date.get(Calendar.YEAR);

second = date.get(Calendar.SECOND);
minute = date.get(Calendar.MINUTE);
hour = date.get(Calendar.HOUR);

System.out.println("Current date is "+day+"/"+(month+1)+"/"+year);
System.out.println("Current time is "+hour+" : "+minute+" : "+second);

/* Total number of processors or cores available to the JVM */
System.out.println("Available processors (cores): " +
Runtime.getRuntime().availableProcessors());

/* Total amount of free memory available to the JVM */
System.out.println("Free memory (bytes): " +
Runtime.getRuntime().freeMemory());

/* This will return Long.MAX_VALUE if there is no preset limit */
long maxMemory = Runtime.getRuntime().maxMemory();
/* Maximum amount of memory the JVM will attempt to use */
System.out.println("Maximum memory (bytes): " +
(maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));

/* Total memory currently available to the JVM */
System.out.println("Total memory available to JVM (bytes): " +
Runtime.getRuntime().totalMemory());

/* Get a list of all filesystem roots on this system */
File[] roots = File.listRoots();

/* For each filesystem root, print some info */
for (File root : roots) {
System.out.println("File system root: " + root.getAbsolutePath());
System.out.println("Total space (bytes): " + root.getTotalSpace());
System.out.println("Free space (bytes): " + root.getFreeSpace());
System.out.println("Usable space (bytes): " + root.getUsableSpace());
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote