So I'm not sure how to make the appropriate method call. I created all the following code below according to some of the stuff that I know and according to what I was asked for of the assignment. I did another assignment on assigning method calls to a main method but it was with integers not with scanner class or most of the content in this assignment. I was able to figure out most of what I needed except this. If there is anything else wrong with my code please tell me. Any help would be appreciated. This is for a class assignment. Thank you for your help. I tried this:
import java.util.*;
import java.util.Scanner;
public class Dba {
public static void printTicket (String name, String id, double price)
{
Random num = new Random();
Scanner input = new Scanner(System.in);
int x = 1000;
int age;
String space="";
String firstResponder;
String veteran;
System.out.println("Please enter your first name and last name, separated by a space:");
name=input.nextLine();
System.out.println("Are you a first responder?");
firstResponder=input.nextLine();
System.out.println("Are you a veteran?");
veteran=input.nextLine();
int randomNumber=num.nextInt(x)+1;
space += name.charAt(0);
int index=0;
for(int i=0;i<name.length();i++)
{
if(name.charAt(i)==' ')
{
index=i;
break;
}
}
for(int i=index+1;i<name.length();i++)
{
space+=name.charAt(i);
}
System.out.println("Please Enter your Age: ");
age=input.nextInt();
if (age<3)
{
price=2;
}
else if(age>=3 && age<=5)
{
price=9;
}
else if(age>=6 && age<=18)
{
price=11;
}
else
{
price=12;
}
if(firstResponder.equals("yes") && age>18)
{
price=price*0.5;
System.out.println("Because you are a first responder with over 18 years of age you get a 50% discount");
}
if(veteran.equals("yes") && age>18)
{
price=price*0.5;
System.out.println("Because you are a veteran with over 18 years of age you get a 50% discount");
}
System.out.println("Welcome to APCS Carnival, " + name +"!");
System.out.println("Your User ID is " + id);
System.out.println("The cost of your ticket is $" + price + ".");
System.out.println("Have a great time at the APCS Carnival today!");
}
public static void main(String[] args)
{
printTicket();
}
}
Aucun commentaire:
Enregistrer un commentaire