I need help making the adjustment to add to my java program that is pasted below
ID: 3711137 • Letter: I
Question
I need help making the adjustment to add to my java program that is pasted below " " to seperate the print statments please. Just need help making the edits to the print lines to all print out on a seperate line for each.
package configSetup;
import java.util.*;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
public class ConfigSetup {
static String[] type = new String[15];
static String[] name = new String[15];
static String[] os = new String[15];
static String[] version = new String[15];
static String[] source = new String[15];
static String[] eth = new String[15];
static String[] intface = new String[15];
static String[] subnet = new String[15];
static String[] netmask = new String[15];
public static void main(String[] args){
configSetup();
}
//Used to set of the print partial section of config file
public static void configSetup(){
printData();
printPartial();
}
//print all the input values according to type
public static void printData(){
for(int i = 0; i < type.length; i++){
if(type.equals("vm")){
System.out.println(type + " " + name[i] + " {");
System.out.println("os : " + os[i]);
System.out.println("ver : " + version[i]);
System.out.println("src : " + source[i]);
System.out.println("eth0 : " + eth[i]);
}
else if(type.equals("hub")){
System.out.println("inf : " + name + ".eth0");
System.out.println("Subnet: " + subnet[i]);
System.out.println("Netmask: " + netmask[i]);
}
}
}
//Used to set of the print partial section of config file
public static void printPartial(){
try (Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("C:\Users\Gabe\Desktop\School\Human Interfacing\TEST.cfg"), "utf-8"))) {
writer.write("partial_solution {");
for(int i = 0; i < type.length; i++){
if(name[i] != null && !name[i].isEmpty()){
writer.write("(" + name[i] + ".eth0 v3.vinf20)");
}
else {
break;
}
}
writer.write("}");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Explanation / Answer
import java.util.*;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
public class ConfigSetup {
static String[] type = new String[15];
static String[] name = new String[15];
static String[] os = new String[15];
static String[] version = new String[15];
static String[] source = new String[15];
static String[] eth = new String[15];
static String[] intface = new String[15];
static String[] subnet = new String[15];
static String[] netmask = new String[15];
public static void main(String[] args){
configSetup();
}
//Used to set of the print partial section of config file
public static void configSetup(){
printData();
printPartial();
}
//print all the input values according to type
public static void printData(){
for(int i = 0; i < type.length; i++){
if(type.equals("vm")){
System.out.println(type + " " + name[i] + " {" + " ");
System.out.println("os : " + os[i] + " ");
System.out.println("ver : " + version[i] + " ");
System.out.println("src : " + source[i] + " ");
System.out.println("eth0 : " + eth[i] + " ");
}
else if(type.equals("hub")){
System.out.println("inf : " + name + ".eth0" + " ");
System.out.println("Subnet: " + subnet[i] + " ");
System.out.println("Netmask: " + netmask[i] + " ");
}
}
}
//Used to set of the print partial section of config file
public static void printPartial(){
try (Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("C:\Users\Gabe\Desktop\School\Human Interfacing\TEST.cfg"), "utf-8"))) {
writer.write("partial_solution {" + " ");
for(int i = 0; i < type.length; i++){
if(name[i] != null && !name[i].isEmpty()){
writer.write("(" + name[i] + ".eth0 v3.vinf20)" + " ");
}
else {
break;
}
}
writer.write("}");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.