Question

i need to fix this java code. it not working on Repl.it website online compiler. error...

i need to fix this java code. it not working on Repl.it website online compiler.

error

-----------------------------------------------

 javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . Main.java
 java -classpath .:/run_dir/junit-4.12.jar:target/dependency/* Main
Exception in thread "main" java.io.FileNotFoundException: C:\\Users\\Carter Collins\\Downloads\\input.txt (No such file or directory)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
at java.base/java.io.FileInputStream.(FileInputStream.java:157)
at java.base/java.util.Scanner.(Scanner.java:639)
at Main.main(Main.java:18)
exit status 1

------------------------------------------------

codes::

import java.io.*;

import java.util.*;

public class Main {

public static void main(String[] args) throws Exception

{

Scanner scan = new Scanner(System.in);

Scanner sc = new Scanner(new File("C:\\\\Users\\\\Carter Collins\\\\Downloads\\\\input.txt"));

Random rand = new Random();

int Bank = 0;

int currentBet = 0;

int Select = 0;

String Fruit = "";

int currentWinning = 0;

char status = 'x';

int random1;

int random2;

int random3;

String fruits[] = {"Cherry", "Orange", "Apple", "Peach", "Melon", "Pear"};

System.out.println("Welcome to Carter Collins' Slot Machine!");

Bank = sc.nextInt();

System.out.println("You inserted $" + Bank + " into the slot machine.");

while(status == 'x' || status == 'X')

{

System.out.println("You currently have $" + Bank + " , you can bet with multiples of $10.");

System.out.println("If you enter 1, you will bet $10");

System.out.println("If you enter 2, you will bet $20, etc.");

System.out.println("Please enter how much you want to bet this time: ");

currentBet = scan.nextInt();

currentBet = currentBet * 10;

while(currentBet > Bank)

{

System.out.println("Sorry, you don't $" + currentBet + " now. You can only bet less than the amount of money you have.");

System.out.println("You currently have $" + Bank + " , you can bet the multiple of $10.");

System.out.println("If you enter 1, you will bet $10");

System.out.println("If you enter 2, you will bet $20, etc.");

System.out.println("Please enter how much do you want to bet this time: ");

currentBet = scan.nextInt();

}

System.out.println("Your current bet: $" + currentBet);

System.out.println("Please select one of the fruit by entering a number between 1 and 6:");

System.out.println("1 - Cherry");

System.out.println("2 - Orange");

System.out.println("3 - Apple");

System.out.println("4 - Peach");

System.out.println("5 - Melon");

System.out.println("6 - Pear");

System.out.println("Please enter your selection: ");

Select = scan.nextInt();

while(Select > 6 || Select < 1)

{

System.out.println("Invalid selection. you must enter a number between 1 and 6 inclusive.\n");

System.out.println("Please select one of the fruit by entering a number between 1 and 6:");

System.out.println("1 - Cherry");

System.out.println("2 - Orange");

System.out.println("3 - Apple");

System.out.println("4 - Peach");

System.out.println("5 - Melon");

System.out.println("6 - Pear");

System.out.println("Please enter your selection: ");

Select = scan.nextInt();

}

Fruit = fruits[Select - 1];

random1 = rand.nextInt(5) + 1;

random2 = rand.nextInt(5) + 1;

random3 = rand.nextInt(5) + 1;

System.out.println("Result: " + fruits[random1] + " " + fruits[random2] + " " + fruits[random3]);

if(fruits[random1] == Fruit)

{

currentWinning = currentWinning + currentBet;

}

if(fruits[random2] == Fruit)

{

currentWinning = currentWinning + currentBet;

}

if(fruits[random3] == Fruit)

{

currentWinning = currentWinning + currentBet;

}

if(fruits[random1] != Fruit && fruits[random2] != Fruit && fruits[random3] != Fruit)

{

System.out.println("None of the randomly selected words matched your selection. You won $0");

Bank = Bank - currentBet;

currentBet = 0;

}

if(currentWinning > 0)

{

System.out.println("You have won $" + currentWinning);

Bank = Bank + currentWinning;

currentWinning = 0;

}

PrintWriter out = new PrintWriter("input.txt");

out.println(Bank);

out.close();

System.out.println("Do you want to continue playing (y/Y) or quit (n/N):");

status = scan.next().charAt(0);

while(status != 'y' && status != 'n' && status != 'N' && status != 'Y')

{

System.out.println("Invaild choice!!! Please enter y or Y to play, n or N to quit: Do you want to \n continue playing (y/Y) or quit (n/N): ");

status = scan.next().charAt(0);

}

if(status == 'n' || status == 'N'){

System.out.println("Thank you for choosing Carter Collins' Slot Machine! Good bye!");

}

}

}

}

Homework Answers

Answer #1

there is a run time exception file not found in line :7 that means the location which you have given in line :7 is not available in computer directory.

please ensure first that the file should be available.

Exception in thread "main" java.io.FileNotFoundException: C:\Users\Carter Collins\Downloads\input.txt (The system cannot find the path specified)
   at java.io.FileInputStream.open0(Native Method)
   at java.io.FileInputStream.open(Unknown Source)
   at java.io.FileInputStream.<init>(Unknown Source)
   at java.util.Scanner.<init>(Unknown Source)
   at Main.main(Main.java:15)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8 13 21 34 55 ....... and also need add code complexity time if you want! here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[ n + 1 ]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for ( i = 2; i < n; i++ ) { fib[ i ] = fib[ i -...
Refactor the following program to use ArrayList instead of Arrays. You can google "Java ArrayList" or...
Refactor the following program to use ArrayList instead of Arrays. You can google "Java ArrayList" or start with the link below: https://www.thoughtco.com/using-the-arraylist-2034204 import java.util.Scanner; public class DaysOfWeeks { public static void main(String[] args) { String DAY_OF_WEEKS[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; char ch; int n; Scanner scanner = new Scanner(System.in); do { System.out.print("Enter the day of the Week: "); n = scanner.nextInt() - 1; if (n >= 0 && n <= 6) System.out.println("The day of the week is " + DAY_OF_WEEKS[n] + ".");...
in java need uml diagram import java.util.ArrayList; import java.util.*; public class TodoList { String date=""; String...
in java need uml diagram import java.util.ArrayList; import java.util.*; public class TodoList { String date=""; String work=""; boolean completed=false; boolean important=false; public TodoList(String a,String b,boolean c,boolean d){ this.date=a; this.work=b; this.completed=c; this.important=d; } public boolean isCompleted(){ return this.completed; } public boolean isImportant(){ return this.important; } public String getDate(){ return this.date; } public String getTask(){ return this.work; } } class Main{ public static void main(String[] args) { ArrayList<TodoList> t1=new ArrayList<TodoList>(); TodoList t2=null; Scanner s=new Scanner(System.in); int a; String b="",c=""; boolean d,e; char...
/* This program should check if the given integer number is prime. Reminder, an integer number...
/* This program should check if the given integer number is prime. Reminder, an integer number greater than 1 is prime if it divisible only by itself and by 1. In other words a prime number divided by any other natural number (besides 1 and itself) will have a non-zero remainder. Your task: Write a method called checkPrime(n) that will take an integer greater than 1 as an input, and return true if that integer is prime; otherwise, it should...
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
In java just need work in the billards class it is in bold everything else is...
In java just need work in the billards class it is in bold everything else is done just the sections marked TODO Suppose that you have several numbered billiard balls on a pool table. The smallest possible number on the ball is “1”. At each step, you remove a billiard ball from the table. If the ball removed is numbered n, you replace it with n balls randomly numbered less than n. For example, if you remove the “5” ball,...
(Use Java ) please write comment on every line I need to understand the code Problem...
(Use Java ) please write comment on every line I need to understand the code Problem Description: Write a program that prompts the user to enter a point (x, y) and checks whether the point is within the rectangle centered at (0, 0) with width 10 and height 5. For example, (2, 2) is inside the rectangle and (6, 4) is outside the rectangle, as shown in the Figure. (Hint: A point is in the rectangle if its horizontal distance...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT