This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
7
Help to make a Java code cleaner
Post Flair (click to view more posts with a particular flair)
Post Body
Im learning Java and I did one exercise that consists in reading the input of the user(name of the network and date of the report) and return the csv that was inputed by the user. I know that the code is far from clean but I dont know how to make it cleaner and is so far working. So Ibasically need help and suggestions on how to write a cleaner code.
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Objects;
import java.util.Scanner;
import java.io.*;
import java.net.*;
public class App {
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(System.in);
System.out.println("Choose the network between supernetwork or adumbrella");
System.out.print("Selection: ");
String userInput = input.nextLine();
String date = "";
if (userInput.equals("supernetwork")) {
System.out.println("Choose the month and date on the MM-DD format");
System.out.print("Date: ");
date = input.nextLine();
}
if (date.equals("09-15")) {
URL adnetwork = new URL("/expertise-test/supernetwork/report/daily/2017-09-15.csv");
URLConnection yc = adnetwork.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
try {
System.out.println("Daily Report");
} catch (Exception e) {
System.out.println(e);
}
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
} else if (date.equals("09-16")) {
URL adnetwork = new URL("expertise-test/supernetwork/report/daily/2017-09-16.csv");
URLConnection yc = adnetwork.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
try {
System.out.println("daily_report");
} catch (Exception e) {
System.out.println(e);
}
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
} else if (userInput.equals("adumbrella")){
System.out.println("Choose the month and date on the MM-DD format");
System.out.print("Date: ");
date = input.nextLine();
if(date.equals("09-15")) {
URL adnetwork = new URL("expertise-test/reporting/adumbrella/adumbrella-15_9_2017.csv");
URLConnection yc = adnetwork.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
try {
System.out.println("Daily Report");
} catch (Exception e) {
System.out.println(e);
}
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
} else if (date.equals("09-16")) {
URL adnetwork = new URL("/expertise-test/reporting/adumbrella/adumbrella-16_9_2017.csv");
URLConnection yc = adnetwork.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
try {
System.out.println("daily_report");
} catch (Exception e) {
System.out.println(e);
}
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
}}
Author
Account Strength
90%
Account Age
4 years
Verified Email
Yes
Verified Flair
No
Total Karma
4,351
Link Karma
452
Comment Karma
3,791
Profile updated: 2 weeks ago
Posts updated: 8 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/codereview/...