0
package com.company;
import java.lang.reflect.Type;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
    // write your code here
        Scanner nameInput = new Scanner(System.in);
        
        System.out.printf("As of right now I noticed you have not selected a weapon. Please choose from the following selections that I recommend, I current have no information on your shooting style.\nSo these recommendations are based souly on beginner levels.");
        System.out.printf(Gun.Type);
    }
}

Then the other one. Guns.Java

import java.io.PrintStream;

class Guns {
    public String Type() {

        return gunList;
    }
    public String gunList(){
        String Arctic = "Arctic Warfare (L96A1)";
        String secondArctic = "Arctic Warfare Magnum";
        String AW50 = "AW50";
        String AS50 = "AS50";
        System.out.printf(" %s \n %s\n %s\n %s \n", Arctic, secondArctic, AW50, AS50);
    }
}

This is just for fun and also to learn faster. Im trying to display a list of the Guns the user is order to use then after I get the printf done I was going to make a input thing (not sure what that is yet idk if I forgot or wasnt taught) then store it in another String in the main CS. But im not sure what im doing wrong here.

I just want to post the Gun list on the printf on the first page using the method I learned from Treehouse.come but cant figure it out for whatever reason.

Hex
  • 13
  • 3
  • What is `String Selection = gunList` supposed to do in your method declaration? That is not valid java. When declaring a method you only declare its signature. An assignment via `=` in a method signature makes little sense. – OH GOD SPIDERS May 07 '21 at 14:40
  • 3
    Also note that your method `gunList` does not return anything (return type is `void`). So you cannot assign that "nothing" to a variable as in `var someVar = gunList(); // will not work` – OH GOD SPIDERS May 07 '21 at 14:41
  • What you probably want to do: 1. delete the `public static void Type` method. 2. create a [main method that serves as an entry point to your program](https://stackoverflow.com/questions/20559037/what-is-the-main-method) 3. call your static gunList method from that main method `Guns.gunList();` 4. run your program. – OH GOD SPIDERS May 07 '21 at 14:47
  • I already have a main in another CS that runs as { public static void main(String[] args) [ // write your code here Scanner nameInput = new Scanner(System.in); System.out.println("Hello, I am your Formatical Analzical Invirmental robotical Interface, other wise known as 'F.A.I.R.I'. \n " + "Since you are not in a incapacitated state this means your mind is able to hold two consciousness. \n");] – Hex May 07 '21 at 14:49
  • 1
    Please show us a [mre]; realize that "reproducible" is at least as important as "minimal". We need enough code that we can compile and run it. I'd remove the jokes and just put the minimal print statements in there to show what needs to be shown. – NomadMaker May 07 '21 at 15:10
  • Also, it should be noted that List is a specific term in Java, referring to one of the main interfaces in the Collections framework that is mostly implemented by the ArrayList class. – NomadMaker May 07 '21 at 15:11
  • @Hex I was merely giving you an example of how you could call your method. If you already have main method somewhere else and want to call that method from there, then there is nothing stopping you from just calling `Guns.gunList();` from wherever you want to including that other main method. – OH GOD SPIDERS May 07 '21 at 15:27

1 Answers1

0

You have multiple problems with your code example. Here are a few.

The gunList method is declared as returning a String. But you do not return a string. Instead you print to System.out, a PrintStream object. Change that to capture the generated text as a String. See Sprintf equivalent in Java. Return that string object using the return keyword.

There is no need for the public String Type() {. (Also, methods in Java should be named starting with a lowercase letter.) Just instantiate a Guns object, and call gunList method. (Also, using “list” here in this method name is a poor choice, as that word has a specific commonly-used meaning in Java.)

Guns guns = new Guns();
String output = guns.gunsList();
System.out.println( output ) ;

Your main method should be calling System.out.println rather than printf as you are not doing any formatting in those lines.


I suggest you spend more time reading code. Study the Java Tutorials by Oracle, provided free of cost. Peruse existing Questions and Answers here on Stack Oveflow. Read some blog postings.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154