2
當前正在爲uni創建一個銷售頁面,以便爲奧林匹克門票創建一個銷售頁面。這只是基本的,但我想知道如何使用位於菜單類 中的購買類中的兩個int
s student
和general
,專門用於查看故障單部分。如何在不同方法之間共享int java
這是我的代碼而不是聲明的以下
package assignment1;
import java.util.Scanner;
public class modulisationtest {
public static void main(String[] args)
{
// TODO Auto-generated method stub
int i, user, general, student;
Scanner s = new Scanner(System.in);
for(i=1; i <=60; i = i+1)
System.out.print("*");
System.out.println("");
System.out.println("Federation University olympics 2016");
System.out.println("");
System.out.println("Developed by Ryan Guest, Student id 30285253 for Itech1000 ");
System.out.println("");
for(i=1; i <=60; i = i+1)
System.out.print("*");
Menu();
}
public static void Menu() {
int user;
Scanner s = new Scanner(System.in);
do
{
System.out.println("Ticket Purchase Menu");
System.out.println("1.Purchase");
System.out.println("2.View Tickets");
System.out.println("3.Exit");
user = s.nextInt();
switch (user)
{
case 1: System.out.println("You have selected purchase"); Purchase();
break;
case 2: System.out.println("ticket");
break;
case 3:
System.out.println("Thanks for shopping");
System.exit(user);
default: System.out.println("Not Valid");
}
} while (user!=3);
}
public static void Purchase()
{
int user, general=0, student =0;
Scanner s = new Scanner(System.in);
{
do
{
System.out.println("Ticket Purchase Menu");
System.out.println("1.General Admission");
System.out.println("2.Student ticket");
System.out.println("3.Finalise order");
System.out.println("4.Return to Menu");
user = s.nextInt();
switch (user)
{
case 1:
System.out.println("How many General tickets do you want to purchase");
general = s.nextInt();
break;
case 2:
System.out.println("How many student tickets do you want to purchase");
student = s.nextInt();
break;
case 3:
System.out.println("You're Buying" + " " + general + " " + "General tickets and" + " " + student + " " + "Student Tickets");
break;
case 4:
break;
default: System.out.println("Not Valid");
}
} while (user!=3&&user!=4);
}
}
}
調用靜態方法學習創建表示要使用的數據的對象。 –