online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
import java.util.Scanner; public class Main { private String genre; private String title; private String time; private double cost; private int theConfirmationNo; private int confirmationNo = (int)(Math.random() * 1000) + 135343; private static Scanner console = new Scanner(System.in); public void setGenre(String genre){ this.genre = genre.toUpperCase(); } public void setTitle(String title){ this.title = title.toUpperCase(); } public void setTime(String time){ this.time = time; } public void setCost(double cost){ this.cost = cost; } public double getCost(){ return cost; } public String getTitle(){ return title; } public String getGenre(){ return genre; } public String getTime(){ return time; } public int getConfirmationNo(){ theConfirmationNo = confirmationNo; return theConfirmationNo; } @Override public String toString(){ String ticket = String.format("****************************************************************************" + "\nYour ticket purchase\nGenre: " + genre + "\nTitle: " + title + "\nTime: " + time + "\nPrice: " + "$%.2f" + "\nConfirmation Number: " + confirmationNo + "\n" + "****************************************************************************", cost); return ticket; } public static void sleepTimer(int timeToSleep){ try{ Thread.sleep(timeToSleep); }catch(InterruptedException e){ e.toString(); } } public static void showEnums(){ System.out.println("Movie Genres:"); for(Prac p : Prac.values()){ sleepTimer(1000); System.out.println(p + " "); sleepTimer(1000); } System.out.println(); for(Prac p : Prac.values()){ System.out.println(p + ": Movie Titles:"); sleepTimer(1000); System.out.println(p.printArr()); } for(Prac p : Prac.values()){ System.out.println(p + ": Movie Times:"); sleepTimer(1000); System.out.println(p.printTimes()); } } public static void initiate(Main obj) throws InterruptedException { System.out.println("Would you like to see our movie options?"); System.out.println("Key in \"Y\" for yes and \"N\" for no."); String answer = console.nextLine(); if(answer.equalsIgnoreCase("y")){ showEnums(); System.out.println(); keyTitle(obj); }//if selection equals no tie in the program initially made } public static void keyTitle(Main obj) throws InterruptedException { Scanner console = new Scanner(System.in); System.out.println("Type in a Genre:"); String genre = console.nextLine(); boolean isPresent = false; Prac pp = null; for(Prac p : Prac.values()){ if(genre.equalsIgnoreCase(p.name())){ pp = p; isPresent = true; break; } } if(isPresent){ obj.setGenre(genre); validateTitle(pp, obj); }else{ System.out.println("You have entered an invalid entry. Try again."); try{ Thread.sleep(1000); }catch(InterruptedException ie){ ie.toString();//ie.printStackTrace(); } keyTitle(obj); } } public static void validateTitle(Prac p, Main obj) throws InterruptedException { Scanner console = new Scanner(System.in); System.out.println("Type in a movie title:"); String title = console.nextLine(); boolean validator = false; validator = p.selectMovie(title); if(validator){ obj.setTitle(title); selectTime(p, obj); } if(validator){ }else{ System.out.println("There is no movie with this title. Try again."); validateTitle(p, obj); } } public static void selectTime(Prac p, Main obj) throws InterruptedException { System.out.println(p.printTimes()); Scanner console = new Scanner(System.in); System.out.println("There are six time slots. Please enter a number between 1 & 6 to select the time slot you would like."); int timeSlot = console.nextInt(); if(timeSlot > 0 && timeSlot <= 6){ obj.setTime(p.bookSlot(timeSlot)); selectNumberOfAttendees(p, obj); }else{ System.out.println("You have entered an invalid integer. Try again."); selectTime(p, obj); } } public static void selectNumberOfAttendees(Prac p, Main obj) throws InterruptedException { Scanner console = new Scanner(System.in); System.out.println("How many will be attending?"); int numberOfAttentees = console.nextInt(); obj.setCost(p.calculateCost(numberOfAttentees)); System.out.println("Your ticket purchase was successful and your confirmation number for your purchase is on your ticket"); sleepTimer(3000); System.out.print(obj.toString()); } public static void main(String[] args) throws InterruptedException { Main obj = new Main(); initiate(obj); } }
public enum Prac { HORROR(){ String[] movies = {"Holloween", "Final Destination", "Resident Evil", "Thirty Days of Night", "The Wicked"}; String[] movieTime = {"2:00pm", "3:00pm", "5:00pm", "7:00pm", "9:00pm", "11:00pm"}; double price = 9.50; public String printArr(){ for(int i = 0; i < movies.length; i++){ System.out.println(movies[i] + " "); Main.sleepTimer(1000); } return ""; } public String printTimes(){ for(int i = 0; i < movieTime.length; i++){ System.out.print(movieTime[i] + " "); Main.sleepTimer(1000); } return ""; } public boolean selectMovie(String selection){ for(int i = 0; i < movies.length; i++){ if(((String)movies[i]).equalsIgnoreCase(selection)){ return true; } } return false; } public String bookSlot(int timeSlot){ return (String)movieTime[timeSlot - 1]; } public double calculateCost(int numberOfAttentees){ return (double)price * numberOfAttentees; } }, COMEDY(){ String[] movies = {"The Bucket List", "Def Comedy Jam", "Rescue From Gilligan's Island", "Easy Money", "The Hustle"}; String[] movieTime = {"2:30pm", "3:30pm", "5:30pm", "7:30pm", "9:30pm", "11:30pm"}; double price = 9.50; public String printArr(){ for(int i = 0; i < movies.length; i++){ System.out.println(movies[i] + " "); Main.sleepTimer(1000); } return ""; } public String printTimes(){ for(int i = 0; i < movieTime.length; i++){ System.out.print(movieTime[i] + " "); Main.sleepTimer(1000); } return ""; } public boolean selectMovie(String selection){ for(int i = 0; i < movies.length; i++){ if(((String)movies[i]).equalsIgnoreCase(selection)){ return true; } } return false; } public String bookSlot(int timeSlot){ return (String)movieTime[timeSlot - 1]; } public double calculateCost(int numberOfAttentees){ return (double)price * numberOfAttentees; } }, ROMANCE(){ String[] movies = {"Love Don't Cost a Thing", "Step Up All In", "The Blue Lagoon", "The Choice", "A Spare Room"}; String[] movieTime = {"12:10pm", "2:10pm", "4:10pm", "6:10pm", "8:10pm", "10:10pm"}; double price = 9.50; public String printArr(){ for(int i = 0; i < movies.length; i++){ System.out.println(movies[i] + " "); Main.sleepTimer(1000); } return ""; } public String printTimes(){ for(int i = 0; i < movieTime.length; i++){ System.out.print(movieTime[i] + " "); Main.sleepTimer(1000); } return ""; } public boolean selectMovie(String selection){ for(int i = 0; i < movies.length; i++){ if(((String)movies[i]).equalsIgnoreCase(selection)){ return true; } } return false; } public String bookSlot(int timeSlot){ return (String)movieTime[timeSlot - 1]; } public double calculateCost(int numberOfAttentees){ return (double)price * numberOfAttentees; } }, ACTION(){ String[] movies = {"Under Siege", "The Long Kiss Goodnight", "Edge of Extinction", "Collateral Damage", "The Legend of Hercules"}; String[] movieTime = {"11:45am", "1:45pm", "3:45pm", "5:45pm", "7:45pm", "9:45pm"}; double price = 9.50; public String printArr(){ for(int i = 0; i < movies.length; i++){ System.out.println(movies[i] + " "); Main.sleepTimer(1000); } return ""; } public String printTimes(){ for(int i = 0; i < movieTime.length; i++){ System.out.print(movieTime[i] + " "); Main.sleepTimer(1000); } return ""; } public boolean selectMovie(String selection){ for(int i = 0; i < movies.length; i++){ if(((String)movies[i]).equalsIgnoreCase(selection)){ return true; } } return false; } public String bookSlot(int timeSlot){ return (String)movieTime[timeSlot - 1]; } public double calculateCost(int numberOfAttentees){ return (double)price * numberOfAttentees; } }, ADVENTURE(){ String[] movies = {"Gods of Egypt", "The Last Witch Hunter", "The Hunger Games: Mockingja", "10,000 BC", "Lost in Space"}; String[] movieTime = {"12:15pm", "1:15pm", "2:15pm", "3:15pm", "4:15pm", "5:15pm"}; double price = 9.50; public String printArr(){ for(int i = 0; i < movies.length; i++){ System.out.println(movies[i] + " "); Main.sleepTimer(1000); } return ""; } public String printTimes(){ for(int i = 0; i < movieTime.length; i++){ System.out.print(movieTime[i] + " "); Main.sleepTimer(1000); } return ""; } public boolean selectMovie(String selection){ for(int i = 0; i < movies.length; i++){ if(((String)movies[i]).equalsIgnoreCase(selection)){ return true; } } return false; } public String bookSlot(int timeSlot){ return (String)movieTime[timeSlot - 1]; } public double calculateCost(int numberOfAttentees){ return (double)price * numberOfAttentees; } }, CRIME(){ String[] movies = {"A Man Apart", "New Jack City", "Cradle 2 the Grave", "I Am Wrath", "Murder at 1600"}; String[] movieTime = {"2:40 pm", "3:40 pm", "5:40 pm", "7:40 pm", "9:40 pm", "11:40 pm"}; double price = 9.50; public String printArr(){ for(int i = 0; i < movies.length; i++){ System.out.println(movies[i] + " "); Main.sleepTimer(1000); } return ""; } public String printTimes(){ for(int i = 0; i < movieTime.length; i++){ System.out.print(movieTime[i] + " "); Main.sleepTimer(1000); } return ""; } public boolean selectMovie(String selection){ boolean isPresent = false; for(int i = 0; i < movies.length; i++){ if(((String)movies[i]).equalsIgnoreCase(selection)){ isPresent = true; return isPresent; } } return false; } public String bookSlot(int timeSlot){ return (String)movieTime[timeSlot - 1]; } public double calculateCost(int numberOfAttentees){ return (double)price * numberOfAttentees; } }; private String[] movies; public abstract String printArr(); public abstract String printTimes(); public abstract boolean selectMovie(String selection); public abstract String bookSlot(int timeSlot); public abstract double calculateCost(int numberOfAttentees); }
public enum Planet { MERCURY (3.303e+23, 2.4397e6), VENUS (4.869e+24, 6.0518e6), EARTH (5.976e+24, 6.37814e6), MARS (6.421e+23, 3.3972e6), JUPITER (1.9e+27, 7.1492e7), SATURN (5.688e+26, 6.0268e7), URANUS (8.686e+25, 2.5559e7), NEPTUNE (1.024e+26, 2.4746e7); private final double mass; // in kilograms private final double radius; // in meters Planet(double mass, double radius) { this.mass = mass; this.radius = radius; } private double mass() { return mass; } private double radius() { return radius; } // universal gravitational constant (m3 kg-1 s-2) public static final double G = 6.67300E-11; double surfaceGravity() { return G * mass / (radius * radius); } double surfaceWeight(double otherMass) { return otherMass * surfaceGravity(); } public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: java Planet <earth_weight>"); System.exit(-1); } double earthWeight = Double.parseDouble(args[0]); double mass = earthWeight/EARTH.surfaceGravity(); for (Planet p : Planet.values()) System.out.printf("Your weight on %s is %f%n", p, p.surfaceWeight(mass)); } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue